eunit.mk 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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. EUNIT_OPTS ?=
  7. # Core targets.
  8. tests:: eunit
  9. help::
  10. $(verbose) printf "%s\n" "" \
  11. "EUnit targets:" \
  12. " eunit Run all the EUnit tests for this project"
  13. # Plugin-specific targets.
  14. define eunit.erl
  15. case "$(COVER)" of
  16. "" -> ok;
  17. _ ->
  18. case cover:compile_beam_directory("ebin") of
  19. {error, _} -> halt(1);
  20. _ -> ok
  21. end
  22. end,
  23. case eunit:test([$(call comma_list,$(1))], [$(EUNIT_OPTS)]) of
  24. ok -> ok;
  25. error -> halt(2)
  26. end,
  27. case "$(COVER)" of
  28. "" -> ok;
  29. _ ->
  30. cover:export("eunit.coverdata")
  31. end,
  32. halt()
  33. endef
  34. EUNIT_EBIN_MODS = $(notdir $(basename $(call core_find,ebin/,*.beam)))
  35. EUNIT_TEST_MODS = $(notdir $(basename $(call core_find,$(TEST_DIR)/,*.beam)))
  36. EUNIT_MODS = $(foreach mod,$(EUNIT_EBIN_MODS) $(filter-out \
  37. $(patsubst %,%_tests,$(EUNIT_EBIN_MODS)),$(EUNIT_TEST_MODS)),{module,'$(mod)'})
  38. eunit: test-build
  39. $(gen_verbose) $(ERL) -pa $(TEST_DIR) $(DEPS_DIR)/*/ebin ebin \
  40. -eval "$(subst $(newline),,$(subst ",\",$(call eunit.erl,$(EUNIT_MODS))))"