ct.mk 1.8 KB

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