eunit.mk 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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. # 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($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_PATHS = -pa $(TEST_DIR) $(DEPS_DIR)/*/ebin $(APPS_DIR)/*/ebin ebin
  35. ifdef t
  36. ifeq (,$(findstring :,$(t)))
  37. eunit: test-build
  38. $(gen_verbose) $(call erlang,$(call eunit.erl,['$(t)']),$(EUNIT_PATHS))
  39. else
  40. eunit: test-build
  41. $(gen_verbose) $(call erlang,$(call eunit.erl,fun $(t)/0),$(EUNIT_PATHS))
  42. endif
  43. else
  44. EUNIT_EBIN_MODS = $(notdir $(basename $(call core_find,ebin/,*.beam)))
  45. EUNIT_TEST_MODS = $(notdir $(basename $(call core_find,$(TEST_DIR)/,*.beam)))
  46. EUNIT_MODS = $(foreach mod,$(EUNIT_EBIN_MODS) $(filter-out \
  47. $(patsubst %,%_tests,$(EUNIT_EBIN_MODS)),$(EUNIT_TEST_MODS)),'$(mod)')
  48. eunit: test-build $(if $(IS_APP),,apps-eunit)
  49. $(gen_verbose) $(call erlang,$(call eunit.erl,[$(call comma_list,$(EUNIT_MODS))]),$(EUNIT_PATHS))
  50. ifneq ($(ALL_APPS_DIRS),)
  51. apps-eunit:
  52. $(verbose) for app in $(ALL_APPS_DIRS); do $(MAKE) -C $$app eunit IS_APP=1; done
  53. endif
  54. endif