testlib: improve test target handling
[topgit/pro.git] / t / Makefile.mak
blobdd93740ef9abe05f96e92ac382690bc619b11bd3
1 # Makefile.mak - POSIX Makefile.mak adjunct for TopGit tests
3 # Many parts shamelessly swiped from Git's t directory since that works
4 # and is GPL2 just like TopGit
6 # Copyright (C) 2016,2017 Kyle J. McKay
7 # The lines swiped from Git are Copyright (C) 2005 Junio C Hamano et al.
10 ## Make Targets
12 ## all -- default target which defaults to $(DEFAULT_TEST_TARGET) which
13 ## defaults to "test"
14 ## prove -- run the tests using the $(PROVE) utility which is expected to
15 ## take the same arguments as Perl's prove
16 ## test -- run the tests without using an external helper utility
20 ## Make Variables
22 ## An existing config.mak in the parent directory IS read first
24 ## SHELL_PATH -- path to POSIX sh, default is /bin/sh if not otherwise set
25 ## PERL_PATH -- path to Perl, default is $(command -v perl) if not set
26 ## GIT_PATH -- path to git to use, default is $(command -v git) if not set
27 ## DIFF -- diff to use, defaults to "diff"
28 ## PROVE -- prove executable to run, MAY contain options
30 ## TESTLIB_PROVE_OPTS
31 ## -- passed to $(PROVE) if the "prove" target is used
33 ## TESTLIB_MAKE_OPTS
34 ## -- passed to multi-test sub $(MAKE) if the "test" target is used
36 ## DEFAULT_TEST_TARGET
37 ## -- defaults to "test" but can be "prove" to run with prove
39 ## TESTLIB_TEST_LINT
40 ## -- set to "test-lint" (the default) to do some lint tests
41 ## may be set to empty to skip these
43 ## TESTLIB_NO_CLEAN
44 ## -- suppresses removal of test-results directory after testing
46 ## TESTLIB_NO_CACHE
47 ## -- suppresses use of TG-TEST-CACHE for "test" and "prove" targets
49 ## TESTLIB_SKIP_TESTS
50 ## -- space-separated "case" patterns to match against the
51 ## t[0-9][0-9][0-9][0-9] portion of the test file name. To
52 ## skip multiple tests use standard '*', '?' and '[...]'
53 ## match operators. For example, to skip test t1234-foo.sh and
54 ## t3210-hi.sh use TESTLIB_SKIP_TESTS="t1234 t3210" to do that.
56 ## TESTLIB_NO_TOLERATE
57 ## -- if non-empty turns all test_tolerate_failure calls into
58 ## test_expect_success calls instead
60 ## TESTLIB_TEST_OPTS
61 ## -- provided as options to all tests (undergoes field splitting)
62 ## might be set to, for example: --verbose -debug
64 ## T -- space-sparated list of tests to run, must be full filename
65 ## WITHOUT any directory part of the test INCLUDING the .sh
66 ## suffix. The default is all t\d{4}-*.sh files in this dir.
68 ## TG_TEST_INSTALLED
69 ## -- if not empty, test whatever "tg" is found in $PATH
72 .POSIX:
74 # Default target is all
75 all:
77 # Makefile.sh sets many variables used by this Makefile.mak
79 include $(CONFIGMAK)
80 SHELL = $(SHELL_PATH)
82 # Very important rule to avoid "accidents" caused by Makefile.sh's existence
83 # Some ridiculous "make" implementations will always implicitly "make Makefile"
84 # even though .POSIX: has been specified and that's definitely NOT POSIX!
85 Makefile:
86 @true
88 # Clean out the standard six single suffix inference rules to avoid accidents
89 .SUFFIXES: .c .sh .f .c˜ .sh˜ .f˜
90 .c:;
91 .f:;
92 .sh:;
93 .c~:;
94 .f~:;
95 .sh~:;
96 .SUFFIXES:
98 AT = @
99 Q_ = $(AT)
100 Q_0 = $(Q_)
101 Q = $(Q_$(V))
102 TEST_TARGET_test = test
103 TEST_TARGET_prove = prove
104 TEST_TARGET_ = $(TEST_TARGET_test)
105 DEFAULT_TEST_TARGET_=$(DEFAULT_TEST_TARGET)
106 TEST_TARGET = $(TEST_TARGET_$(DEFAULT_TEST_TARGET_))
108 # But all is just an alias for DEFAULT_TEST_TARGET which defaults to test
110 all: $(TEST_TARGET)
112 test: pre-clean TG-TEST-SETTINGS $(TEST_LINT) FORCE
113 $(Q)set -m && $(CACHE_SETUP_TTY) $(MAKE) $${GNO_PD_OPT} -f Makefile.mak aggregate-results-and-cleanup
115 prove: pre-clean TG-TEST-SETTINGS $(TEST_LINT) FORCE
116 @echo "*** prove ***" && set -m && $(CACHE_SETUP) $(PROVE) --exec $(SHELL_PATH_SQ)'' $(TESTLIB_PROVE_OPTS) $(T) :: $(TESTLIB_TEST_OPTS)
117 $(Q)$(NOCLEANCMT)$(MAKE) $${GNO_PD_OPT} -f Makefile.mak -s post-clean-except-prove-cache
119 .PRECIOUS: $(T)
120 $(T): FORCE
121 @echo "*** $@ ***"; $(SHELL_PATH_SQ)'' $@ $(TESTLIB_TEST_OPTS)
123 # How to clean up
125 pre-clean:
126 $(Q)rm -r -f $(TEST_RESULTS_DIRECTORY_SQ)''
128 post-clean-except-prove-cache:
129 rm -r -f $(TEST_RESULTS_DIRECTORY_SQ)''
130 @chmod -R u+rw 'trash directory'.* >/dev/null 2>&1 || :
131 @chmod -R u+rw 'trash tmp directory'.* >/dev/null 2>&1 || :
132 rm -r -f empty 'trash directory'.* 'trash tmp directory'.*
133 rm -f TG-TEST-CACHE
135 post-clean: post-clean-except-prove-cache FORCE
136 rm -f .prove
138 clean: post-clean FORCE
139 rm -f TG-TEST-SETTINGS Makefile.var
141 # Pick off the lint
143 test-lint: test-lint-duplicates test-lint-executable test-lint-shell-syntax \
144 test-lint-filenames
146 test-lint-duplicates:
147 $(Q)dups=`echo $(ALLT) | tr ' ' '\n' | sed 's/-.*//' | sort | uniq -d` && \
148 test -z "$$dups" || { \
149 echo >&2 "duplicate test numbers:" $$dups; exit 1; }
151 test-lint-executable:
152 $(Q)bad=`for i in $(LINTTESTS); do test -x "$$i" || echo $$i; done` && \
153 test -z "$$bad" || { \
154 echo >&2 "non-executable tests:" $$bad; exit 1; }
156 test-lint-shell-syntax:
157 $(Q)p=$(PERL_PATH_SQ)''; "$${p:-perl}" check-non-portable-shell.pl $(LINTTESTS) $(LINTSCRIPTS)
159 test-lint-filenames:
160 @# We do *not* pass a glob to ls-files but use grep instead, to catch
161 @# non-ASCII characters (which are quoted within double-quotes)
162 $(Q)g=$(GIT_PATH_SQ)''; bad="$$("$${g:-git}" -c core.quotepath=true ls-files 2>/dev/null | \
163 LC_ALL=C grep '['\''""*:<>?\\|]')" || :; \
164 test -z "$$bad" || { \
165 echo >&2 "non-portable file name(s): $$bad"; exit 1; }
167 # Run the tests without using prove
169 run-individual-tests: $(T)
171 aggregate-results-and-cleanup:
172 $(Q)set -m && ec=0 && $(SHELL_PATH_SQ)'' -c 'TESTLIB_TEST_PARENT_INT_ON_ERROR=$$$$ exec "$$@"' $(SHELL_PATH_SQ)'' \
173 $(MAKE) $${GNO_PD_OPT} -f Makefile.mak -k $(TESTLIB_MAKE_OPTS) run-individual-tests || ec=$$? && \
174 test -e $(TEST_RESULTS_DIRECTORY_SQ)/bailout || { $(MAKE) $${GNO_PD_OPT} -f Makefile.mak aggregate-results || exit; } && exit $$ec
175 $(Q)$(NOCLEANCMT)$(MAKE) $${GNO_PD_OPT} -f Makefile.mak -s post-clean
177 aggregate-results:
178 $(Q)for f in $(TEST_RESULTS_DIRECTORY_SQ)/t*-*.counts; do \
179 [ "$$f" = '$(TEST_RESULTS_DIRECTORY_SQ)/t*-*.counts' ] || echo "$$f"; \
180 done | $(SHELL_PATH_SQ)'' ./aggregate-results.sh
182 # Provide Makefile-determined settings in a test-available format
184 TEST_SETTINGS = \
185 ts() { printf "%s\\n" \
186 ': "$${SHELL_PATH:=$(SHELL_PATH)}"' \
187 ': "$${PERL_PATH:=$(PERL_PATH)}"' \
188 ': "$${PERL_PATH:=perl}"' \
189 ': "$${GIT_PATH:=$(GIT_PATH)}"' \
190 ': "$${GIT_PATH:=git}"' \
191 ': "$${DIFF:=$(DIFF)}"' \
192 ': "$${TESTLIB_NO_TOLERATE=$(TESTLIB_NO_TOLERATE)}"' \
193 ': "$${GIT_MINIMUM_VERSION:=$(GIT_MINIMUM_VERSION)}"' \
194 ': "$${GIT_MINIMUM_VERSION:=$$TG_GIT_MINIMUM_VERSION}"' \
197 TG-TEST-SETTINGS: $(FORCE_SETTINGS_BUILD)
198 $(Q)$(TEST_SETTINGS);if test x"$$(ts)" != x"`cat \"$@\" 2>/dev/null`"; then \
199 echo "* new test settings"; \
200 ts >"$@"; \
203 FORCE: __file_which_should_not_exist
205 # This "phony" target must have at least one command otherwise it will not
206 # actually run anything and so will not actually trigger the rules that depend
207 # on FORCE to run either. By using "true" instead of ":" "make"s that
208 # short-circuit directly to execvp should be able to run "true" directly.
209 __file_which_should_not_exist:
210 -@true