Просмотр исходного кода

COVER_DATA_DIR for *.coverdata

Also make COVER_REPORT_DIR not override user value (if set before
include erlang.mk).
Use incl_app in CT cover spec.
nevar 7 лет назад
Родитель
Сommit
6a764de5ff
3 измененных файлов с 72 добавлено и 18 удалено
  1. 17 13
      plugins/cover.mk
  2. 4 4
      plugins/eunit.mk
  3. 51 1
      test/plugin_cover.mk

+ 17 - 13
plugins/cover.mk

@@ -2,23 +2,20 @@
 # Copyright (c) 2015, Viktor Söderqvist <viktor@zuiderkwast.se>
 # Copyright (c) 2015, Viktor Söderqvist <viktor@zuiderkwast.se>
 # This file is part of erlang.mk and subject to the terms of the ISC License.
 # This file is part of erlang.mk and subject to the terms of the ISC License.
 
 
-COVER_REPORT_DIR = cover
+COVER_REPORT_DIR ?= cover
+COVER_DATA_DIR ?= $(CURDIR)
 
 
 # Hook in coverage to ct
 # Hook in coverage to ct
 
 
 ifdef COVER
 ifdef COVER
 ifdef CT_RUN
 ifdef CT_RUN
 ifneq ($(wildcard $(TEST_DIR)),)
 ifneq ($(wildcard $(TEST_DIR)),)
-# All modules in 'ebin'
-COVER_MODS = $(notdir $(basename $(call core_ls,ebin/*.beam)))
-
 test-build:: $(TEST_DIR)/ct.cover.spec
 test-build:: $(TEST_DIR)/ct.cover.spec
 
 
-$(TEST_DIR)/ct.cover.spec:
-	$(verbose) echo Cover mods: $(COVER_MODS)
+$(TEST_DIR)/ct.cover.spec: cover-data-dir
 	$(gen_verbose) printf "%s\n" \
 	$(gen_verbose) printf "%s\n" \
-		'{incl_mods,[$(subst $(space),$(comma),$(COVER_MODS))]}.' \
-		'{export,"$(CURDIR)/ct.coverdata"}.' > $@
+		"{incl_app, '$(PROJECT)', details}." \
+		'{export,"$(abspath $(COVER_DATA_DIR))/ct.coverdata"}.' > $@
 
 
 CT_RUN += -cover $(TEST_DIR)/ct.cover.spec
 CT_RUN += -cover $(TEST_DIR)/ct.cover.spec
 endif
 endif
@@ -32,6 +29,13 @@ ifneq ($(COVER_REPORT_DIR),)
 tests::
 tests::
 	$(verbose) $(MAKE) --no-print-directory cover-report
 	$(verbose) $(MAKE) --no-print-directory cover-report
 endif
 endif
+
+cover-data-dir: | $(COVER_DATA_DIR)
+
+$(COVER_DATA_DIR):
+	$(verbose) mkdir -p $(COVER_DATA_DIR)
+else
+cover-data-dir:
 endif
 endif
 
 
 clean:: coverdata-clean
 clean:: coverdata-clean
@@ -54,19 +58,19 @@ help::
 
 
 # Plugin specific targets
 # Plugin specific targets
 
 
-COVERDATA = $(filter-out all.coverdata,$(wildcard *.coverdata))
+COVERDATA = $(filter-out $(COVER_DATA_DIR)/all.coverdata,$(wildcard $(COVER_DATA_DIR)/*.coverdata))
 
 
 .PHONY: coverdata-clean
 .PHONY: coverdata-clean
 coverdata-clean:
 coverdata-clean:
-	$(gen_verbose) rm -f *.coverdata $(TEST_DIR)/ct.cover.spec
+	$(gen_verbose) rm -f $(COVER_DATA_DIR)/*.coverdata $(TEST_DIR)/ct.cover.spec
 
 
 # Merge all coverdata files into one.
 # Merge all coverdata files into one.
 define cover_export.erl
 define cover_export.erl
 	$(foreach f,$(COVERDATA),cover:import("$(f)") == ok orelse halt(1),)
 	$(foreach f,$(COVERDATA),cover:import("$(f)") == ok orelse halt(1),)
-	cover:export("$@"), halt(0).
+	cover:export("$(COVER_DATA_DIR)/$@"), halt(0).
 endef
 endef
 
 
-all.coverdata: $(COVERDATA)
+all.coverdata: $(COVERDATA) cover-data-dir
 	$(gen_verbose) $(call erlang,$(cover_export.erl))
 	$(gen_verbose) $(call erlang,$(cover_export.erl))
 
 
 # These are only defined if COVER_REPORT_DIR is non-empty. Set COVER_REPORT_DIR to
 # These are only defined if COVER_REPORT_DIR is non-empty. Set COVER_REPORT_DIR to
@@ -76,7 +80,7 @@ ifneq ($(COVER_REPORT_DIR),)
 .PHONY: cover-report-clean cover-report
 .PHONY: cover-report-clean cover-report
 
 
 cover-report-clean:
 cover-report-clean:
-	$(gen_verbose) rm -rf $(COVER_REPORT_DIR)
+	$(gen_verbose) rm -rf $(COVER_REPORT_DIR) $(COVER_DATA_DIR)
 
 
 ifeq ($(COVERDATA),)
 ifeq ($(COVERDATA),)
 cover-report:
 cover-report:

+ 4 - 4
plugins/eunit.mk

@@ -36,7 +36,7 @@ define eunit.erl
 	case "$(COVER)" of
 	case "$(COVER)" of
 		"" -> ok;
 		"" -> ok;
 		_ ->
 		_ ->
-			cover:export("eunit.coverdata")
+			cover:export("$(COVER_DATA_DIR)/eunit.coverdata")
 	end,
 	end,
 	halt()
 	halt()
 endef
 endef
@@ -45,10 +45,10 @@ EUNIT_ERL_OPTS += -pa $(TEST_DIR) $(DEPS_DIR)/*/ebin $(APPS_DIR)/*/ebin $(CURDIR
 
 
 ifdef t
 ifdef t
 ifeq (,$(findstring :,$(t)))
 ifeq (,$(findstring :,$(t)))
-eunit: test-build
+eunit: test-build cover-data-dir
 	$(gen_verbose) $(call erlang,$(call eunit.erl,['$(t)']),$(EUNIT_ERL_OPTS))
 	$(gen_verbose) $(call erlang,$(call eunit.erl,['$(t)']),$(EUNIT_ERL_OPTS))
 else
 else
-eunit: test-build
+eunit: test-build cover-data-dir
 	$(gen_verbose) $(call erlang,$(call eunit.erl,fun $(t)/0),$(EUNIT_ERL_OPTS))
 	$(gen_verbose) $(call erlang,$(call eunit.erl,fun $(t)/0),$(EUNIT_ERL_OPTS))
 endif
 endif
 else
 else
@@ -58,7 +58,7 @@ EUNIT_TEST_MODS = $(notdir $(basename $(call core_find,$(TEST_DIR)/,*.erl)))
 EUNIT_MODS = $(foreach mod,$(EUNIT_EBIN_MODS) $(filter-out \
 EUNIT_MODS = $(foreach mod,$(EUNIT_EBIN_MODS) $(filter-out \
 	$(patsubst %,%_tests,$(EUNIT_EBIN_MODS)),$(EUNIT_TEST_MODS)),'$(mod)')
 	$(patsubst %,%_tests,$(EUNIT_EBIN_MODS)),$(EUNIT_TEST_MODS)),'$(mod)')
 
 
-eunit: test-build $(if $(IS_APP),,apps-eunit)
+eunit: test-build $(if $(IS_APP),,apps-eunit) cover-data-dir
 	$(gen_verbose) $(call erlang,$(call eunit.erl,[$(call comma_list,$(EUNIT_MODS))]),$(EUNIT_ERL_OPTS))
 	$(gen_verbose) $(call erlang,$(call eunit.erl,[$(call comma_list,$(EUNIT_MODS))]),$(EUNIT_ERL_OPTS))
 
 
 ifneq ($(ALL_APPS_DIRS),)
 ifneq ($(ALL_APPS_DIRS),)

+ 51 - 1
test/plugin_cover.mk

@@ -1,6 +1,6 @@
 # Common Test plugin.
 # Common Test plugin.
 
 
-COVER_CASES = ct eunit report-and-merge
+COVER_CASES = ct custom-dir eunit report-and-merge
 COVER_TARGETS = $(addprefix cover-,$(COVER_CASES))
 COVER_TARGETS = $(addprefix cover-,$(COVER_CASES))
 
 
 .PHONY: cover $(COVER_TARGETS)
 .PHONY: cover $(COVER_TARGETS)
@@ -34,6 +34,56 @@ cover-ct: build clean
 	$t test ! -e $(APP)/ct.coverdata
 	$t test ! -e $(APP)/ct.coverdata
 	$t test ! -e $(APP)/test/ct.cover.spec
 	$t test ! -e $(APP)/test/ct.cover.spec
 
 
+cover-custom-dir: 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 "Set COVER_DATA_DIR in the Makefile"
+	$t perl -ni.bak -e 'print;if ($$.==1) {print "COVER_DATA_DIR = custom_dir\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() -> ok." \
+		"-endif." > $(APP)/src/$(APP).erl
+
+	$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(_) -> ok." > $(APP)/test/$(APP)_SUITE.erl
+
+	$i "Run Common Test with code coverage enabled"
+	$t $(MAKE) -C $(APP) ct COVER=1 $v
+
+	$i "Run EUnit with code coverage enabled"
+	$t $(MAKE) -C $(APP) eunit COVER=1 $v
+
+	$i "Check that the generated file exists"
+	$t test -f $(APP)/custom_dir/ct.coverdata
+	$t test -f $(APP)/custom_dir/eunit.coverdata
+
+	$i "Merge coverdata files into all.coverdata"
+	$t $(MAKE) -C $(APP) all.coverdata $v
+	$t test -f $(APP)/custom_dir/all.coverdata
+
+	$i "Check that the generated file is removed on clean"
+	$t $(MAKE) -C $(APP) clean $v
+	$t test ! -e $(APP)/custom_dir/eunit.coverdata
+	$t test ! -e $(APP)/custom_dir/ct.coverdata
+	$t test ! -e $(APP)/custom_dir/all.coverdata
+
+	$i "Check that the custom dir is removed on distclean"
+	$t $(MAKE) -C $(APP) distclean $v
+	$t test ! -e $(APP)/custom_dir/
+
 cover-eunit: build clean
 cover-eunit: build clean
 
 
 	$i "Bootstrap a new OTP application named $(APP)"
 	$i "Bootstrap a new OTP application named $(APP)"