test.mk 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. # Copyright (c) 2015-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: test-deps test-dir test-build clean-test-dir
  4. # Configuration.
  5. TEST_DIR ?= $(CURDIR)/test
  6. ALL_TEST_DEPS_DIRS = $(addprefix $(DEPS_DIR)/,$(TEST_DEPS))
  7. TEST_ERLC_OPTS ?= +debug_info +warn_export_vars +warn_shadow_vars +warn_obsolete_guard
  8. TEST_ERLC_OPTS += -DTEST=1
  9. # Targets.
  10. $(foreach dep,$(TEST_DEPS),$(eval $(call dep_target,$(dep))))
  11. ifneq ($(SKIP_DEPS),)
  12. test-deps:
  13. else
  14. test-deps: $(ALL_TEST_DEPS_DIRS)
  15. $(verbose) set -e; for dep in $(ALL_TEST_DEPS_DIRS) ; do $(MAKE) -C $$dep IS_DEP=1; done
  16. endif
  17. ifneq ($(wildcard $(TEST_DIR)),)
  18. test-dir:
  19. $(gen_verbose) erlc -v $(TEST_ERLC_OPTS) -o $(TEST_DIR) \
  20. -pa ebin/ -I include/ $(call core_find,$(TEST_DIR)/,*.erl)
  21. endif
  22. test-build:: IS_TEST=1
  23. test-build:: ERLC_OPTS=$(TEST_ERLC_OPTS)
  24. test-build:: $(if $(wildcard src),$(if $(wildcard ebin/test),,clean)) $(if $(IS_APP),,deps test-deps)
  25. # We already compiled everything when IS_APP=1.
  26. ifndef IS_APP
  27. ifneq ($(wildcard $(TEST_DIR)),)
  28. $(verbose) $(MAKE) --no-print-directory test-dir ERLC_OPTS="$(call escape_dquotes,$(TEST_ERLC_OPTS))"
  29. endif
  30. ifneq ($(wildcard src),)
  31. $(verbose) $(MAKE) --no-print-directory $(PROJECT).d ERLC_OPTS="$(call escape_dquotes,$(TEST_ERLC_OPTS))"
  32. $(verbose) $(MAKE) --no-print-directory app-build ERLC_OPTS="$(call escape_dquotes,$(TEST_ERLC_OPTS))"
  33. $(gen_verbose) touch ebin/test
  34. endif
  35. endif
  36. # Roughly the same as test-build, but when IS_APP=1.
  37. # We only care about compiling the current application.
  38. ifdef IS_APP
  39. test-build-app:: ERLC_OPTS=$(TEST_ERLC_OPTS)
  40. test-build-app:: test-deps
  41. ifneq ($(wildcard $(TEST_DIR)),)
  42. $(verbose) $(MAKE) --no-print-directory test-dir ERLC_OPTS="$(call escape_dquotes,$(TEST_ERLC_OPTS))"
  43. endif
  44. ifneq ($(wildcard src),)
  45. $(verbose) $(MAKE) --no-print-directory $(PROJECT).d ERLC_OPTS="$(call escape_dquotes,$(TEST_ERLC_OPTS))"
  46. $(verbose) $(MAKE) --no-print-directory app-build ERLC_OPTS="$(call escape_dquotes,$(TEST_ERLC_OPTS))"
  47. $(gen_verbose) touch ebin/test
  48. endif
  49. endif
  50. clean:: clean-test-dir
  51. clean-test-dir:
  52. ifneq ($(wildcard $(TEST_DIR)/*.beam),)
  53. $(gen_verbose) rm -f $(TEST_DIR)/*.beam
  54. endif