Browse Source

Fix code coverage for ct-* targets

Thanks to David Ansari for the report.
Loïc Hoguin 2 years ago
parent
commit
6423c1c057
2 changed files with 30 additions and 3 deletions
  1. 3 3
      plugins/ct.mk
  2. 27 0
      test/plugin_cover.mk

+ 3 - 3
plugins/ct.mk

@@ -78,9 +78,9 @@ endif
 endif
 
 define ct_suite_target
-ct-$(1): test-build
-	$(verbose) mkdir -p $(CT_LOGS_DIR)
-	$(gen_verbose_esc) $(CT_RUN) -sname ct_$(PROJECT) -suite $(addsuffix _SUITE,$(1)) $(CT_EXTRA) $(CT_OPTS)
+ct-$1: test-build
+	$$(verbose) mkdir -p $$(CT_LOGS_DIR)
+	$$(gen_verbose_esc) $$(CT_RUN) -sname ct_$$(PROJECT) -suite $$(addsuffix _SUITE,$1) $$(CT_EXTRA) $$(CT_OPTS)
 endef
 
 $(foreach test,$(CT_SUITES),$(eval $(call ct_suite_target,$(test))))

+ 27 - 0
test/plugin_cover.mk

@@ -150,6 +150,33 @@ endif
 	$t test -f $(APP)/logs/ct_run.*/cow_http_hd.COVER.html
 	$t ! test -e $(APP)/logs/ct_run.*/ranch_app.COVER.html
 
+cover-ct-single-suite: 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 "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 against this specific test suite with code coverage enabled"
+	$t $(MAKE) -C $(APP) ct-$(APP) 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 generated files are removed on clean"
+	$t $(MAKE) -C $(APP) clean $v
+	$t test ! -e $(APP)/cover/ct.coverdata
+	$t test ! -e $(APP)/test/ct.cover.spec
+
 cover-custom-dir: init
 
 	$i "Bootstrap a new OTP application named $(APP)"