ct.mk 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. # Copyright (c) 2013-2014, 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: build-ct-deps build-ct-suites tests-ct clean-ct distclean-ct
  4. # Configuration.
  5. CT_OPTS ?=
  6. ifneq ($(wildcard test/),)
  7. CT_SUITES ?= $(sort $(subst _SUITE.erl,,$(shell find test -type f -name \*_SUITE.erl -exec basename {} \;)))
  8. else
  9. CT_SUITES ?=
  10. endif
  11. TEST_ERLC_OPTS ?= +debug_info +warn_export_vars +warn_shadow_vars +warn_obsolete_guard
  12. TEST_ERLC_OPTS += -DTEST=1 -DEXTRA=1 +'{parse_transform, eunit_autoexport}'
  13. # Core targets.
  14. tests:: tests-ct
  15. clean:: clean-ct
  16. distclean:: distclean-ct
  17. help::
  18. @printf "%s\n" "" \
  19. "All your common_test suites have their associated targets." \
  20. "A suite named http_SUITE can be ran using the ct-http target."
  21. # Plugin-specific targets.
  22. ALL_TEST_DEPS_DIRS = $(addprefix $(DEPS_DIR)/,$(TEST_DEPS))
  23. CT_RUN = ct_run \
  24. -no_auto_compile \
  25. -noinput \
  26. -pa $(realpath ebin) $(DEPS_DIR)/*/ebin \
  27. -dir test \
  28. -logdir logs
  29. $(foreach dep,$(TEST_DEPS),$(eval $(call dep_target,$(dep))))
  30. build-ct-deps: $(ALL_TEST_DEPS_DIRS)
  31. @for dep in $(ALL_TEST_DEPS_DIRS) ; do $(MAKE) -C $$dep; done
  32. build-ct-suites: build-ct-deps
  33. $(gen_verbose) erlc -v $(TEST_ERLC_OPTS) -I include/ -o test/ \
  34. $(wildcard test/*.erl test/*/*.erl) -pa ebin/
  35. tests-ct: ERLC_OPTS = $(TEST_ERLC_OPTS)
  36. tests-ct: clean deps app build-ct-suites
  37. @if [ -d "test" ] ; \
  38. then \
  39. mkdir -p logs/ ; \
  40. $(CT_RUN) -suite $(addsuffix _SUITE,$(CT_SUITES)) $(CT_OPTS) ; \
  41. fi
  42. $(gen_verbose) rm -f test/*.beam
  43. define ct_suite_target
  44. ct-$(1): ERLC_OPTS = $(TEST_ERLC_OPTS)
  45. ct-$(1): clean deps app build-ct-suites
  46. @if [ -d "test" ] ; \
  47. then \
  48. mkdir -p logs/ ; \
  49. $(CT_RUN) -suite $(addsuffix _SUITE,$(1)) $(CT_OPTS) ; \
  50. fi
  51. $(gen_verbose) rm -f test/*.beam
  52. endef
  53. $(foreach test,$(CT_SUITES),$(eval $(call ct_suite_target,$(test))))
  54. clean-ct:
  55. $(gen_verbose) rm -rf test/*.beam
  56. distclean-ct:
  57. $(gen_verbose) rm -rf logs/