eunit.mk 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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. ifeq ($(strip $(TEST_DIR)),)
  7. TAGGED_EUNIT_TESTS = {dir,"ebin"}
  8. else
  9. ifeq ($(wildcard $(TEST_DIR)),)
  10. TAGGED_EUNIT_TESTS = {dir,"ebin"}
  11. else
  12. # All modules in TEST_DIR
  13. TEST_DIR_MODS = $(notdir $(basename $(shell find $(TEST_DIR) -type f -name *.beam)))
  14. # All modules in 'ebin'
  15. EUNIT_EBIN_MODS = $(notdir $(basename $(shell find ebin -type f -name *.beam)))
  16. # Only those modules in TEST_DIR with no matching module in 'ebin'.
  17. # This is done to avoid some tests being executed twice.
  18. EUNIT_MODS = $(filter-out $(patsubst %,%_tests,$(EUNIT_EBIN_MODS)),$(TEST_DIR_MODS))
  19. TAGGED_EUNIT_TESTS = {dir,"ebin"} $(foreach mod,$(EUNIT_MODS),$(shell echo $(mod) | sed -e 's/\(.*\)/{module,\1}/g'))
  20. endif
  21. endif
  22. EUNIT_OPTS ?=
  23. # Utility functions
  24. define str-join
  25. $(shell echo '$(strip $(1))' | sed -e "s/ /,/g")
  26. endef
  27. # Core targets.
  28. tests:: eunit
  29. help::
  30. @printf "%s\n" "" \
  31. "EUnit targets:" \
  32. " eunit Run all the EUnit tests for this project"
  33. # Plugin-specific targets.
  34. EUNIT_RUN = $(ERL) \
  35. -pa $(TEST_DIR) $(DEPS_DIR)/*/ebin \
  36. -pz ebin \
  37. -eval 'case eunit:test([$(call str-join,$(TAGGED_EUNIT_TESTS))], [$(EUNIT_OPTS)]) of ok -> halt(0); error -> halt(1) end.'
  38. eunit: test-build
  39. $(gen_verbose) $(EUNIT_RUN)