eunit.mk 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. # Copyright (c) 2014, Enrique Fernandez <enrique.fernandez@erlang-solutions.com>
  2. # Copyright (c) 2015, Loïc Hoguin <essen@ninenines.eu>
  3. # This file is contributed to erlang.mk and subject to the terms of the ISC License.
  4. .PHONY: eunit
  5. # Configuration
  6. # All modules in TEST_DIR
  7. ifeq ($(strip $(TEST_DIR)),)
  8. TEST_DIR_MODS =
  9. else
  10. TEST_DIR_MODS = $(notdir $(basename $(shell find $(TEST_DIR) -type f -name *.beam)))
  11. endif
  12. # All modules in 'ebin'
  13. EUNIT_EBIN_MODS = $(notdir $(basename $(shell find ebin -type f -name *.beam)))
  14. # Only those modules in TEST_DIR with no matching module in 'ebin'.
  15. # This is done to avoid some tests being executed twice.
  16. EUNIT_MODS = $(filter-out $(patsubst %,%_tests,$(EUNIT_EBIN_MODS)),$(TEST_DIR_MODS))
  17. TAGGED_EUNIT_TESTS = $(foreach mod,$(EUNIT_EBIN_MODS) $(EUNIT_MODS),{module,$(mod)})
  18. EUNIT_OPTS ?=
  19. # Utility functions
  20. define str-join
  21. $(shell echo '$(strip $(1))' | sed -e "s/ /,/g")
  22. endef
  23. # Core targets.
  24. tests:: eunit
  25. help::
  26. @printf "%s\n" "" \
  27. "EUnit targets:" \
  28. " eunit Run all the EUnit tests for this project"
  29. # Plugin-specific targets.
  30. EUNIT_RUN_BEFORE ?=
  31. EUNIT_RUN_AFTER ?=
  32. EUNIT_RUN = $(ERL) \
  33. -pa $(TEST_DIR) $(DEPS_DIR)/*/ebin \
  34. -pz ebin \
  35. $(EUNIT_RUN_BEFORE) \
  36. -eval 'case eunit:test([$(call str-join,$(TAGGED_EUNIT_TESTS))],\
  37. [$(EUNIT_OPTS)]) of ok -> ok; error -> halt(1) end.' \
  38. $(EUNIT_RUN_AFTER) \
  39. -eval 'halt(0).'
  40. eunit: test-build
  41. $(gen_verbose) $(EUNIT_RUN)