test.mk 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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 \
  16. if [ -z "$(strip $(FULL))" ] && [ ! -L $$dep ] && [ -f $$dep/ebin/dep_built ]; then \
  17. :; \
  18. else \
  19. $(MAKE) -C $$dep IS_DEP=1; \
  20. if [ ! -L $$dep ] && [ -d $$dep/ebin ]; then touch $$dep/ebin/dep_built; fi; \
  21. fi \
  22. done
  23. endif
  24. ifneq ($(wildcard $(TEST_DIR)),)
  25. test-dir: $(ERLANG_MK_TMP)/$(PROJECT).last-testdir-build
  26. @:
  27. test_erlc_verbose_0 = @echo " ERLC " $(filter-out $(patsubst %,%.erl,$(ERLC_EXCLUDE)),\
  28. $(filter %.erl %.core,$(notdir $(FILES_TO_COMPILE))));
  29. test_erlc_verbose_2 = set -x;
  30. test_erlc_verbose = $(test_erlc_verbose_$(V))
  31. define compile_test_erl
  32. $(test_erlc_verbose) erlc -v $(TEST_ERLC_OPTS) -o $(TEST_DIR) \
  33. -pa ebin/ -I include/ $(1)
  34. endef
  35. ERL_TEST_FILES = $(call core_find,$(TEST_DIR)/,*.erl)
  36. $(ERLANG_MK_TMP)/$(PROJECT).last-testdir-build: $(ERL_TEST_FILES) $(MAKEFILE_LIST)
  37. $(eval FILES_TO_COMPILE := $(if $(filter $(MAKEFILE_LIST),$?),$(filter $(ERL_TEST_FILES),$^),$?))
  38. $(if $(strip $(FILES_TO_COMPILE)),$(call compile_test_erl,$(FILES_TO_COMPILE)) && touch $@)
  39. endif
  40. test-build:: IS_TEST=1
  41. test-build:: ERLC_OPTS=$(TEST_ERLC_OPTS)
  42. test-build:: $(if $(wildcard src),$(if $(wildcard ebin/test),,clean)) $(if $(IS_APP),,deps test-deps)
  43. # We already compiled everything when IS_APP=1.
  44. ifndef IS_APP
  45. ifneq ($(wildcard src),)
  46. $(verbose) $(MAKE) --no-print-directory $(PROJECT).d ERLC_OPTS="$(call escape_dquotes,$(TEST_ERLC_OPTS))"
  47. $(verbose) $(MAKE) --no-print-directory app-build ERLC_OPTS="$(call escape_dquotes,$(TEST_ERLC_OPTS))"
  48. $(gen_verbose) touch ebin/test
  49. endif
  50. ifneq ($(wildcard $(TEST_DIR)),)
  51. $(verbose) $(MAKE) --no-print-directory test-dir ERLC_OPTS="$(call escape_dquotes,$(TEST_ERLC_OPTS))"
  52. endif
  53. endif
  54. # Roughly the same as test-build, but when IS_APP=1.
  55. # We only care about compiling the current application.
  56. ifdef IS_APP
  57. test-build-app:: ERLC_OPTS=$(TEST_ERLC_OPTS)
  58. test-build-app:: deps test-deps
  59. ifneq ($(wildcard src),)
  60. $(verbose) $(MAKE) --no-print-directory $(PROJECT).d ERLC_OPTS="$(call escape_dquotes,$(TEST_ERLC_OPTS))"
  61. $(verbose) $(MAKE) --no-print-directory app-build ERLC_OPTS="$(call escape_dquotes,$(TEST_ERLC_OPTS))"
  62. $(gen_verbose) touch ebin/test
  63. endif
  64. ifneq ($(wildcard $(TEST_DIR)),)
  65. $(verbose) $(MAKE) --no-print-directory test-dir ERLC_OPTS="$(call escape_dquotes,$(TEST_ERLC_OPTS))"
  66. endif
  67. endif
  68. clean:: clean-test-dir
  69. clean-test-dir:
  70. ifneq ($(wildcard $(TEST_DIR)/*.beam),)
  71. $(gen_verbose) rm -f $(TEST_DIR)/*.beam $(ERLANG_MK_TMP)/$(PROJECT).last-testdir-build
  72. endif