Browse Source

Add CT_LOGS_DIR

nevar 8 years ago
parent
commit
e519628eec
3 changed files with 35 additions and 5 deletions
  1. 6 0
      doc/src/guide/common_test.asciidoc
  2. 5 4
      plugins/ct.mk
  3. 24 1
      test/plugin_ct.mk

+ 6 - 0
doc/src/guide/common_test.asciidoc

@@ -35,6 +35,12 @@ is `http`:
 [source,make]
 CT_SUITES = http ws
 
+The `CT_LOGS_DIR` variable can be used to set where HTML
+log files are to be written. This defaults to 'logs/'.
+
+[source,make]
+CT_LOGS_DIR = ct_output_log_dir
+
 === Usage
 
 To run all tests (including Common Test):

+ 5 - 4
plugins/ct.mk

@@ -13,6 +13,7 @@ CT_SUITES := $(sort $(subst _SUITE.erl,,$(notdir $(call core_find,$(TEST_DIR)/,*
 endif
 endif
 CT_SUITES ?=
+CT_LOGS_DIR ?= $(CURDIR)/logs
 
 # Core targets.
 
@@ -35,13 +36,13 @@ CT_RUN = ct_run \
 	-noinput \
 	-pa $(CURDIR)/ebin $(DEPS_DIR)/*/ebin $(APPS_DIR)/*/ebin $(TEST_DIR) \
 	-dir $(TEST_DIR) \
-	-logdir $(CURDIR)/logs
+	-logdir $(CT_LOGS_DIR)
 
 ifeq ($(CT_SUITES),)
 ct: $(if $(IS_APP),,apps-ct)
 else
 ct: test-build $(if $(IS_APP),,apps-ct)
-	$(verbose) mkdir -p $(CURDIR)/logs/
+	$(verbose) mkdir -p $(CT_LOGS_DIR)
 	$(gen_verbose) $(CT_RUN) -sname ct_$(PROJECT) -suite $(addsuffix _SUITE,$(CT_SUITES)) $(CT_OPTS)
 endif
 
@@ -69,11 +70,11 @@ endif
 
 define ct_suite_target
 ct-$(1): test-build
-	$(verbose) mkdir -p $(CURDIR)/logs/
+	$(verbose) mkdir -p $(CT_LOGS_DIR)
 	$(gen_verbose) $(CT_RUN) -sname ct_$(PROJECT) -suite $(addsuffix _SUITE,$(1)) $(CT_EXTRA) $(CT_OPTS)
 endef
 
 $(foreach test,$(CT_SUITES),$(eval $(call ct_suite_target,$(test))))
 
 distclean-ct:
-	$(gen_verbose) rm -rf $(CURDIR)/logs/
+	$(gen_verbose) rm -rf $(CT_LOGS_DIR)

+ 24 - 1
test/plugin_ct.mk

@@ -1,6 +1,6 @@
 # Common Test plugin.
 
-CT_CASES = all apps-only case check group opts suite tests
+CT_CASES = all apps-only case check group logs-dir opts suite tests
 CT_TARGETS = $(addprefix ct-,$(CT_CASES))
 
 .PHONY: ct $(CT_TARGETS)
@@ -182,6 +182,29 @@ ct-opts: build clean
 	$i "Check that Common Test uses options from CT_OPTS"
 	$t grep -q hello_ct_opts $(APP)/logs/index.html
 
+ct-logs-dir: build clean
+
+	$i "Bootstrap a new OTP application named $(APP)"
+	$t mkdir $(APP)/
+	$t cp ../erlang.mk $(APP)/
+	$t $(MAKE) -C $(APP) -f erlang.mk bootstrap $v
+
+	$i "Set CT_OPTS in the Makefile"
+	$t perl -ni.bak -e 'print;if ($$.==1) {print "CT_LOGS_DIR = custom_dir\n"}' $(APP)/Makefile
+
+	$i "Generate a Common Test suite"
+	$t mkdir $(APP)/test
+	$t printf "%s\n" \
+		"-module($(APP)_SUITE)." \
+		"-export([all/0, ok/1])." \
+		"all() -> [ok]." \
+		"ok(_) -> ok." > $(APP)/test/$(APP)_SUITE.erl
+
+	$i "Check that Common Test log in right place"
+	$t test ! -e $(APP)/custom_dir/index.html
+	$t $(MAKE) -C $(APP) ct $v
+	$t test -f $(APP)/custom_dir/index.html
+
 ct-suite: build clean
 
 	$i "Bootstrap a new OTP application named $(APP)"