tg.sh: handle help -h
[topgit/pro.git] / t / Makefile.mak
blobeb551fbe1b8a58319154f77102eb2503f087ea2b
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,2021 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 ## AWK_PATH -- path to awk, default is /usr/bin/awk if not otherwise set
27 ## GIT_PATH -- path to git to use, default is $(command -v git) if not set
28 ## DIFF -- diff to use, defaults to "diff"
29 ## PROVE -- prove executable to run, MAY contain options
31 ## TESTLIB_PROVE_OPTS
32 ## -- passed to $(PROVE) if the "prove" target is used
34 ## TESTLIB_MAKE_OPTS
35 ## -- passed to multi-test sub $(MAKE) if the "test" target is used
37 ## DEFAULT_TEST_TARGET
38 ## -- defaults to "test" but can be "prove" to run with prove
40 ## TESTLIB_TEST_LINT
41 ## -- set to "test-lint" (the default) to do some lint tests
42 ## may be set to empty to skip these
44 ## TESTLIB_NO_CLEAN
45 ## -- suppresses removal of test-results directory after testing
47 ## TESTLIB_NO_CACHE
48 ## -- suppresses use of TG-TEST-CACHE for "test" and "prove" targets
50 ## TESTLIB_SKIP_TESTS
51 ## -- space-separated "case" patterns to match against the
52 ## t[0-9][0-9][0-9][0-9] portion of the test file name. To
53 ## skip multiple tests use standard '*', '?' and '[...]'
54 ## match operators. For example, to skip test t1234-foo.sh and
55 ## t3210-hi.sh use TESTLIB_SKIP_TESTS="t1234 t3210" to do that.
57 ## TESTLIB_NO_TOLERATE
58 ## -- if non-empty turns all test_tolerate_failure calls into
59 ## test_expect_success calls instead
61 ## TESTLIB_TEST_OPTS
62 ## -- provided as options to all tests (undergoes field splitting)
63 ## might be set to, for example: --verbose -debug
65 ## T -- space-sparated list of tests to run, must be full filename
66 ## WITHOUT any directory part of the test INCLUDING the .sh
67 ## suffix. The default is all t\d{4}-*.sh files in this dir.
69 ## TG_TEST_INSTALLED
70 ## -- if not empty, test whatever "tg" is found in $PATH
73 .POSIX:
75 # Default target is all
76 all:
78 # Makefile.sh sets many variables used by this Makefile.mak
80 include $(CONFIGMAK)
81 SHELL = $(SHELL_PATH)
83 # Very important rule to avoid "accidents" caused by Makefile.sh's existence
84 # Some ridiculous "make" implementations will always implicitly "make Makefile"
85 # even though .POSIX: has been specified and that's definitely NOT POSIX!
86 Makefile Makefile.mak ../Makefile.mt ../Makefile.dep Makefile.sh ../config.mak ../config.sh:
87 -@true
89 # Clean out the standard six single suffix inference rules to avoid accidents
90 .SUFFIXES: .c .sh .f .c˜ .sh˜ .f˜
91 .c:;
92 .f:;
93 .sh:;
94 .c~:;
95 .f~:;
96 .sh~:;
97 .SUFFIXES:
99 AT = @
100 Q_ = $(AT)
101 Q_0 = $(Q_)
102 Q = $(Q_$(V))
103 TEST_TARGET_test = test
104 TEST_TARGET_prove = prove
105 TEST_TARGET_ = $(TEST_TARGET_test)
106 DEFAULT_TEST_TARGET_=$(DEFAULT_TEST_TARGET)
107 TEST_TARGET = $(TEST_TARGET_$(DEFAULT_TEST_TARGET_))
109 # But all is just an alias for DEFAULT_TEST_TARGET which defaults to test
111 all: $(TEST_TARGET)
113 settings: TG-TEST-SETTINGS
114 -@true # avoids the "Nothing to be done" message
116 test: pre-clean TG-TEST-SETTINGS $(TESTLIB_TEST_LINT) FORCE
117 $(Q)helper/git_version "*** testing using" && set -m && $(CACHE_SETUP_TTY) $(MAKE) $${GNO_PD_OPT} -f Makefile.mak aggregate-results-and-cleanup
119 prove: pre-clean TG-TEST-SETTINGS $(TESTLIB_TEST_LINT) FORCE
120 @helper/git_version "*** testing using" && echo "*** prove ***" && set -m && $(CACHE_SETUP) $(PROVE) --exec $(SHELL_PATH_SQ)'' $(TESTLIB_PROVE_OPTS) $(T) :: $(TESTLIB_TEST_OPTS)
121 $(Q)$(NOCLEANCMT)$(MAKE) $${GNO_PD_OPT} -f Makefile.mak -s post-clean-except-prove-cache
123 .PRECIOUS: $(T)
124 $(T): FORCE
125 @echo "*** $@ ***"; $(SHELL_PATH_SQ)'' $@ $(TESTLIB_TEST_OPTS)
127 # How to clean up
129 pre-clean:
130 $(Q)rm -r -f $(TEST_RESULTS_DIRECTORY_SQ)''
132 post-clean-except-prove-cache:
133 rm -r -f $(TEST_RESULTS_DIRECTORY_SQ)''
134 @chmod -R u+rw 'trash directory'.* >/dev/null 2>&1 || :
135 @chmod -R u+rw 'trash tmp directory'.* >/dev/null 2>&1 || :
136 rm -r -f empty 'trash directory'.* 'trash tmp directory'.*
137 rm -f TG-TEST-CACHE
139 post-clean: post-clean-except-prove-cache FORCE
140 rm -f .prove
142 clean: post-clean FORCE
143 rm -f TG-TEST-SETTINGS Makefile.var
145 # Pick off the lint
147 test-lint: test-lint-duplicates test-lint-executable test-lint-shell-syntax \
148 test-lint-filenames
150 test-lint-duplicates:
151 $(Q)dups=`echo $(ALLT) | tr ' ' '\n' | sed 's/-.*//' | sort | uniq -d` && \
152 test -z "$$dups" || { \
153 echo >&2 "duplicate test numbers:" $$dups; exit 1; }
155 test-lint-executable:
156 $(Q)bad=`for i in $(LINTTESTS); do test -x "$$i" || echo $$i; done` && \
157 test -z "$$bad" || { \
158 echo >&2 "non-executable tests:" $$bad; exit 1; }
160 test-lint-shell-syntax:
161 $(Q)p=$(PERL_PATH_SQ)''; "$${p:-perl}" check-non-portable-shell.pl $(LINTTESTS) $(LINTSCRIPTS)
163 test-lint-filenames:
164 @# We do *not* pass a glob to ls-files but use grep instead, to catch
165 @# non-ASCII characters (which are quoted within double-quotes)
166 $(Q)g=$(GIT_PATH_SQ)''; bad="$$("$${g:-git}" -c core.quotepath=true ls-files 2>/dev/null | \
167 LC_ALL=C grep '['\''""*:<>?\\|]')" || :; \
168 test -z "$$bad" || { \
169 echo >&2 "non-portable file name(s): $$bad"; exit 1; }
171 # Run the tests without using prove
173 run-individual-tests: $(T)
175 aggregate-results-and-cleanup:
176 $(Q)set -m && ec=0 && trap : INT && \
177 $(SHELL_PATH_SQ)'' -c 'TESTLIB_TEST_PARENT_INT_ON_ERROR=$$$$ exec "$$@"' $(SHELL_PATH_SQ)'' \
178 $(MAKE) $${GNO_PD_OPT} -f Makefile.mak -k $(TESTLIB_MAKE_OPTS) run-individual-tests || ec=$$? && \
179 test -e $(TEST_RESULTS_DIRECTORY_SQ)/bailout || { $(MAKE) $${GNO_PD_OPT} -f Makefile.mak aggregate-results || exit; } && exit $$ec
180 $(Q)$(NOCLEANCMT)$(MAKE) $${GNO_PD_OPT} -f Makefile.mak -s post-clean
182 aggregate-results:
183 $(Q)for f in $(TEST_RESULTS_DIRECTORY_SQ)/t*-*.counts; do \
184 [ "$$f" = '$(TEST_RESULTS_DIRECTORY_SQ)/t*-*.counts' ] || echo "$$f"; \
185 done | $(SHELL_PATH_SQ)'' ./aggregate-results.sh
187 # Provide Makefile-determined settings in a test-available format
189 TEST_SETTINGS = \
190 ts() { printf "%s\\n" \
191 ': "$${SHELL_PATH:=$(SHELL_PATH)}"' \
192 ': "$${AWK_PATH:=$(AWK_PATH)}"' \
193 ': "$${AWK_PATH:=awk}"' \
194 ': "$${PERL_PATH:=$(PERL_PATH)}"' \
195 ': "$${PERL_PATH:=perl}"' \
196 ': "$${GIT_PATH:=$(GIT_PATH)}"' \
197 ': "$${GIT_PATH:=git}"' \
198 ': "$${DIFF:=$(DIFF)}"' \
199 ': "$${TESTLIB_NO_TOLERATE=$(TESTLIB_NO_TOLERATE)}"' \
200 ': "$${TESTLIB_TEST_TAP_ONLY=$(TESTLIB_TEST_TAP_ONLY)}"' \
201 ': "$${GIT_MINIMUM_VERSION:=$(GIT_MINIMUM_VERSION)}"' \
202 ': "$${GIT_MINIMUM_VERSION:=$$TG_GIT_MINIMUM_VERSION}"' \
205 TG-TEST-SETTINGS: $(CONFIGDEPS) $(FORCE_SETTINGS_BUILD)
206 $(Q)$(TEST_SETTINGS);if test x"$$(ts)" != x"`cat \"$@\" 2>/dev/null`"; then \
207 echo "* new test settings"; \
208 ts >"$@"; \
209 elif test z"$(FORCE_SETTINGS_BUILD)" = z; then touch "$@"; fi
211 FORCE: Makefile.mak/phony
213 # This "phony" target must have at least one command otherwise it will not
214 # actually run anything and so will not actually trigger the rules that depend
215 # on FORCE to run either. By using "true" instead of ":" "make"s that
216 # short-circuit directly to execvp should be able to run "true" directly.
217 Makefile.mak/phony:
218 -@true