diff --git a/tests/unit/Makefile.am b/tests/unit/Makefile.am index cb5bfc10013..80fe7311c46 100644 --- a/tests/unit/Makefile.am +++ b/tests/unit/Makefile.am @@ -39,27 +39,50 @@ nodist_%C%_test_zap_SOURCES = \ # test run and coverage targets below -PHONY += unit unit-coverage +PHONY += unit unit-coverage unit-coverage-html _unit_run_%: %D%/% @echo " UNITTEST $<" ; $< $(TOPT) -_unit_coverage_%: %D%/% - @${LCOV} --quiet --zerocounters --directory $(top_srcdir) >/dev/null +# note: any changes in switches to lcov or genhtml must be carefully checked +# on 1.x and 2.x; the current option set is carefully chosen to allow +# both to work sensibly + +# .info is marked PRECIOUS, because its usually only created as an intermediate +# from one of the unit phony targets, but once it exists there's no point +# remaking it until and unless the test binary itself changes +.PRECIOUS: %D%/%.info +%D%/%.info: %D%/% + @-${RM} $@ + @${LCOV} --quiet --quiet --zerocounters --directory $(top_srcdir) @echo " UNITTEST $<" ; $< $(TOPT) - @${LCOV} --quiet --capture \ - --test-name $(subst _unit_coverage_, , $@) \ + @${LCOV} --quiet --quiet --capture \ + --test-name $(notdir $<) \ --directory $(top_srcdir) \ - --output-file \ - %D%/$(join $(subst _unit_coverage_, , $@), .info) \ - $(addprefix --include , $(call $(join \ - $(subst _unit_coverage_, nodist_%C%_, $@), _SOURCES))) - @${GENHTML} --quiet \ - %D%/$(join $(subst _unit_coverage_, , $@), .info) \ - --output-directory \ - %D%/$(join $(subst _unit_coverage_, , $@), _coverage) + --output-file $@ \ + --rc lcov_branch_coverage=1 \ + --rc geninfo_unexecuted_blocks=1 \ + $(addprefix --include $(abs_top_builddir)/, $(call \ + $(join $(join nodist_%C%_, $(notdir $<)), _SOURCES))) \ + 2>/dev/null + +_unit_coverage_%: %D%/%.info + @scripts/coverage_report.pl $< + +_unit_coverage_html_%: %D%/%.info + @-${RM} -r $(subst .info,_coverage, $<) + @${GENHTML} --quiet -quiet \ + --rc lcov_branch_coverage=1 \ + --rc check_data_consistency=0 \ + --output-directory $(subst .info,_coverage, $<) \ + $< \ + 2>/dev/null @echo "coverage results:" \ - "file://$(realpath %D%)/$(join $(subst _unit_coverage_, , $@), _coverage)/index.html" + "file://$(realpath %D%)/$(subst .info,_coverage,$(notdir $<))/index.html" + +CLEAN_LOCAL += unit-clean-local +unit-clean-local: + -${RM} -r %D%/*.info %D%/*_coverage/ _UNIT_ALL_TARGETS = $(notdir $(UNIT_TESTS)) _UNIT_FIND_TARGET = \ @@ -76,9 +99,12 @@ unit: $(addprefix _unit_run_, $(_UNIT_TARGETS)) if CODE_COVERAGE_ENABLED unit-coverage: $(addprefix _unit_coverage_, $(_UNIT_TARGETS)) @$(if $^, true, echo "ERROR: couldn't find unit test: $(T)" && false) +unit-coverage-html: $(addprefix _unit_coverage_html_, $(_UNIT_TARGETS)) + @$(if $^, true, echo "ERROR: couldn't find unit test: $(T)" && false) else unit-coverage: @echo "unit test coverage not enabled." @echo "re-run configure with --enable-code-coverage" @false +unit-coverage-html: unit-coverage endif