From 789a4fb6be3bb92380e4314748872ab441ed5554 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Hoguin?= Date: Mon, 11 May 2015 13:47:51 +0300 Subject: Fix cover tests and use Erlang snippet --- plugins/cover.mk | 59 +++++++++++++++++++++++++++++--------------------------- test/Makefile | 12 ++++++++---- 2 files changed, 39 insertions(+), 32 deletions(-) diff --git a/plugins/cover.mk b/plugins/cover.mk index 3397dca..e94dcd4 100644 --- a/plugins/cover.mk +++ b/plugins/cover.mk @@ -101,36 +101,39 @@ EUNIT_HRL_MODS = $(subst $(space),$(comma),$(shell \ grep -e '^\s*-include.*include/eunit\.hrl"' src/*.erl \ | sed "s/^src\/\(.*\)\.erl:.*/'\1'/" | uniq)) +define cover_report.erl + $(foreach f,$(COVERDATA),cover:import("$(f)") == ok orelse halt(1),) + Ms = cover:imported_modules(), + [cover:analyse_to_file(M, "$(COVER_REPORT_DIR)/" ++ atom_to_list(M) + ++ ".COVER.html", [html]) || M <- Ms], + Report = [begin {ok, R} = cover:analyse(M, module), R end || M <- Ms], + EunitHrlMods = [$(EUNIT_HRL_MODS)], + Report1 = [{M, {Y, case lists:member(M, EunitHrlMods) of + true -> N - 1; false -> N end}} || {M, {Y, N}} <- Report], + TotalY = lists:sum([Y || {_, {Y, _}} <- Report1]), + TotalN = lists:sum([N || {_, {_, N}} <- Report1]), + TotalPerc = round(100 * TotalY / (TotalY + TotalN)), + {ok, F} = file:open("$(COVER_REPORT_DIR)/index.html", [write]), + io:format(F, "~n" + "~n" + "Coverage report~n" + "~n", []), + io:format(F, "

Coverage

~n

Total: ~p%

~n", [TotalPerc]), + io:format(F, "~n", []), + [io:format(F, "" + "~n", + [M, M, round(100 * Y / (Y + N))]) || {M, {Y, N}} <- Report1], + How = "$(subst $(space),$(comma)$(space),$(basename $(COVERDATA)))", + Date = "$(shell date -u "+%Y-%m-%dT%H:%M:%SZ")", + io:format(F, "
ModuleCoverage
~p~p%
~n" + "

Generated using ~s and erlang.mk on ~s.

~n" + "", [How, Date]), + halt(). +endef + cover-report: $(gen_verbose) mkdir -p $(COVER_REPORT_DIR) - $(gen_verbose) $(ERL) -eval ' \ - $(foreach f,$(COVERDATA),cover:import("$(f)") == ok orelse halt(1),) \ - Ms = cover:imported_modules(), \ - [cover:analyse_to_file(M, "$(COVER_REPORT_DIR)/" ++ atom_to_list(M) \ - ++ ".COVER.html", [html]) || M <- Ms], \ - Report = [begin {ok, R} = cover:analyse(M, module), R end || M <- Ms], \ - EunitHrlMods = [$(EUNIT_HRL_MODS)], \ - Report1 = [{M, {Y, case lists:member(M, EunitHrlMods) of \ - true -> N - 1; false -> N end}} || {M, {Y, N}} <- Report], \ - TotalY = lists:sum([Y || {_, {Y, _}} <- Report1]), \ - TotalN = lists:sum([N || {_, {_, N}} <- Report1]), \ - TotalPerc = round(100 * TotalY / (TotalY + TotalN)), \ - {ok, F} = file:open("$(COVER_REPORT_DIR)/index.html", [write]), \ - io:format(F, "~n" \ - "~n" \ - "Coverage report~n" \ - "~n", []), \ - io:format(F, "

Coverage

~n

Total: ~p%

~n", [TotalPerc]),\ - io:format(F, "~n", []), \ - [io:format(F, "" \ - "~n", \ - [M, M, round(100 * Y / (Y + N))]) || {M, {Y, N}} <- Report1], \ - How = "$(subst $(space),$(comma)$(space),$(basename $(COVERDATA)))", \ - Date = "$(shell date -u "+%Y-%m-%dT%H:%M:%SZ")", \ - io:format(F, "
ModuleCoverage
~p~p%
~n" \ - "

Generated using ~s and erlang.mk on ~s.

~n" \ - "", [How, Date]), \ - halt().' + $(gen_verbose) $(call erlang,$(cover_report.erl)) endif endif # ifneq ($(COVER_REPORT_DIR),) diff --git a/test/Makefile b/test/Makefile index 180b5a1..5449ee5 100644 --- a/test/Makefile +++ b/test/Makefile @@ -35,7 +35,7 @@ endif .PHONY: all clean app ct eunit tests-cover docs -all: app ct eunit tests-cover docs clean +all: clean app ct eunit tests-cover docs $i '+---------------------+' $i '| All tests passed. |' $i '+---------------------+' @@ -161,9 +161,12 @@ tests-cover: app1 $t [ -e app1/cover/index.html ] $i "Checking combined coverage from eunit and ct." $t [ `grep 'Total: 100%' app1/cover/index.html | wc -l` -eq 1 ] - $i "Checking that cover-clean removes cover data and report." - $t make -C app1 cover-clean $v - $t [ ! -e app1/cover ] && [ ! -e app1/eunit.coverdata ] + $i "Checking that cover-report-clean removes cover report." + $t make -C app1 cover-report-clean $v + $t [ ! -e app1/cover ] + $i "Checking that coverdata-clean removes cover data." + $t make -C app1 coverdata-clean $v + $t [ ! -e app1/eunit.coverdata ] @# clean up $t rm -rf app1/src/t.erl app1/test app1/test-eunit.log $t make -C app1 clean $v @@ -196,6 +199,7 @@ docs: app1 app1: $i "Setting up app." $t mkdir -p app1 + $t cd .. && make $t cp ../erlang.mk app1/ $t make -C app1 -f erlang.mk bootstrap-lib $t printf "%s\n" \ -- cgit v1.2.3