aboutsummaryrefslogtreecommitdiffstats
path: root/plugins/eunit.mk
diff options
context:
space:
mode:
authorLoïc Hoguin <[email protected]>2015-07-02 18:35:44 +0200
committerLoïc Hoguin <[email protected]>2015-07-02 18:35:44 +0200
commit6a3bf18655384cbd534308104d82b1ae0f66c228 (patch)
tree65a4d3a9c0910774eb664ac5895af18bb623cbf1 /plugins/eunit.mk
parent061d4491da416ad23a8d470a4198a0cd608b7e0f (diff)
downloaderlang.mk-6a3bf18655384cbd534308104d82b1ae0f66c228.tar.gz
erlang.mk-6a3bf18655384cbd534308104d82b1ae0f66c228.tar.bz2
erlang.mk-6a3bf18655384cbd534308104d82b1ae0f66c228.zip
Reduce dependency on external programs
This commit implements a core_find and core_ls function that can be used to list files recursively or not. A few other minute changes are included and a couple hacks removed.
Diffstat (limited to 'plugins/eunit.mk')
-rw-r--r--plugins/eunit.mk58
1 files changed, 27 insertions, 31 deletions
diff --git a/plugins/eunit.mk b/plugins/eunit.mk
index b9f2856..79add79 100644
--- a/plugins/eunit.mk
+++ b/plugins/eunit.mk
@@ -6,28 +6,8 @@
# Configuration
-# All modules in TEST_DIR
-ifeq ($(strip $(TEST_DIR)),)
-TEST_DIR_MODS =
-else
-TEST_DIR_MODS = $(notdir $(basename $(shell find $(TEST_DIR) -type f -name *.beam)))
-endif
-
-# All modules in 'ebin'
-EUNIT_EBIN_MODS = $(notdir $(basename $(shell find ebin -type f -name *.beam)))
-# Only those modules in TEST_DIR with no matching module in 'ebin'.
-# This is done to avoid some tests being executed twice.
-EUNIT_MODS = $(filter-out $(patsubst %,%_tests,$(EUNIT_EBIN_MODS)),$(TEST_DIR_MODS))
-TAGGED_EUNIT_TESTS = $(foreach mod,$(EUNIT_EBIN_MODS) $(EUNIT_MODS),{module,$(mod)})
-
EUNIT_OPTS ?=
-# Utility functions
-
-define str-join
- $(shell echo '$(strip $(1))' | sed -e "s/ /,/g")
-endef
-
# Core targets.
tests:: eunit
@@ -39,16 +19,32 @@ help::
# Plugin-specific targets.
-EUNIT_RUN_BEFORE ?=
-EUNIT_RUN_AFTER ?=
-EUNIT_RUN = $(ERL) \
- -pa $(TEST_DIR) $(DEPS_DIR)/*/ebin \
- -pz ebin \
- $(EUNIT_RUN_BEFORE) \
- -eval 'case eunit:test([$(call str-join,$(TAGGED_EUNIT_TESTS))],\
- [$(EUNIT_OPTS)]) of ok -> ok; error -> halt(1) end.' \
- $(EUNIT_RUN_AFTER) \
- -eval 'halt(0).'
+define eunit.erl
+ case "$(COVER)" of
+ "" -> ok;
+ _ ->
+ case cover:compile_beam_directory("ebin") of
+ {error, _} -> halt(1);
+ _ -> ok
+ end
+ end,
+ case eunit:test([$(call comma_list,$(1))], [$(EUNIT_OPTS)]) of
+ ok -> ok;
+ error -> halt(2)
+ end,
+ case "$(COVER)" of
+ "" -> ok;
+ _ ->
+ cover:export("eunit.coverdata")
+ end,
+ halt()
+endef
+
+EUNIT_EBIN_MODS = $(notdir $(basename $(call core_find,ebin/,*.beam)))
+EUNIT_TEST_MODS = $(notdir $(basename $(call core_find,$(TEST_DIR)/,*.beam)))
+EUNIT_MODS = $(foreach mod,$(EUNIT_EBIN_MODS) $(filter-out \
+ $(patsubst %,%_tests,$(EUNIT_EBIN_MODS)),$(EUNIT_TEST_MODS)),{module,'$(mod)'})
eunit: test-build
- $(gen_verbose) $(EUNIT_RUN)
+ $(gen_verbose) $(ERL) -pa $(TEST_DIR) $(DEPS_DIR)/*/ebin ebin \
+ -eval "$(subst $(newline),,$(subst ",\",$(call eunit.erl,$(EUNIT_MODS))))"