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.
12 ## all -- default target which defaults to $(DEFAULT_TEST_TARGET) which
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
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
31 ## -- passed to $(PROVE) if the "prove" target is used
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
40 ## -- set to "test-lint" (the default) to do some lint tests
41 ## may be set to empty to skip these
44 ## -- suppresses removal of test-results directory after testing
47 ## -- suppresses use of TG-TEST-CACHE for "test" and "prove" targets
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
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.
69 ## -- if not empty, test whatever "tg" is found in $PATH
74 # Default target is all
77 # Makefile.sh sets many variables used by this Makefile.mak
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!
88 # Clean out the standard six single suffix inference rules to avoid accidents
89 .SUFFIXES
: .c .sh .f .c˜ .sh˜ .f˜
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
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
121 @echo
"*** $@ ***"; $(SHELL_PATH_SQ
)'' $@
$(TESTLIB_TEST_OPTS
)
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'.
*
135 post-clean
: post-clean-except-prove-cache FORCE
138 clean: post-clean FORCE
139 rm -f TG-TEST-SETTINGS Makefile.var
143 test-lint
: test-lint-duplicates test-lint-executable test-lint-shell-syntax \
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
)
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
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
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 ': "$${TESTLIB_TEST_TAP_ONLY=$(TESTLIB_TEST_TAP_ONLY)}"' \
194 ': "$${GIT_MINIMUM_VERSION:=$(GIT_MINIMUM_VERSION)}"' \
195 ': "$${GIT_MINIMUM_VERSION:=$$TG_GIT_MINIMUM_VERSION}"' \
198 TG-TEST-SETTINGS
: $(FORCE_SETTINGS_BUILD
)
199 $(Q
)$(TEST_SETTINGS
);if
test x
"$$(ts)" != x
"`cat \"$@\" 2>/dev/null`"; then \
200 echo
"* new test settings"; \
204 FORCE
: __file_which_should_not_exist
206 # This "phony" target must have at least one command otherwise it will not
207 # actually run anything and so will not actually trigger the rules that depend
208 # on FORCE to run either. By using "true" instead of ":" "make"s that
209 # short-circuit directly to execvp should be able to run "true" directly.
210 __file_which_should_not_exist
: