From bac26c547c9398968780b2c18c4740af322e55fe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Hoguin?= Date: Fri, 7 Dec 2018 11:22:50 +0100 Subject: Add COVER_APPS and COVER_DEPS to cover compile other apps/deps By default COVER_APPS will cover compile all apps. COVER_DEPS will not cover compile any dependency by default, however. --- plugins/cover.mk | 29 ++++-- test/plugin_cover.mk | 247 ++++++++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 266 insertions(+), 10 deletions(-) diff --git a/plugins/cover.mk b/plugins/cover.mk index 6fd8829..04ea657 100644 --- a/plugins/cover.mk +++ b/plugins/cover.mk @@ -5,6 +5,11 @@ COVER_REPORT_DIR ?= cover COVER_DATA_DIR ?= $(COVER_REPORT_DIR) +ifdef COVER +COVER_APPS ?= $(notdir $(ALL_APPS_DIRS)) +COVER_DEPS ?= +endif + # Code coverage for Common Test. ifdef COVER @@ -15,6 +20,9 @@ test-build:: $(TEST_DIR)/ct.cover.spec $(TEST_DIR)/ct.cover.spec: cover-data-dir $(gen_verbose) printf "%s\n" \ "{incl_app, '$(PROJECT)', details}." \ + "{incl_dirs, '$(PROJECT)', [\"$(CURDIR)/ebin\" \ + $(foreach a,$(COVER_APPS),$(comma) \"$(APPS_DIR)/$a/ebin\") \ + $(foreach d,$(COVER_DEPS),$(comma) \"$(DEPS_DIR)/$d/ebin\")]}." \ '{export,"$(abspath $(COVER_DATA_DIR))/ct.coverdata"}.' > $@ CT_RUN += -cover $(TEST_DIR)/ct.cover.spec @@ -27,14 +35,19 @@ endif 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 + Dirs = ["$(CURDIR)/ebin" + $(foreach a,$(COVER_APPS),$(comma) "$(APPS_DIR)/$a/ebin") + $(foreach d,$(COVER_DEPS),$(comma) "$(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 + end + end || Dir <- Dirs] end, CoverExport = fun(Filename) -> cover:export(Filename) end, endef diff --git a/test/plugin_cover.mk b/test/plugin_cover.mk index a5ed295..ccb5f12 100644 --- a/test/plugin_cover.mk +++ b/test/plugin_cover.mk @@ -11,7 +11,7 @@ cover-ct: 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 + $t $(MAKE) -C $(APP) -f erlang.mk bootstrap $v $i "Generate a Common Test suite" $t mkdir $(APP)/test @@ -19,7 +19,7 @@ cover-ct: build clean "-module($(APP)_SUITE)." \ "-export([all/0, ok/1])." \ "all() -> [ok]." \ - "ok(_) -> ok." > $(APP)/test/$(APP)_SUITE.erl + "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 @@ -33,6 +33,123 @@ cover-ct: build clean $t test ! -e $(APP)/cover/ct.coverdata $t test ! -e $(APP)/test/ct.cover.spec +cover-ct-incl-apps: 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 $v + + $i "Create a new application app_one" + $t $(MAKE) -C $(APP) new-app in=app_one $v + + $i "Create a new application app_two" + $t $(MAKE) -C $(APP) new-app in=app_two $v + + $i "Create a new application app_three" + $t $(MAKE) -C $(APP) new-app in=app_three $v + + $i "Add all three apps to LOCAL_DEPS" + $t perl -ni.bak -e 'print;if ($$.==1) {print "LOCAL_DEPS = app_one app_two app_three\n"}' $(APP)/Makefile + +ifdef LEGACY + $i "Add all three apps to the applications key in the .app.src file" + $t perl -ni.bak -e 'print;if ($$.==7) {print "\t\tapp_one,\n\t\tapp_two,\n\t\tapp_three,\n"}' $(APP)/src/$(APP).app.src +endif + + $i "Add app_one and app_three to the code coverage" + $t perl -ni.bak -e 'print;if ($$.==1) {print "COVER_APPS = app_one app_three\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:ensure_all_started($(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 app_one and app_three were covered, but app_two wasn't" + $t test -f $(APP)/logs/ct_run.*/app_one_app.COVER.html + $t test -f $(APP)/logs/ct_run.*/app_three_app.COVER.html + $t ! test -e $(APP)/logs/ct_run.*/app_two_app.COVER.html + +cover-ct-incl-apps-default: 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 $v + + $i "Create a new application app_one" + $t $(MAKE) -C $(APP) new-app in=app_one $v + + $i "Create a new application app_two" + $t $(MAKE) -C $(APP) new-app in=app_two $v + + $i "Create a new application app_three" + $t $(MAKE) -C $(APP) new-app in=app_three $v + + $i "Add all three apps to LOCAL_DEPS" + $t perl -ni.bak -e 'print;if ($$.==1) {print "LOCAL_DEPS = app_one app_two app_three\n"}' $(APP)/Makefile + +ifdef LEGACY + $i "Add all three apps to the applications key in the .app.src file" + $t perl -ni.bak -e 'print;if ($$.==7) {print "\t\tapp_one,\n\t\tapp_two,\n\t\tapp_three,\n"}' $(APP)/src/$(APP).app.src +endif + + $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:ensure_all_started($(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 all apps were covered by default" + $t test -f $(APP)/logs/ct_run.*/app_one_app.COVER.html + $t test -f $(APP)/logs/ct_run.*/app_two_app.COVER.html + $t test -f $(APP)/logs/ct_run.*/app_three_app.COVER.html + +cover-ct-incl-deps: 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 $v + + $i "Add Cowboy 1.0.0 to the list of dependencies" + $t perl -ni.bak -e 'print;if ($$.==1) {print "DEPS = cowboy\ndep_cowboy_commit = 1.0.0\n"}' $(APP)/Makefile + +ifdef LEGACY + $i "Add Cowboy to the applications key in the .app.src file" + $t perl -ni.bak -e 'print;if ($$.==7) {print "\t\tcowboy,\n"}' $(APP)/src/$(APP).app.src +endif + + $i "Add Cowboy and Cowlib to the code coverage" + $t perl -ni.bak -e 'print;if ($$.==1) {print "COVER_DEPS = cowboy cowlib\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:ensure_all_started($(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 Cowboy and Cowlib were covered, but Ranch wasn't" + $t test -f $(APP)/logs/ct_run.*/cowboy_app.COVER.html + $t test -f $(APP)/logs/ct_run.*/cow_http_hd.COVER.html + $t ! test -e $(APP)/logs/ct_run.*/ranch_app.COVER.html + cover-custom-dir: build clean $i "Bootstrap a new OTP application named $(APP)" @@ -141,6 +258,132 @@ cover-eunit-apps-only: build clean $i "Check that the generated file exists" $t test -f $(APP)/apps/my_app/cover/eunit.coverdata +cover-eunit-incl-apps: 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 $v + + $i "Create a new application app_one" + $t $(MAKE) -C $(APP) new-app in=app_one $v + + $i "Create a new application app_two" + $t $(MAKE) -C $(APP) new-app in=app_two $v + + $i "Create a new application app_three" + $t $(MAKE) -C $(APP) new-app in=app_three $v + + $i "Add all three apps to LOCAL_DEPS" + $t perl -ni.bak -e 'print;if ($$.==1) {print "LOCAL_DEPS = app_one app_two app_three\n"}' $(APP)/Makefile + +ifdef LEGACY + $i "Add all three apps to the applications key in the .app.src file" + $t perl -ni.bak -e 'print;if ($$.==7) {print "\t\tapp_one,\n\t\tapp_two,\n\t\tapp_three,\n"}' $(APP)/src/$(APP).app.src +endif + + $i "Add app_one and app_three to the code coverage" + $t perl -ni.bak -e 'print;if ($$.==1) {print "COVER_APPS = app_one app_three\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_one and app_three were covered, but app_two wasn't" + $t test -f $(APP)/cover/app_one_app.COVER.html + $t test -f $(APP)/cover/app_three_app.COVER.html + $t ! test -e $(APP)/cover/app_two_app.COVER.html + +cover-eunit-incl-apps-default: 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 $v + + $i "Create a new application app_one" + $t $(MAKE) -C $(APP) new-app in=app_one $v + + $i "Create a new application app_two" + $t $(MAKE) -C $(APP) new-app in=app_two $v + + $i "Create a new application app_three" + $t $(MAKE) -C $(APP) new-app in=app_three $v + + $i "Add all three apps to LOCAL_DEPS" + $t perl -ni.bak -e 'print;if ($$.==1) {print "LOCAL_DEPS = app_one app_two app_three\n"}' $(APP)/Makefile + +ifdef LEGACY + $i "Add all three apps to the applications key in the .app.src file" + $t perl -ni.bak -e 'print;if ($$.==7) {print "\t\tapp_one,\n\t\tapp_two,\n\t\tapp_three,\n"}' $(APP)/src/$(APP).app.src +endif + + $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 all apps were covered by default" + $t test -f $(APP)/cover/app_one_app.COVER.html + $t test -f $(APP)/cover/app_two_app.COVER.html + $t test -f $(APP)/cover/app_three_app.COVER.html + +cover-eunit-incl-deps: 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 $v + + $i "Add Cowboy 1.0.0 to the list of dependencies" + $t perl -ni.bak -e 'print;if ($$.==1) {print "DEPS = cowboy\ndep_cowboy_commit = 1.0.0\n"}' $(APP)/Makefile + +ifdef LEGACY + $i "Add Cowboy to the applications key in the .app.src file" + $t perl -ni.bak -e 'print;if ($$.==7) {print "\t\tcowboy,\n"}' $(APP)/src/$(APP).app.src +endif + + $i "Add Cowboy and Cowlib to the code coverage" + $t perl -ni.bak -e 'print;if ($$.==1) {print "COVER_DEPS = cowboy cowlib\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 Cowboy and Cowlib were covered, but Ranch wasn't" + $t test -f $(APP)/cover/cowboy_app.COVER.html + $t test -f $(APP)/cover/cow_http_hd.COVER.html + $t ! test -e $(APP)/cover/ranch_app.COVER.html + cover-proper: build clean $i "Bootstrap a new OTP application named $(APP)" -- cgit v1.2.3