eunit.mk 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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 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("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
  39. $(gen_verbose) $(call erlang,$(call eunit.erl,['$(t)']),$(EUNIT_ERL_OPTS))
  40. else
  41. eunit: test-build
  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)
  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) for app in $(ALL_APPS_DIRS); do $(MAKE) -C $$app eunit IS_APP=1; done
  54. endif
  55. endif