aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLoïc Hoguin <[email protected]>2018-12-06 18:25:09 +0100
committerLoïc Hoguin <[email protected]>2018-12-06 18:25:09 +0100
commit754bad09421c70034242f4370c633e177a869151 (patch)
tree5d8e4faed1d6f204cd65a537f8f7eb58bacd975e
parent44fe1e993f16c98ed41c01e4511c0367e14e9637 (diff)
downloaderlang.mk-754bad09421c70034242f4370c633e177a869151.tar.gz
erlang.mk-754bad09421c70034242f4370c633e177a869151.tar.bz2
erlang.mk-754bad09421c70034242f4370c633e177a869151.zip
Add cover support for PropEr and Triq
-rw-r--r--plugins/cover.mk25
-rw-r--r--plugins/eunit.mk21
-rw-r--r--plugins/proper.mk18
-rw-r--r--plugins/triq.mk18
-rw-r--r--test/plugin_cover.mk56
-rw-r--r--test/plugin_proper.mk2
6 files changed, 106 insertions, 34 deletions
diff --git a/plugins/cover.mk b/plugins/cover.mk
index 416219c..6fd8829 100644
--- a/plugins/cover.mk
+++ b/plugins/cover.mk
@@ -5,7 +5,7 @@
COVER_REPORT_DIR ?= cover
COVER_DATA_DIR ?= $(COVER_REPORT_DIR)
-# Hook in coverage to ct
+# Code coverage for Common Test.
ifdef COVER
ifdef CT_RUN
@@ -22,6 +22,29 @@ endif
endif
endif
+# Code coverage for other tools.
+
+ifdef COVER
+define cover.erl
+ CoverSetup = fun() ->
+ case filelib:is_dir("ebin") of
+ false -> false;
+ true ->
+ case cover:compile_beam_directory("ebin") of
+ {error, _} -> halt(1);
+ _ -> true
+ end
+ end
+ end,
+ CoverExport = fun(Filename) -> cover:export(Filename) end,
+endef
+else
+define cover.erl
+ CoverSetup = fun() -> ok end,
+ CoverExport = fun(_) -> ok end,
+endef
+endif
+
# Core targets
ifdef COVER
diff --git a/plugins/eunit.mk b/plugins/eunit.mk
index 600010d..1847453 100644
--- a/plugins/eunit.mk
+++ b/plugins/eunit.mk
@@ -21,28 +21,13 @@ help::
# Plugin-specific targets.
define eunit.erl
- Enabled = case "$(COVER)" of
- "" -> false;
- _ ->
- case filelib:is_dir("ebin") of
- false -> false;
- true ->
- case cover:compile_beam_directory("ebin") of
- {error, _} -> halt(1);
- _ -> true
- end
- end
- end,
+ $(call cover.erl)
+ CoverSetup(),
case eunit:test($1, [$(EUNIT_OPTS)]) of
ok -> ok;
error -> halt(2)
end,
- case {Enabled, "$(COVER)"} of
- {false, _} -> ok;
- {_, ""} -> ok;
- _ ->
- cover:export("$(COVER_DATA_DIR)/eunit.coverdata")
- end,
+ CoverExport("$(COVER_DATA_DIR)/eunit.coverdata"),
halt()
endef
diff --git a/plugins/proper.mk b/plugins/proper.mk
index b749d9e..6262199 100644
--- a/plugins/proper.mk
+++ b/plugins/proper.mk
@@ -9,6 +9,7 @@ ifeq ($(filter proper,$(DEPS) $(TEST_DEPS)),proper)
tests:: proper
define proper_check.erl
+ $(call cover.erl)
code:add_pathsa([
"$(call core_native_path,$(CURDIR)/ebin)",
"$(call core_native_path,$(DEPS_DIR)/*/ebin)",
@@ -24,13 +25,16 @@ define proper_check.erl
end
|| {F, 0} <- M:module_info(exports)])
end,
- try
- case $(1) of
+ try begin
+ CoverSetup(),
+ Res = case $(1) of
all -> [true] =:= lists:usort([Module(M) || M <- [$(call comma_list,$(3))]]);
module -> Module($(2));
function -> proper:quickcheck($(2), nocolors)
- end
- of
+ end,
+ CoverExport("$(COVER_DATA_DIR)/proper.coverdata"),
+ Res
+ end of
true -> halt(0);
_ -> halt(1)
catch error:undef ->
@@ -41,15 +45,15 @@ endef
ifdef t
ifeq (,$(findstring :,$(t)))
-proper: test-build
+proper: test-build cover-data-dir
$(verbose) $(call erlang,$(call proper_check.erl,module,$(t)))
else
-proper: test-build
+proper: test-build cover-data-dir
$(verbose) echo Testing $(t)/0
$(verbose) $(call erlang,$(call proper_check.erl,function,$(t)()))
endif
else
-proper: test-build
+proper: test-build cover-data-dir
$(eval MODULES := $(patsubst %,'%',$(sort $(notdir $(basename \
$(wildcard ebin/*.beam) $(call core_find,$(TEST_DIR)/,*.beam))))))
$(gen_verbose) $(call erlang,$(call proper_check.erl,all,undefined,$(MODULES)))
diff --git a/plugins/triq.mk b/plugins/triq.mk
index 9d5a30f..8791e2c 100644
--- a/plugins/triq.mk
+++ b/plugins/triq.mk
@@ -9,17 +9,21 @@ ifeq ($(filter triq,$(DEPS) $(TEST_DEPS)),triq)
tests:: triq
define triq_check.erl
+ $(call cover.erl)
code:add_pathsa([
"$(call core_native_path,$(CURDIR)/ebin)",
"$(call core_native_path,$(DEPS_DIR)/*/ebin)",
"$(call core_native_path,$(TEST_DIR))"]),
- try
- case $(1) of
+ try begin
+ CoverSetup(),
+ Res = case $(1) of
all -> [true] =:= lists:usort([triq:check(M) || M <- [$(call comma_list,$(3))]]);
module -> triq:check($(2));
function -> triq:check($(2))
- end
- of
+ end,
+ CoverExport("$(COVER_DATA_DIR)/triq.coverdata"),
+ Res
+ end of
true -> halt(0);
_ -> halt(1)
catch error:undef ->
@@ -30,15 +34,15 @@ endef
ifdef t
ifeq (,$(findstring :,$(t)))
-triq: test-build
+triq: test-build cover-data-dir
$(verbose) $(call erlang,$(call triq_check.erl,module,$(t)))
else
-triq: test-build
+triq: test-build cover-data-dir
$(verbose) echo Testing $(t)/0
$(verbose) $(call erlang,$(call triq_check.erl,function,$(t)()))
endif
else
-triq: test-build
+triq: test-build cover-data-dir
$(eval MODULES := $(patsubst %,'%',$(sort $(notdir $(basename \
$(wildcard ebin/*.beam) $(call core_find,$(TEST_DIR)/,*.beam))))))
$(gen_verbose) $(call erlang,$(call triq_check.erl,all,undefined,$(MODULES)))
diff --git a/test/plugin_cover.mk b/test/plugin_cover.mk
index b6b3a5d..a5ed295 100644
--- a/test/plugin_cover.mk
+++ b/test/plugin_cover.mk
@@ -141,6 +141,34 @@ cover-eunit-apps-only: build clean
$i "Check that the generated file exists"
$t test -f $(APP)/apps/my_app/cover/eunit.coverdata
+cover-proper: build clean
+
+ $i "Bootstrap a new OTP application named $(APP)"
+ $t mkdir $(APP)/
+ $t cp ../erlang.mk $(APP)/
+ $t $(MAKE) -C $(APP) -f erlang.mk bootstrap-lib $v
+
+ $i "Add PropEr to the list of dependencies"
+ $t perl -ni.bak -e 'print;if ($$.==1) {print "DEPS = proper\n"}' $(APP)/Makefile
+
+ $i "Generate a module containing Proper properties"
+ $t printf "%s\n" \
+ "-module($(APP))." \
+ "-ifdef(TEST)." \
+ "-include_lib(\"proper/include/proper.hrl\")." \
+ "prop_foo() -> ?FORALL(_, any(), true)." \
+ "-endif." > $(APP)/src/$(APP).erl
+
+ $i "Run PropEr with code coverage enabled"
+ $t $(MAKE) -C $(APP) proper COVER=1 $v
+
+ $i "Check that the generated file exists"
+ $t test -f $(APP)/cover/proper.coverdata
+
+ $i "Check that the generated file is removed on clean"
+ $t $(MAKE) -C $(APP) clean $v
+ $t test ! -e $(APP)/cover/proper.coverdata
+
cover-report-and-merge: build clean
$i "Bootstrap a new OTP application named $(APP)"
@@ -188,3 +216,31 @@ cover-report-and-merge: build clean
$i "Check that the cover report is removed on distclean"
$t $(MAKE) -C $(APP) distclean $v
$t test ! -e $(APP)/cover/
+
+cover-triq: build clean
+
+ $i "Bootstrap a new OTP application named $(APP)"
+ $t mkdir $(APP)/
+ $t cp ../erlang.mk $(APP)/
+ $t $(MAKE) -C $(APP) -f erlang.mk bootstrap-lib $v
+
+ $i "Add Triq to the list of dependencies"
+ $t perl -ni.bak -e 'print;if ($$.==1) {print "DEPS = triq\n"}' $(APP)/Makefile
+
+ $i "Generate a module containing Triq properties"
+ $t printf "%s\n" \
+ "-module($(APP))." \
+ "-ifdef(TEST)." \
+ "-include_lib(\"triq/include/triq.hrl\")." \
+ "prop_foo() -> ?FORALL(_, any(), true)." \
+ "-endif." > $(APP)/src/$(APP).erl
+
+ $i "Run Triq with code coverage enabled"
+ $t $(MAKE) -C $(APP) triq COVER=1 $v
+
+ $i "Check that the generated file exists"
+ $t test -f $(APP)/cover/triq.coverdata
+
+ $i "Check that the generated file is removed on clean"
+ $t $(MAKE) -C $(APP) clean $v
+ $t test ! -e $(APP)/cover/triq.coverdata
diff --git a/test/plugin_proper.mk b/test/plugin_proper.mk
index 98a7c99..ca92d91 100644
--- a/test/plugin_proper.mk
+++ b/test/plugin_proper.mk
@@ -16,7 +16,7 @@ proper-test-dir: build clean
$i "Add PropEr to the list of dependencies"
$t perl -ni.bak -e 'print;if ($$.==1) {print "DEPS = proper\n"}' $(APP)/Makefile
- $i "Generate a module containing Proper properties"
+ $i "Generate a module containing PropEr properties"
$t printf "%s\n" \
"-module($(APP))." \
"-ifdef(TEST)." \