aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLoïc Hoguin <[email protected]>2018-05-14 13:55:30 +0200
committerLoïc Hoguin <[email protected]>2018-05-14 13:55:30 +0200
commite344a3027b7cd5d6510cda8c9d80527de11e24f4 (patch)
tree872d5c2b4fe50385acfd889c6e9d2cde6fab289c
parentcbcb57ad25e63a8ff7952121b72458e5b2d04355 (diff)
downloaderlang.mk-e344a3027b7cd5d6510cda8c9d80527de11e24f4.tar.gz
erlang.mk-e344a3027b7cd5d6510cda8c9d80527de11e24f4.tar.bz2
erlang.mk-e344a3027b7cd5d6510cda8c9d80527de11e24f4.zip
Don't run cover when there's no ebin files in the directory
-rw-r--r--plugins/eunit.mk19
-rw-r--r--test/plugin_cover.mk29
2 files changed, 40 insertions, 8 deletions
diff --git a/plugins/eunit.mk b/plugins/eunit.mk
index af614f6..6ef0778 100644
--- a/plugins/eunit.mk
+++ b/plugins/eunit.mk
@@ -21,20 +21,25 @@ help::
# Plugin-specific targets.
define eunit.erl
- case "$(COVER)" of
- "" -> ok;
+ Enabled = case "$(COVER)" of
+ "" -> false;
_ ->
- case cover:compile_beam_directory("ebin") of
- {error, _} -> halt(1);
- _ -> ok
+ case filelib:is_dir("ebin") of
+ false -> false;
+ true ->
+ case cover:compile_beam_directory("ebin") of
+ {error, _} -> halt(1);
+ _ -> true
+ end
end
end,
case eunit:test($1, [$(EUNIT_OPTS)]) of
ok -> ok;
error -> halt(2)
end,
- case "$(COVER)" of
- "" -> ok;
+ case {Enabled, "$(COVER)"} of
+ {false, _} -> ok;
+ {_, ""} -> ok;
_ ->
cover:export("$(COVER_DATA_DIR)/eunit.coverdata")
end,
diff --git a/test/plugin_cover.mk b/test/plugin_cover.mk
index c9ba3d7..a4accd1 100644
--- a/test/plugin_cover.mk
+++ b/test/plugin_cover.mk
@@ -1,6 +1,6 @@
# Common Test plugin.
-COVER_CASES = ct custom-dir eunit report-and-merge
+COVER_CASES = ct custom-dir eunit eunit-apps-only report-and-merge
COVER_TARGETS = $(addprefix cover-,$(COVER_CASES))
.PHONY: cover $(COVER_TARGETS)
@@ -115,6 +115,33 @@ cover-eunit: build clean
$t $(MAKE) -C $(APP) clean $v
$t test ! -e $(APP)/eunit.coverdata
+cover-eunit-apps-only: build clean
+
+ $i "Create a multi application repository with no root application"
+ $t mkdir $(APP)/
+ $t cp ../erlang.mk $(APP)/
+ $t echo "include erlang.mk" > $(APP)/Makefile
+
+ $i "Create a new application named my_app"
+ $t $(MAKE) -C $(APP) new-app in=my_app $v
+
+ $i "Generate a module containing EUnit tests in my_app"
+ $t printf "%s\n" \
+ "-module(my_app)." \
+ "-ifdef(TEST)." \
+ "-include_lib(\"eunit/include/eunit.hrl\")." \
+ "ok_test() -> ok." \
+ "-endif." > $(APP)/apps/my_app/src/my_app.erl
+
+ $i "Run EUnit with code coverage enabled"
+ $t $(MAKE) -C $(APP) eunit COVER=1 $v
+
+ $i "Check that no file was generated in the top-level directory"
+ $t ! test -f $(APP)/eunit.coverdata
+
+ $i "Check that the generated file exists"
+ $t test -f $(APP)/apps/my_app/eunit.coverdata
+
cover-report-and-merge: build clean
$i "Bootstrap a new OTP application named $(APP)"