|
@@ -1278,7 +1278,7 @@ endif
|
|
# Copyright 2015, Viktor Söderqvist <viktor@zuiderkwast.se>
|
|
# Copyright 2015, Viktor Söderqvist <viktor@zuiderkwast.se>
|
|
# This file is part of erlang.mk and subject to the terms of the ISC License.
|
|
# This file is part of erlang.mk and subject to the terms of the ISC License.
|
|
|
|
|
|
-COVER_DIR = cover
|
|
+COVER_REPORT_DIR = cover
|
|
|
|
|
|
# utility variables for representing special symbols
|
|
# utility variables for representing special symbols
|
|
empty :=
|
|
empty :=
|
|
@@ -1321,7 +1321,7 @@ endif
|
|
# Core targets
|
|
# Core targets
|
|
|
|
|
|
ifdef COVER
|
|
ifdef COVER
|
|
-ifneq ($(COVER_DIR),)
|
|
+ifneq ($(COVER_REPORT_DIR),)
|
|
tests::
|
|
tests::
|
|
@$(MAKE) make --no-print-directory cover-report
|
|
@$(MAKE) make --no-print-directory cover-report
|
|
endif
|
|
endif
|
|
@@ -1329,8 +1329,8 @@ endif
|
|
|
|
|
|
clean:: coverdata-clean
|
|
clean:: coverdata-clean
|
|
|
|
|
|
-ifneq ($(COVER_DIR),)
|
|
+ifneq ($(COVER_REPORT_DIR),)
|
|
-distclean:: cover-clean
|
|
+distclean:: cover-report-clean
|
|
endif
|
|
endif
|
|
|
|
|
|
help::
|
|
help::
|
|
@@ -1338,28 +1338,35 @@ help::
|
|
"Cover targets:" \
|
|
"Cover targets:" \
|
|
" cover-report Generate a HTML coverage report from previously collected" \
|
|
" cover-report Generate a HTML coverage report from previously collected" \
|
|
" cover data." \
|
|
" cover data." \
|
|
|
|
+ " all.coverdata Merge {eunit,ct}.coverdata into one coverdata file." \
|
|
"" \
|
|
"" \
|
|
- "Cover-report is included in the 'tests' target by setting COVER=1." \
|
|
+ "If COVER=1 is set, coverage data is generated by the targets eunit and ct. The" \
|
|
- "If you run 'ct' or 'eunit' separately with COVER=1, cover data is" \
|
|
+ "target tests additionally generates a HTML coverage report from the combined" \
|
|
- "collected but to generate a report you have to run 'cover-report'" \
|
|
+ "coverdata files from each of these testing tools. HTML reports can be disabled" \
|
|
- "afterwards."
|
|
+ "by setting COVER_REPORT_DIR to empty."
|
|
|
|
|
|
# Plugin specific targets
|
|
# Plugin specific targets
|
|
|
|
|
|
|
|
+COVERDATA = $(filter-out all.coverdata,$(wildcard *.coverdata))
|
|
|
|
+
|
|
.PHONY: coverdata-clean
|
|
.PHONY: coverdata-clean
|
|
coverdata-clean:
|
|
coverdata-clean:
|
|
$(gen_verbose) rm -f *.coverdata ct.cover.spec
|
|
$(gen_verbose) rm -f *.coverdata ct.cover.spec
|
|
|
|
|
|
-# These are only defined if COVER_DIR is non-empty
|
|
+# Merge all coverdata files into one.
|
|
-
|
|
+all.coverdata: $(COVERDATA)
|
|
-ifneq ($(COVER_DIR),)
|
|
+ $(gen_verbose) $(ERL) -eval ' \
|
|
|
|
+ $(foreach f,$(COVERDATA),cover:import("$(f)") == ok orelse halt(1),) \
|
|
|
|
+ cover:export("$@"), halt(0).'
|
|
|
|
|
|
-.PHONY: cover-clean cover-report
|
|
+# These are only defined if COVER_REPORT_DIR is non-empty. Set COVER_REPORT_DIR to
|
|
|
|
+# empty if you want the coverdata files but not the HTML report.
|
|
|
|
+ifneq ($(COVER_REPORT_DIR),)
|
|
|
|
|
|
-cover-clean: coverdata-clean
|
|
+.PHONY: cover-report-clean cover-report
|
|
- $(gen_verbose) rm -rf $(COVER_DIR)
|
|
|
|
|
|
|
|
-COVERDATA = $(wildcard *.coverdata)
|
|
+cover-report-clean:
|
|
|
|
+ $(gen_verbose) rm -rf $(COVER_REPORT_DIR)
|
|
|
|
|
|
ifeq ($(COVERDATA),)
|
|
ifeq ($(COVERDATA),)
|
|
cover-report:
|
|
cover-report:
|
|
@@ -1369,14 +1376,14 @@ else
|
|
# because eunit defines test/0 which is never called. We compensate for this.
|
|
# because eunit defines test/0 which is never called. We compensate for this.
|
|
EUNIT_HRL_MODS = $(subst $(space),$(comma),$(shell \
|
|
EUNIT_HRL_MODS = $(subst $(space),$(comma),$(shell \
|
|
grep -e '^\s*-include.*include/eunit\.hrl"' src/*.erl \
|
|
grep -e '^\s*-include.*include/eunit\.hrl"' src/*.erl \
|
|
- | sed 's/\.erl:.*//;s/^src\///' | uniq))
|
|
+ | sed "s/^src\/\(.*\)\.erl:.*/'\1'/" | uniq))
|
|
|
|
|
|
cover-report:
|
|
cover-report:
|
|
- $(gen_verbose) mkdir -p $(COVER_DIR)
|
|
+ $(gen_verbose) mkdir -p $(COVER_REPORT_DIR)
|
|
$(gen_verbose) $(ERL) -eval ' \
|
|
$(gen_verbose) $(ERL) -eval ' \
|
|
$(foreach f,$(COVERDATA),cover:import("$(f)") == ok orelse halt(1),) \
|
|
$(foreach f,$(COVERDATA),cover:import("$(f)") == ok orelse halt(1),) \
|
|
Ms = cover:imported_modules(), \
|
|
Ms = cover:imported_modules(), \
|
|
- [cover:analyse_to_file(M, "$(COVER_DIR)/" ++ atom_to_list(M) \
|
|
+ [cover:analyse_to_file(M, "$(COVER_REPORT_DIR)/" ++ atom_to_list(M) \
|
|
++ ".COVER.html", [html]) || M <- Ms], \
|
|
++ ".COVER.html", [html]) || M <- Ms], \
|
|
Report = [begin {ok, R} = cover:analyse(M, module), R end || M <- Ms], \
|
|
Report = [begin {ok, R} = cover:analyse(M, module), R end || M <- Ms], \
|
|
EunitHrlMods = [$(EUNIT_HRL_MODS)], \
|
|
EunitHrlMods = [$(EUNIT_HRL_MODS)], \
|
|
@@ -1385,7 +1392,7 @@ cover-report:
|
|
TotalY = lists:sum([Y || {_, {Y, _}} <- Report1]), \
|
|
TotalY = lists:sum([Y || {_, {Y, _}} <- Report1]), \
|
|
TotalN = lists:sum([N || {_, {_, N}} <- Report1]), \
|
|
TotalN = lists:sum([N || {_, {_, N}} <- Report1]), \
|
|
TotalPerc = round(100 * TotalY / (TotalY + TotalN)), \
|
|
TotalPerc = round(100 * TotalY / (TotalY + TotalN)), \
|
|
- {ok, F} = file:open("$(COVER_DIR)/index.html", [write]), \
|
|
+ {ok, F} = file:open("$(COVER_REPORT_DIR)/index.html", [write]), \
|
|
io:format(F, "<!DOCTYPE html><html>~n" \
|
|
io:format(F, "<!DOCTYPE html><html>~n" \
|
|
"<head><meta charset=\"UTF-8\">~n" \
|
|
"<head><meta charset=\"UTF-8\">~n" \
|
|
"<title>Coverage report</title></head>~n" \
|
|
"<title>Coverage report</title></head>~n" \
|
|
@@ -1403,4 +1410,4 @@ cover-report:
|
|
halt().'
|
|
halt().'
|
|
|
|
|
|
endif
|
|
endif
|
|
-endif # ifneq ($(COVER_DIR),)
|
|
+endif # ifneq ($(COVER_REPORT_DIR),)
|