eunit.mk 1.8 KB

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