Browse Source

Improve ct/eunit tests

Also don't run eunit if there's no src/test directory.
Loïc Hoguin 6 years ago
parent
commit
acd16b52d1
3 changed files with 15 additions and 13 deletions
  1. 2 0
      plugins/eunit.mk
  2. 2 2
      test/plugin_ct.mk
  3. 11 11
      test/plugin_eunit.mk

+ 2 - 0
plugins/eunit.mk

@@ -64,7 +64,9 @@ EUNIT_MODS = $(foreach mod,$(EUNIT_EBIN_MODS) $(filter-out \
 	$(patsubst %,%_tests,$(EUNIT_EBIN_MODS)),$(EUNIT_TEST_MODS)),'$(mod)')
 
 eunit: test-build $(if $(IS_APP)$(ROOT_DIR),,apps-eunit) cover-data-dir
+ifneq ($(wildcard src/ $(TEST_DIR)),)
 	$(gen_verbose) $(call erlang,$(call eunit.erl,[$(call comma_list,$(EUNIT_MODS))]),$(EUNIT_ERL_OPTS))
+endif
 
 ifneq ($(ALL_APPS_DIRS),)
 apps-eunit:

+ 2 - 2
test/plugin_ct.mk

@@ -14,7 +14,7 @@ ct-all: build clean
 	$t $(MAKE) -C $(APP) -f erlang.mk bootstrap $v
 
 	$i "Check that Common Test detects no tests"
-	$t $(MAKE) -C $(APP) ct | grep -q "Nothing to be done for 'ct'."
+	$t $(MAKE) -C $(APP) ct | grep -c "Nothing to be done for 'ct'." | grep -q 1
 
 	$i "Generate a Common Test suite"
 	$t mkdir $(APP)/test
@@ -100,7 +100,7 @@ ct-apps-only: build clean
 		"random_int() -> 4." > $(APP)/apps/my_lib/src/my_lib.erl
 
 	$i "Check that Common Test detects no tests"
-	$t $(MAKE) -C $(APP) ct | grep -q "Nothing to be done for 'ct'."
+	$t $(MAKE) -C $(APP) ct | grep -c "Nothing to be done for 'ct'." | grep -q 2
 
 	$i "Generate a Common Test suite in my_app"
 	$t mkdir $(APP)/apps/my_app/test

+ 11 - 11
test/plugin_eunit.mk

@@ -14,7 +14,7 @@ eunit-all: build clean
 	$t $(MAKE) -C $(APP) -f erlang.mk bootstrap $v
 
 	$i "Check that EUnit detects no tests"
-	$t $(MAKE) -C $(APP) eunit | grep -q "There were no tests to run."
+	$t $(MAKE) -C $(APP) eunit | grep -c "There were no tests to run." | grep -q 1
 
 	$i "Generate a module containing EUnit tests"
 	$t printf "%s\n" \
@@ -32,7 +32,7 @@ eunit-all: build clean
 	$t $(ERL) -pa $(APP)/ebin -eval 'code:load_file($(APP)), false = erlang:function_exported($(APP), ok_test, 0), halt()'
 
 	$i "Check that EUnit runs tests"
-	$t $(MAKE) -C $(APP) eunit | grep -q "Test passed."
+	$t $(MAKE) -C $(APP) eunit | grep -c "Test passed." | grep -q 1
 
 	$i "Add a failing test to the module"
 	$t printf "%s\n" \
@@ -112,7 +112,7 @@ eunit-apps-one-app-tested: build clean
 		"-endif." > $(APP)/apps/my_lib/src/my_lib.erl
 
 	$i "Run EUnit on my_app only"
-	$t $(MAKE) -C $(APP)/apps/my_app eunit | grep "Test passed." | wc -l | grep -q "1"
+	$t $(MAKE) -C $(APP)/apps/my_app eunit | grep -c "Test passed." | grep -q 1
 
 eunit-apps-only: build clean
 
@@ -128,7 +128,7 @@ eunit-apps-only: build clean
 	$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."
+	$t $(MAKE) -C $(APP) eunit | grep -c "There were no tests to run." | grep -q 2
 
 	$i "Generate a module containing EUnit tests in my_app"
 	$t printf "%s\n" \
@@ -147,7 +147,7 @@ eunit-apps-only: build clean
 		"-endif." > $(APP)/apps/my_lib/src/my_lib.erl
 
 	$i "Check that EUnit runs tests"
-	$t $(MAKE) -C $(APP) eunit | grep -q "Test passed."
+	$t $(MAKE) -C $(APP) eunit | grep -c "Test passed." | grep -q 2
 
 eunit-apps-only-error: build clean
 
@@ -166,7 +166,7 @@ eunit-apps-only-error: build clean
 	$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."
+	$t $(MAKE) -C $(APP) eunit | grep -c "There were no tests to run." | grep -q 3
 
 	$i "Generate a module containing broken EUnit tests in my_app1"
 	$t printf "%s\n" \
@@ -214,7 +214,7 @@ eunit-check: build clean
 		"-endif." > $(APP)/src/$(APP).erl
 
 	$i "Check that EUnit runs on 'make check'"
-	$t $(MAKE) -C $(APP) check | grep -q "Test passed."
+	$t $(MAKE) -C $(APP) check | grep -c "Test passed." | grep -q 1
 
 eunit-erl-opts: build clean
 
@@ -235,7 +235,7 @@ eunit-erl-opts: build clean
 		"-endif." > $(APP)/src/$(APP).erl
 
 	$i "Check that EUnit uses EUNIT_ERL_OPTS"
-	$t $(MAKE) -C $(APP) eunit | grep -q "hello"
+	$t $(MAKE) -C $(APP) eunit | grep -c "hello" | grep -q 1
 
 eunit-fun: build clean
 
@@ -298,7 +298,7 @@ eunit-priv: build clean
 		"-endif." > $(APP)/src/$(APP).erl
 
 	$i "Check that EUnit can resolve the priv_dir"
-	$t $(MAKE) -C $(APP) tests | grep -q "Test passed."
+	$t $(MAKE) -C $(APP) tests | grep -c "Test passed." | grep -q 1
 
 eunit-test-dir: build clean
 
@@ -323,7 +323,7 @@ eunit-test-dir: build clean
 		"log_test() -> os:cmd(\"echo $(APP)_tests >> eunit.log\")." > $(APP)/test/$(APP)_tests.erl
 
 	$i "Check that EUnit runs both tests"
-	$t $(MAKE) -C $(APP) eunit | grep -q "2 tests passed."
+	$t $(MAKE) -C $(APP) eunit | grep -c "2 tests passed." | grep -q 1
 
 	$i "Check that tests were both run only once"
 	$t printf "%s\n" $(APP) $(APP)_tests | cmp $(APP)/eunit.log -
@@ -344,4 +344,4 @@ eunit-tests: build clean
 		"-endif." > $(APP)/src/$(APP).erl
 
 	$i "Check that EUnit runs on 'make tests'"
-	$t $(MAKE) -C $(APP) tests | grep -q "Test passed."
+	$t $(MAKE) -C $(APP) tests | grep -c "Test passed." | grep -q 1