eunit.mk 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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. $(call cover.erl)
  17. CoverSetup(),
  18. case eunit:test($1, [$(EUNIT_OPTS)]) of
  19. ok -> ok;
  20. error -> halt(2)
  21. end,
  22. CoverExport("$(call core_native_path,$(COVER_DATA_DIR))/eunit.coverdata"),
  23. halt()
  24. endef
  25. EUNIT_ERL_OPTS += -pa $(TEST_DIR) $(CURDIR)/ebin
  26. ifdef t
  27. ifeq (,$(findstring :,$(t)))
  28. eunit: test-build cover-data-dir
  29. $(gen_verbose) $(call erlang,$(call eunit.erl,['$(t)']),$(EUNIT_ERL_OPTS))
  30. else
  31. eunit: test-build cover-data-dir
  32. $(gen_verbose) $(call erlang,$(call eunit.erl,fun $(t)/0),$(EUNIT_ERL_OPTS))
  33. endif
  34. else
  35. EUNIT_EBIN_MODS = $(notdir $(basename $(ERL_FILES) $(BEAM_FILES)))
  36. EUNIT_TEST_MODS = $(notdir $(basename $(call core_find,$(TEST_DIR)/,*.erl)))
  37. EUNIT_MODS = $(foreach mod,$(EUNIT_EBIN_MODS) $(filter-out \
  38. $(patsubst %,%_tests,$(EUNIT_EBIN_MODS)),$(EUNIT_TEST_MODS)),'$(mod)')
  39. eunit: test-build $(if $(IS_APP)$(ROOT_DIR),,apps-eunit) cover-data-dir
  40. ifneq ($(wildcard src/ $(TEST_DIR)),)
  41. $(gen_verbose) $(call erlang,$(call eunit.erl,[$(call comma_list,$(EUNIT_MODS))]),$(EUNIT_ERL_OPTS))
  42. endif
  43. ifneq ($(ALL_APPS_DIRS),)
  44. apps-eunit: test-build
  45. $(verbose) eunit_retcode=0 ; for app in $(ALL_APPS_DIRS); do $(MAKE) -C $$app eunit IS_APP=1; \
  46. [ $$? -ne 0 ] && eunit_retcode=1 ; done ; \
  47. exit $$eunit_retcode
  48. endif
  49. endif