eunit.mk 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. # Copyright (c) 2015-2016, Loïc Hoguin <essen@ninenines.eu>
  2. # Copyright (c) 2014, Enrique Fernandez <enrique.fernandez@erlang-solutions.com>
  3. # This file is contributed to erlang.mk and subject to the terms of the ISC License.
  4. .PHONY: eunit apps-eunit
  5. # Configuration
  6. EUNIT_OPTS ?=
  7. EUNIT_ERL_OPTS ?=
  8. # Core targets.
  9. tests:: eunit
  10. help::
  11. $(verbose) printf "%s\n" "" \
  12. "EUnit targets:" \
  13. " eunit Run all the EUnit tests for this project"
  14. # Plugin-specific targets.
  15. define eunit.erl
  16. case "$(COVER)" of
  17. "" -> ok;
  18. _ ->
  19. case cover:compile_beam_directory("ebin") of
  20. {error, _} -> halt(1);
  21. _ -> ok
  22. end
  23. end,
  24. case eunit:test($1, [$(EUNIT_OPTS)]) of
  25. ok -> ok;
  26. error -> halt(2)
  27. end,
  28. case "$(COVER)" of
  29. "" -> ok;
  30. _ ->
  31. cover:export("$(COVER_DATA_DIR)/eunit.coverdata")
  32. end,
  33. halt()
  34. endef
  35. EUNIT_ERL_OPTS += -pa $(TEST_DIR) $(DEPS_DIR)/*/ebin $(APPS_DIR)/*/ebin $(CURDIR)/ebin
  36. ifdef t
  37. ifeq (,$(findstring :,$(t)))
  38. eunit: test-build cover-data-dir
  39. $(gen_verbose) $(call erlang,$(call eunit.erl,['$(t)']),$(EUNIT_ERL_OPTS))
  40. else
  41. eunit: test-build cover-data-dir
  42. $(gen_verbose) $(call erlang,$(call eunit.erl,fun $(t)/0),$(EUNIT_ERL_OPTS))
  43. endif
  44. else
  45. EUNIT_EBIN_MODS = $(notdir $(basename $(ERL_FILES) $(BEAM_FILES)))
  46. EUNIT_TEST_MODS = $(notdir $(basename $(call core_find,$(TEST_DIR)/,*.erl)))
  47. EUNIT_MODS = $(foreach mod,$(EUNIT_EBIN_MODS) $(filter-out \
  48. $(patsubst %,%_tests,$(EUNIT_EBIN_MODS)),$(EUNIT_TEST_MODS)),'$(mod)')
  49. eunit: test-build $(if $(IS_APP),,apps-eunit) cover-data-dir
  50. $(gen_verbose) $(call erlang,$(call eunit.erl,[$(call comma_list,$(EUNIT_MODS))]),$(EUNIT_ERL_OPTS))
  51. ifneq ($(ALL_APPS_DIRS),)
  52. apps-eunit:
  53. $(verbose) eunit_retcode=0 ; for app in $(ALL_APPS_DIRS); do $(MAKE) -C $$app eunit IS_APP=1; \
  54. [ $$? -ne 0 ] && eunit_retcode=1 ; done ; \
  55. exit $$eunit_retcode
  56. endif
  57. endif