eunit.mk 1.3 KB

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