Browse Source

Add EUNIT_ERL_OPTS variable

Loïc Hoguin 9 years ago
parent
commit
1624b70fe6
3 changed files with 34 additions and 5 deletions
  1. 7 0
      doc/src/guide/eunit.asciidoc
  2. 5 4
      plugins/eunit.mk
  3. 22 1
      test/plugin_eunit.mk

+ 7 - 0
doc/src/guide/eunit.asciidoc

@@ -59,6 +59,13 @@ At the time of writing, the only available option is `verbose`:
 [source,make]
 EUNIT_OPTS = verbose
 
+The `EUNIT_ERL_OPTS` variable allows you to specify options
+to be passed to `erl` when running EUnit tests. For example,
+you can load the 'vm.args' and 'sys.config' files:
+
+[source,make]
+EUNIT_ERL_OPTS = -args_file rel/vm.args -config rel/sys.config
+
 === Usage
 
 To run all tests (including EUnit):

+ 5 - 4
plugins/eunit.mk

@@ -7,6 +7,7 @@
 # Configuration
 
 EUNIT_OPTS ?=
+EUNIT_ERL_OPTS ?=
 
 # Core targets.
 
@@ -40,15 +41,15 @@ define eunit.erl
 	halt()
 endef
 
-EUNIT_PATHS = -pa $(TEST_DIR) $(DEPS_DIR)/*/ebin $(APPS_DIR)/*/ebin ebin
+EUNIT_ERL_OPTS += -pa $(TEST_DIR) $(DEPS_DIR)/*/ebin $(APPS_DIR)/*/ebin ebin
 
 ifdef t
 ifeq (,$(findstring :,$(t)))
 eunit: test-build
-	$(gen_verbose) $(call erlang,$(call eunit.erl,['$(t)']),$(EUNIT_PATHS))
+	$(gen_verbose) $(call erlang,$(call eunit.erl,['$(t)']),$(EUNIT_ERL_OPTS))
 else
 eunit: test-build
-	$(gen_verbose) $(call erlang,$(call eunit.erl,fun $(t)/0),$(EUNIT_PATHS))
+	$(gen_verbose) $(call erlang,$(call eunit.erl,fun $(t)/0),$(EUNIT_ERL_OPTS))
 endif
 else
 EUNIT_EBIN_MODS = $(notdir $(basename $(call core_find,ebin/,*.beam)))
@@ -57,7 +58,7 @@ EUNIT_MODS = $(foreach mod,$(EUNIT_EBIN_MODS) $(filter-out \
 	$(patsubst %,%_tests,$(EUNIT_EBIN_MODS)),$(EUNIT_TEST_MODS)),'$(mod)')
 
 eunit: test-build $(if $(IS_APP),,apps-eunit)
-	$(gen_verbose) $(call erlang,$(call eunit.erl,[$(call comma_list,$(EUNIT_MODS))]),$(EUNIT_PATHS))
+	$(gen_verbose) $(call erlang,$(call eunit.erl,[$(call comma_list,$(EUNIT_MODS))]),$(EUNIT_ERL_OPTS))
 
 ifneq ($(ALL_APPS_DIRS),)
 apps-eunit:

+ 22 - 1
test/plugin_eunit.mk

@@ -1,6 +1,6 @@
 # EUnit plugin.
 
-EUNIT_CASES = all apps-only check fun mod test-dir tests
+EUNIT_CASES = all apps-only check erl-opts fun mod test-dir tests
 EUNIT_TARGETS = $(addprefix eunit-,$(EUNIT_CASES))
 EUNIT_CLEAN_TARGETS = $(addprefix clean-,$(EUNIT_TARGETS))
 
@@ -103,6 +103,27 @@ eunit-check: build clean-eunit-check
 	$i "Check that EUnit runs on 'make check'"
 	$t $(MAKE) -C $(APP) check | grep -q "Test passed."
 
+eunit-erl-opts: build clean-eunit-erl-opts
+
+	$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 "Set EUNIT_ERL_OPTS in the Makefile"
+	$t perl -ni.bak -e 'print;if ($$.==1) {print "EUNIT_ERL_OPTS = -eval \"erlang:display(hello).\" \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 "Check that EUnit uses EUNIT_ERL_OPTS"
+	$t $(MAKE) -C $(APP) eunit | grep -q "hello"
+
 eunit-fun: build clean-eunit-fun
 
 	$i "Bootstrap a new OTP application named $(APP)"