eunit.mk 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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. # All modules in TEST_DIR
  10. TEST_DIR_MODS = $(notdir $(basename $(shell find $(TEST_DIR) -type f -name *.beam)))
  11. # All modules in 'ebin'
  12. EUNIT_EBIN_MODS = $(notdir $(basename $(shell find ebin -type f -name *.beam)))
  13. # Only those modules in TEST_DIR with no matching module in 'ebin'.
  14. # This is done to avoid some tests being executed twice.
  15. EUNIT_MODS = $(filter-out $(patsubst %,%_tests,$(EUNIT_EBIN_MODS)),$(TEST_DIR_MODS))
  16. TAGGED_EUNIT_TESTS = {dir,"ebin"} $(foreach mod,$(EUNIT_MODS),$(shell echo $(mod) | sed -e 's/\(.*\)/{module,\1}/g'))
  17. endif
  18. EUNIT_OPTS ?= verbose
  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 = $(ERL) \
  31. -pa $(TEST_DIR) $(DEPS_DIR)/*/ebin \
  32. -pz ebin \
  33. -eval 'case eunit:test([$(call str-join,$(TAGGED_EUNIT_TESTS))], [$(EUNIT_OPTS)]) of ok -> halt(0); error -> halt(1) end.'
  34. eunit: test-build
  35. $(gen_verbose) $(EUNIT_RUN)