tg export: no need for merge or hook setup
[topgit/pro.git] / t / Makefile.mak
blobbf8805c3ac7f01bab7fdd06e65d763683c887132
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 settings: TG-TEST-SETTINGS
113 -@true # avoids the "Nothing to be done" message
115 test: pre-clean TG-TEST-SETTINGS $(TEST_LINT) FORCE
116 $(Q)set -m && $(CACHE_SETUP_TTY) $(MAKE) $${GNO_PD_OPT} -f Makefile.mak aggregate-results-and-cleanup
118 prove: pre-clean TG-TEST-SETTINGS $(TEST_LINT) FORCE
119 @echo "*** prove ***" && set -m && $(CACHE_SETUP) $(PROVE) --exec $(SHELL_PATH_SQ)'' $(TESTLIB_PROVE_OPTS) $(T) :: $(TESTLIB_TEST_OPTS)
120 $(Q)$(NOCLEANCMT)$(MAKE) $${GNO_PD_OPT} -f Makefile.mak -s post-clean-except-prove-cache
122 .PRECIOUS: $(T)
123 $(T): FORCE
124 @echo "*** $@ ***"; $(SHELL_PATH_SQ)'' $@ $(TESTLIB_TEST_OPTS)
126 # How to clean up
128 pre-clean:
129 $(Q)rm -r -f $(TEST_RESULTS_DIRECTORY_SQ)''
131 post-clean-except-prove-cache:
132 rm -r -f $(TEST_RESULTS_DIRECTORY_SQ)''
133 @chmod -R u+rw 'trash directory'.* >/dev/null 2>&1 || :
134 @chmod -R u+rw 'trash tmp directory'.* >/dev/null 2>&1 || :
135 rm -r -f empty 'trash directory'.* 'trash tmp directory'.*
136 rm -f TG-TEST-CACHE
138 post-clean: post-clean-except-prove-cache FORCE
139 rm -f .prove
141 clean: post-clean FORCE
142 rm -f TG-TEST-SETTINGS Makefile.var
144 # Pick off the lint
146 test-lint: test-lint-duplicates test-lint-executable test-lint-shell-syntax \
147 test-lint-filenames
149 test-lint-duplicates:
150 $(Q)dups=`echo $(ALLT) | tr ' ' '\n' | sed 's/-.*//' | sort | uniq -d` && \
151 test -z "$$dups" || { \
152 echo >&2 "duplicate test numbers:" $$dups; exit 1; }
154 test-lint-executable:
155 $(Q)bad=`for i in $(LINTTESTS); do test -x "$$i" || echo $$i; done` && \
156 test -z "$$bad" || { \
157 echo >&2 "non-executable tests:" $$bad; exit 1; }
159 test-lint-shell-syntax:
160 $(Q)p=$(PERL_PATH_SQ)''; "$${p:-perl}" check-non-portable-shell.pl $(LINTTESTS) $(LINTSCRIPTS)
162 test-lint-filenames:
163 @# We do *not* pass a glob to ls-files but use grep instead, to catch
164 @# non-ASCII characters (which are quoted within double-quotes)
165 $(Q)g=$(GIT_PATH_SQ)''; bad="$$("$${g:-git}" -c core.quotepath=true ls-files 2>/dev/null | \
166 LC_ALL=C grep '['\''""*:<>?\\|]')" || :; \
167 test -z "$$bad" || { \
168 echo >&2 "non-portable file name(s): $$bad"; exit 1; }
170 # Run the tests without using prove
172 run-individual-tests: $(T)
174 aggregate-results-and-cleanup:
175 $(Q)set -m && ec=0 && $(SHELL_PATH_SQ)'' -c 'TESTLIB_TEST_PARENT_INT_ON_ERROR=$$$$ exec "$$@"' $(SHELL_PATH_SQ)'' \
176 $(MAKE) $${GNO_PD_OPT} -f Makefile.mak -k $(TESTLIB_MAKE_OPTS) run-individual-tests || ec=$$? && \
177 test -e $(TEST_RESULTS_DIRECTORY_SQ)/bailout || { $(MAKE) $${GNO_PD_OPT} -f Makefile.mak aggregate-results || exit; } && exit $$ec
178 $(Q)$(NOCLEANCMT)$(MAKE) $${GNO_PD_OPT} -f Makefile.mak -s post-clean
180 aggregate-results:
181 $(Q)for f in $(TEST_RESULTS_DIRECTORY_SQ)/t*-*.counts; do \
182 [ "$$f" = '$(TEST_RESULTS_DIRECTORY_SQ)/t*-*.counts' ] || echo "$$f"; \
183 done | $(SHELL_PATH_SQ)'' ./aggregate-results.sh
185 # Provide Makefile-determined settings in a test-available format
187 TEST_SETTINGS = \
188 ts() { printf "%s\\n" \
189 ': "$${SHELL_PATH:=$(SHELL_PATH)}"' \
190 ': "$${PERL_PATH:=$(PERL_PATH)}"' \
191 ': "$${PERL_PATH:=perl}"' \
192 ': "$${GIT_PATH:=$(GIT_PATH)}"' \
193 ': "$${GIT_PATH:=git}"' \
194 ': "$${DIFF:=$(DIFF)}"' \
195 ': "$${TESTLIB_NO_TOLERATE=$(TESTLIB_NO_TOLERATE)}"' \
196 ': "$${TESTLIB_TEST_TAP_ONLY=$(TESTLIB_TEST_TAP_ONLY)}"' \
197 ': "$${GIT_MINIMUM_VERSION:=$(GIT_MINIMUM_VERSION)}"' \
198 ': "$${GIT_MINIMUM_VERSION:=$$TG_GIT_MINIMUM_VERSION}"' \
201 TG-TEST-SETTINGS: $(CONFIGDEPS) $(FORCE_SETTINGS_BUILD)
202 $(Q)$(TEST_SETTINGS);if test x"$$(ts)" != x"`cat \"$@\" 2>/dev/null`"; then \
203 echo "* new test settings"; \
204 ts >"$@"; \
205 elif test z"$(FORCE_SETTINGS_BUILD)" = z; then touch "$@"; fi
207 FORCE: __file_which_should_not_exist
209 # This "phony" target must have at least one command otherwise it will not
210 # actually run anything and so will not actually trigger the rules that depend
211 # on FORCE to run either. By using "true" instead of ":" "make"s that
212 # short-circuit directly to execvp should be able to run "true" directly.
213 __file_which_should_not_exist:
214 -@true