ct.mk 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. # Copyright (c) 2013-2016, Loïc Hoguin <essen@ninenines.eu>
  2. # This file is part of erlang.mk and subject to the terms of the ISC License.
  3. .PHONY: ct apps-ct distclean-ct
  4. # Configuration.
  5. CT_OPTS ?=
  6. ifneq ($(wildcard $(TEST_DIR)),)
  7. ifndef CT_SUITES
  8. CT_SUITES := $(sort $(subst _SUITE.erl,,$(notdir $(call core_find,$(TEST_DIR)/,*_SUITE.erl))))
  9. endif
  10. endif
  11. CT_SUITES ?=
  12. CT_LOGS_DIR ?= $(CURDIR)/logs
  13. # Core targets.
  14. tests:: ct
  15. ifndef KEEP_LOGS
  16. distclean:: distclean-ct
  17. endif
  18. help::
  19. $(verbose) printf "%s\n" "" \
  20. "Common_test targets:" \
  21. " ct Run all the common_test suites for this project" \
  22. "" \
  23. "All your common_test suites have their associated targets." \
  24. "A suite named http_SUITE can be ran using the ct-http target."
  25. # Plugin-specific targets.
  26. CT_RUN = ct_run \
  27. -no_auto_compile \
  28. -noinput \
  29. -pa $(CURDIR)/ebin $(TEST_DIR) \
  30. -dir $(TEST_DIR) \
  31. -logdir $(CT_LOGS_DIR)
  32. ifeq ($(CT_SUITES),)
  33. ct: $(if $(IS_APP)$(ROOT_DIR),,apps-ct)
  34. else
  35. # We do not run tests if we are in an apps/* with no test directory.
  36. ifneq ($(IS_APP)$(wildcard $(TEST_DIR)),1)
  37. ct: test-build $(if $(IS_APP)$(ROOT_DIR),,apps-ct)
  38. $(verbose) mkdir -p $(CT_LOGS_DIR)
  39. $(gen_verbose) $(CT_RUN) -sname ct_$(PROJECT) -suite $(addsuffix _SUITE,$(CT_SUITES)) $(CT_OPTS)
  40. endif
  41. endif
  42. ifneq ($(ALL_APPS_DIRS),)
  43. define ct_app_target
  44. apps-ct-$1: test-build
  45. $$(MAKE) -C $1 ct IS_APP=1
  46. endef
  47. $(foreach app,$(ALL_APPS_DIRS),$(eval $(call ct_app_target,$(app))))
  48. apps-ct: $(addprefix apps-ct-,$(ALL_APPS_DIRS))
  49. endif
  50. ifdef t
  51. ifeq (,$(findstring :,$t))
  52. CT_EXTRA = -group $t
  53. else
  54. t_words = $(subst :, ,$t)
  55. CT_EXTRA = -group $(firstword $(t_words)) -case $(lastword $(t_words))
  56. endif
  57. else
  58. ifdef c
  59. CT_EXTRA = -case $c
  60. else
  61. CT_EXTRA =
  62. endif
  63. endif
  64. define ct_suite_target
  65. ct-$1: test-build
  66. $$(verbose) mkdir -p $$(CT_LOGS_DIR)
  67. $$(gen_verbose_esc) $$(CT_RUN) -sname ct_$$(PROJECT) -suite $$(addsuffix _SUITE,$1) $$(CT_EXTRA) $$(CT_OPTS)
  68. endef
  69. $(foreach test,$(CT_SUITES),$(eval $(call ct_suite_target,$(test))))
  70. distclean-ct:
  71. $(gen_verbose) rm -rf $(CT_LOGS_DIR)