Browse Source

Add the test directory in the list of paths for proper

Loïc Hoguin 7 years ago
parent
commit
e0f8b46b0d
3 changed files with 49 additions and 4 deletions
  1. 6 2
      plugins/proper.mk
  2. 40 0
      test/plugin_proper.mk
  3. 3 2
      test/plugin_triq.mk

+ 6 - 2
plugins/proper.mk

@@ -9,7 +9,10 @@ ifeq ($(filter proper,$(DEPS) $(TEST_DEPS)),proper)
 tests:: proper
 
 define proper_check.erl
-	code:add_pathsa(["$(call core_native_path,$(CURDIR)/ebin)", "$(call core_native_path,$(DEPS_DIR)/*/ebin)"]),
+	code:add_pathsa([
+		"$(call core_native_path,$(CURDIR)/ebin)",
+		"$(call core_native_path,$(DEPS_DIR)/*/ebin)",
+		"$(call core_native_path,$(TEST_DIR))"]),
 	Module = fun(M) ->
 		[true] =:= lists:usort([
 			case atom_to_list(F) of
@@ -47,7 +50,8 @@ proper: test-build
 endif
 else
 proper: test-build
-	$(eval MODULES := $(patsubst %,'%',$(sort $(notdir $(basename $(wildcard ebin/*.beam))))))
+	$(eval MODULES := $(patsubst %,'%',$(sort $(notdir $(basename \
+		$(wildcard ebin/*.beam) $(call core_find,$(TEST_DIR)/,*.beam))))))
 	$(gen_verbose) $(call erlang,$(call proper_check.erl,all,undefined,$(MODULES)))
 endif
 endif

+ 40 - 0
test/plugin_proper.mk

@@ -0,0 +1,40 @@
+# PropEr plugin.
+
+PROPER_CASES = test-dir
+PROPER_TARGETS = $(addprefix proper-,$(PROPER_CASES))
+
+.PHONY: proper $(PROPER_TARGETS)
+
+proper: $(PROPER_TARGETS)
+
+proper-test-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 $v
+
+	$i "Add PropEr to the list of dependencies"
+	$t perl -ni.bak -e 'print;if ($$.==1) {print "DEPS = proper\n"}' $(APP)/Makefile
+
+	$i "Generate a module containing Proper properties"
+	$t printf "%s\n" \
+		"-module($(APP))." \
+		"-ifdef(TEST)." \
+		"-include_lib(\"proper/include/proper.hrl\")." \
+		"prop_foo() -> ?FORALL(_, any(), true)." \
+		"-endif." > $(APP)/src/$(APP).erl
+
+	$i "Generate a module containing PropEr properties in TEST_DIR"
+	$t mkdir $(APP)/test
+	$t printf "%s\n" \
+		"-module($(APP)_tests)." \
+		"-include_lib(\"proper/include/proper.hrl\")." \
+		"prop_bar() -> ?FORALL(_, any(), true)." > $(APP)/test/$(APP)_tests.erl
+
+	$i "Run the PropEr plugin"
+	$t $(MAKE) -C $(APP) proper > $(APP)/proper.log
+
+	$i "Check that both properties were checked"
+	$t grep -q prop_foo $(APP)/proper.log
+	$t grep -q prop_bar $(APP)/proper.log

+ 3 - 2
test/plugin_triq.mk

@@ -1,4 +1,4 @@
-# Triq plugin
+# Triq plugin.
 
 TRIQ_CASES = test-dir
 TRIQ_TARGETS = $(addprefix triq-,$(TRIQ_CASES))
@@ -8,6 +8,7 @@ TRIQ_TARGETS = $(addprefix triq-,$(TRIQ_CASES))
 triq: $(TRIQ_TARGETS)
 
 triq-test-dir: build clean
+
 	$i "Bootstrap a new OTP application named $(APP)"
 	$t mkdir $(APP)/
 	$t cp ../erlang.mk $(APP)/
@@ -24,7 +25,7 @@ triq-test-dir: build clean
 		"prop_foo() -> ?FORALL(_, any(), true)." \
 		"-endif." > $(APP)/src/$(APP).erl
 
-	$i "Generate a module containing Triq properies in TEST_DIR"
+	$i "Generate a module containing Triq properties in TEST_DIR"
 	$t mkdir $(APP)/test
 	$t printf "%s\n" \
 		"-module($(APP)_tests)." \