aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJoseph Dunne <[email protected]>2020-10-25 18:34:26 +0000
committerLoïc Hoguin <[email protected]>2023-05-15 09:44:38 +0200
commit57798d7dc357528424a36f95c090e86450556885 (patch)
tree1052bb65e57e4685b97e6f2237f440a89b6c902a
parentb9676cb3fd1f71fef34d5f151baba100d77072d4 (diff)
downloaderlang.mk-57798d7dc357528424a36f95c090e86450556885.tar.gz
erlang.mk-57798d7dc357528424a36f95c090e86450556885.tar.bz2
erlang.mk-57798d7dc357528424a36f95c090e86450556885.zip
Add COVER_EXCL_MODS variable
-rw-r--r--doc/src/guide/coverage.asciidoc11
-rw-r--r--plugins/cover.mk24
-rw-r--r--test/plugin_cover.mk56
3 files changed, 82 insertions, 9 deletions
diff --git a/doc/src/guide/coverage.asciidoc b/doc/src/guide/coverage.asciidoc
index 02f8b5b..af159d8 100644
--- a/doc/src/guide/coverage.asciidoc
+++ b/doc/src/guide/coverage.asciidoc
@@ -46,6 +46,17 @@ some applications by defining the `COVER_APPS` variable:
[source,make]
COVER_APPS = presence backend
+=== Removing modules from the cover report
+
+By default Erlang.mk will include all modules in the
+cover report.
+
+To exclude some modules from the report, you can
+define the `COVER_EXCLUDE_MODS` variable:
+
+[source,make]
+COVER_EXCLUDE_MODS = cowboy_app cowboy_sup
+
=== Configuring paths
By default Erlang.mk will store 'coverdata' files and
diff --git a/plugins/cover.mk b/plugins/cover.mk
index 68f5b98..395e8b8 100644
--- a/plugins/cover.mk
+++ b/plugins/cover.mk
@@ -8,6 +8,7 @@ COVER_DATA_DIR ?= $(COVER_REPORT_DIR)
ifdef COVER
COVER_APPS ?= $(notdir $(ALL_APPS_DIRS))
COVER_DEPS ?=
+COVER_EXCLUDE_MODS ?=
endif
# Code coverage for Common Test.
@@ -23,7 +24,8 @@ $(TEST_DIR)/ct.cover.spec: cover-data-dir
"{incl_dirs, '$(PROJECT)', [\"$(call core_native_path,$(CURDIR)/ebin)\" \
$(foreach a,$(COVER_APPS),$(comma) \"$(call core_native_path,$(APPS_DIR)/$a/ebin)\") \
$(foreach d,$(COVER_DEPS),$(comma) \"$(call core_native_path,$(DEPS_DIR)/$d/ebin)\")]}." \
- '{export,"$(call core_native_path,$(abspath $(COVER_DATA_DIR))/ct.coverdata)"}.' > $@
+ '{export,"$(call core_native_path,$(abspath $(COVER_DATA_DIR))/ct.coverdata)"}.' \
+ "{excl_mods, '$(PROJECT)', [$(call comma_list,$(COVER_EXCLUDE_MODS))]}." > $@
CT_RUN += -cover $(TEST_DIR)/ct.cover.spec
endif
@@ -38,14 +40,18 @@ define cover.erl
Dirs = ["$(call core_native_path,$(CURDIR)/ebin)"
$(foreach a,$(COVER_APPS),$(comma) "$(call core_native_path,$(APPS_DIR)/$a/ebin)")
$(foreach d,$(COVER_DEPS),$(comma) "$(call core_native_path,$(DEPS_DIR)/$d/ebin)")],
- [begin
- case filelib:is_dir(Dir) of
- false -> false;
- true ->
- case cover:compile_beam_directory(Dir) of
- {error, _} -> halt(1);
- _ -> true
- end
+ Excludes = [$(call comma_list,$(foreach e,$(COVER_EXCLUDE_MODS),"$e"))],
+ [case file:list_dir(Dir) of
+ {error, enotdir} -> false;
+ {error, _} -> halt(2);
+ {ok, Files} ->
+ BeamFiles = [filename:join(Dir, File) ||
+ File <- Files,
+ not lists:member(filename:basename(File, ".beam"), Excludes),
+ filename:extension(File) =:= ".beam"],
+ case cover:compile_beam(BeamFiles) of
+ {error, _} -> halt(1);
+ _ -> true
end
end || Dir <- Dirs]
end,
diff --git a/test/plugin_cover.mk b/test/plugin_cover.mk
index 91b1b2c..2ad8ef4 100644
--- a/test/plugin_cover.mk
+++ b/test/plugin_cover.mk
@@ -33,6 +33,34 @@ cover-ct: init
$t test ! -e $(APP)/cover/ct.coverdata
$t test ! -e $(APP)/test/ct.cover.spec
+cover-ct-excl-mods: init
+
+ $i "Bootstrap a new OTP application named $(APP)"
+ $t mkdir $(APP)/
+ $t cp ../erlang.mk $(APP)/
+ $t $(MAKE) -C $(APP) -f erlang.mk bootstrap $v
+
+ $i "Add supervisor module to the cover exclude module list "
+ $t perl -ni.bak -e 'print;if ($$.==1) {print "COVER_EXCLUDE_MODS = $(APP)_sup \n"}' $(APP)/Makefile
+
+ $i "Generate a Common Test suite"
+ $t mkdir $(APP)/test
+ $t printf "%s\n" \
+ "-module($(APP)_SUITE)." \
+ "-export([all/0, ok/1])." \
+ "all() -> [ok]." \
+ "ok(_) -> application:start($(APP))." > $(APP)/test/$(APP)_SUITE.erl
+
+ $i "Run Common Test with code coverage enabled"
+ $t $(MAKE) -C $(APP) ct COVER=1 $v
+
+ $i "Check that the generated files exist"
+ $t test -f $(APP)/cover/ct.coverdata
+ $t test -f $(APP)/test/ct.cover.spec
+
+ $i "Check that the supervisor module is not included in the cover report"
+ $t ! test -e $(APP)/logs/ct_run.*/$(APP)_sup.COVER.html
+
cover-ct-incl-apps: init
$i "Bootstrap a new OTP application named $(APP)"
@@ -285,6 +313,34 @@ cover-eunit-apps-only: init
$i "Check that the generated file exists"
$t test -f $(APP)/apps/my_app/cover/eunit.coverdata
+cover-eunit-excl-mods: init
+
+ $i "Bootstrap a new OTP application named $(APP)"
+ $t mkdir $(APP)/
+ $t cp ../erlang.mk $(APP)/
+ $t $(MAKE) -C $(APP) -f erlang.mk bootstrap $v
+
+ $i "Add supervisor module to the cover exclude module list "
+ $t perl -ni.bak -e 'print;if ($$.==1) {print "COVER_EXCLUDE_MODS = $(APP)_sup \n"}' $(APP)/Makefile
+
+ $i "Generate a module containing EUnit tests"
+ $t printf "%s\n" \
+ "-module($(APP))." \
+ "-ifdef(TEST)." \
+ "-include_lib(\"eunit/include/eunit.hrl\")." \
+ "ok_test() -> application:ensure_all_started($(APP))." \
+ "-endif." > $(APP)/src/$(APP).erl
+
+ $i "Run EUnit with code coverage enabled"
+ $t $(MAKE) -C $(APP) eunit COVER=1 $v
+
+ $i "Build the cover report"
+ $t $(MAKE) -C $(APP) cover-report $v
+
+ $i "Check that app was covered, but supervisor wasn't"
+ $t test -f $(APP)/cover/$(APP)_app.COVER.html
+ $t ! test -e $(APP)/cover/$(APP)_sup.COVER.html
+
cover-eunit-incl-apps: init
$i "Bootstrap a new OTP application named $(APP)"