aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLoïc Hoguin <[email protected]>2015-12-24 15:26:45 +0100
committerLoïc Hoguin <[email protected]>2015-12-24 15:26:45 +0100
commit1624b70fe633229ce71e70dd3a7be5dcb8c47583 (patch)
tree3acdbfca707d1f279df0aa2c641cc0a59156eae5
parent3669bd9d3680ee5a353cad9a938b593248babba0 (diff)
downloaderlang.mk-1624b70fe633229ce71e70dd3a7be5dcb8c47583.tar.gz
erlang.mk-1624b70fe633229ce71e70dd3a7be5dcb8c47583.tar.bz2
erlang.mk-1624b70fe633229ce71e70dd3a7be5dcb8c47583.zip
Add EUNIT_ERL_OPTS variable
-rw-r--r--doc/src/guide/eunit.asciidoc7
-rw-r--r--plugins/eunit.mk9
-rw-r--r--test/plugin_eunit.mk23
3 files changed, 34 insertions, 5 deletions
diff --git a/doc/src/guide/eunit.asciidoc b/doc/src/guide/eunit.asciidoc
index 0295726..591d4c6 100644
--- a/doc/src/guide/eunit.asciidoc
+++ b/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):
diff --git a/plugins/eunit.mk b/plugins/eunit.mk
index 36de6e7..f6afa34 100644
--- a/plugins/eunit.mk
+++ b/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:
diff --git a/test/plugin_eunit.mk b/test/plugin_eunit.mk
index 26c0997..61f0e92 100644
--- a/test/plugin_eunit.mk
+++ b/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)"