Browse Source

Accumulate eunit failures in multi-apps

Stanislav Ovchar 8 years ago
parent
commit
24beec0a19
2 changed files with 67 additions and 2 deletions
  1. 3 1
      plugins/eunit.mk
  2. 64 1
      test/plugin_eunit.mk

+ 3 - 1
plugins/eunit.mk

@@ -63,6 +63,8 @@ eunit: test-build $(if $(IS_APP),,apps-eunit)
 
 
 ifneq ($(ALL_APPS_DIRS),)
 ifneq ($(ALL_APPS_DIRS),)
 apps-eunit:
 apps-eunit:
-	$(verbose) for app in $(ALL_APPS_DIRS); do $(MAKE) -C $$app eunit IS_APP=1; done
+	$(verbose) eunit_retcode=0 ; for app in $(ALL_APPS_DIRS); do $(MAKE) -C $$app eunit IS_APP=1; \
+		[ $$? -ne 0 ] && eunit_retcode=1 ; done ; \
+		exit $$eunit_retcode
 endif
 endif
 endif
 endif

+ 64 - 1
test/plugin_eunit.mk

@@ -1,6 +1,6 @@
 # EUnit plugin.
 # EUnit plugin.
 
 
-EUNIT_CASES = all apps-only check erl-opts fun mod priv test-dir tests
+EUNIT_CASES = all apps-only check erl-opts fun mod priv test-dir tests multiapps-no-root-check-exit-code
 EUNIT_TARGETS = $(addprefix eunit-,$(EUNIT_CASES))
 EUNIT_TARGETS = $(addprefix eunit-,$(EUNIT_CASES))
 
 
 .PHONY: eunit $(EUNIT_TARGETS)
 .PHONY: eunit $(EUNIT_TARGETS)
@@ -79,6 +79,69 @@ eunit-apps-only: build clean
 	$i "Check that EUnit runs tests"
 	$i "Check that EUnit runs tests"
 	$t $(MAKE) -C $(APP) eunit | grep -q "Test passed."
 	$t $(MAKE) -C $(APP) eunit | grep -q "Test passed."
 
 
+	$i "Check that EUnit runs tests"
+
+eunit-multiapps-no-root-check-exit-code: 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_app1"
+		$t $(MAKE) -C $(APP) new-app in=my_app1 $v
+
+		$i "Create a new application named my_app2"
+		$t $(MAKE) -C $(APP) new-app in=my_app2 $v
+
+		$i "Create a new library named my_lib"
+		$t $(MAKE) -C $(APP) new-lib in=my_lib $v
+
+		$i "Check that EUnit detects no tests"
+		$t $(MAKE) -C $(APP) eunit | grep -q "There were no tests to run."
+
+		$i "Generate a module containing broken EUnit tests in my_app1"
+		$t printf "%s\n" \
+			"-module(my_app1)." \
+			"-ifdef(TEST)." \
+			"-include_lib(\"eunit/include/eunit.hrl\")." \
+			"bad_test() -> ?assert(0 =:= 1)." \
+			"-endif." > $(APP)/apps/my_app1/src/my_app1.erl
+
+		$i "Generate a module containing EUnit good tests in my_app2"
+		$t printf "%s\n" \
+			"-module(my_app2)." \
+			"-ifdef(TEST)." \
+			"-include_lib(\"eunit/include/eunit.hrl\")." \
+			"ok_test() -> ok." \
+			"-endif." > $(APP)/apps/my_app2/src/my_app2.erl
+
+		$i "Generate a module containing EUnit tests in my_lib"
+		$t printf "%s\n" \
+			"-module(my_lib)." \
+			"-ifdef(TEST)." \
+			"-include_lib(\"eunit/include/eunit.hrl\")." \
+			"ok_test() -> ok." \
+			"-endif." > $(APP)/apps/my_lib/src/my_lib.erl
+
+		$i "Check exit code of EUnit for the module with broken test should be non-zero"
+		$t ( set +e; $(MAKE) -C $(APP)/apps/my_app1 eunit ; if [ $$? -ne 0 ] ; then \
+			echo "Test passed exit-code is non-zero" ; \
+		else \
+			echo "Test failed exit-code is zero" ; \
+			exit 100; \
+		fi )
+
+		$i "Check exit code of EUnit for the whole project with broken test should be non-zero"
+		$t ( set +e; $(MAKE) -C $(APP) eunit ; if [ $$? -ne 0 ] ; then \
+			echo "Test passed exit-code is non-zero" ; \
+		else \
+			echo "Test failed exit-code is zero" ; \
+			exit 100; \
+		fi )
+
+
+
 eunit-check: build clean
 eunit-check: build clean
 
 
 	$i "Bootstrap a new OTP application named $(APP)"
 	$i "Bootstrap a new OTP application named $(APP)"