blob: f61da562f6265e39375aa649c04f334d71020188 [file] [log] [blame]
Jonathan Niederc74c7202013-11-25 13:03:06 -08001# Test framework for git. See t/README for usage.
Junio C Hamanoe1970ce2005-05-13 22:50:32 -07002#
3# Copyright (c) 2005 Junio C Hamano
4#
Michal Sojka64b90322010-04-16 15:53:59 +02005# This program is free software: you can redistribute it and/or modify
6# it under the terms of the GNU General Public License as published by
7# the Free Software Foundation, either version 2 of the License, or
8# (at your option) any later version.
9#
10# This program is distributed in the hope that it will be useful,
11# but WITHOUT ANY WARRANTY; without even the implied warranty of
12# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13# GNU General Public License for more details.
14#
15# You should have received a copy of the GNU General Public License
16# along with this program. If not, see http://www.gnu.org/licenses/ .
Junio C Hamanoe1970ce2005-05-13 22:50:32 -070017
Junio C Hamano3c8f12c2012-06-24 22:01:35 -070018# Test the binaries we have just built. The tests are kept in
19# t/ subdirectory and are run in 'trash directory' subdirectory.
20if test -z "$TEST_DIRECTORY"
21then
22 # We allow tests to override this, in case they want to run tests
23 # outside of t/, e.g. for running tests on the test library
24 # itself.
25 TEST_DIRECTORY=$(pwd)
Felipe Contreras85176d72013-11-17 23:12:43 -050026else
27 # ensure that TEST_DIRECTORY is an absolute path so that it
28 # is valid even if the current working directory is changed
29 TEST_DIRECTORY=$(cd "$TEST_DIRECTORY" && pwd) || exit 1
Junio C Hamano3c8f12c2012-06-24 22:01:35 -070030fi
31if test -z "$TEST_OUTPUT_DIRECTORY"
32then
33 # Similarly, override this to store the test-results subdir
34 # elsewhere
35 TEST_OUTPUT_DIRECTORY=$TEST_DIRECTORY
36fi
37GIT_BUILD_DIR="$TEST_DIRECTORY"/..
38
Jeff Kingd0cc5792017-07-10 09:24:35 -040039# If we were built with ASAN, it may complain about leaks
40# of program-lifetime variables. Disable it by default to lower
41# the noise level. This needs to happen at the start of the script,
42# before we even do our "did we build git yet" check (since we don't
43# want that one to complain to stderr).
Jeff Kingbf1ce902017-07-10 09:24:39 -040044: ${ASAN_OPTIONS=detect_leaks=0:abort_on_error=1}
Jeff Kingd0cc5792017-07-10 09:24:35 -040045export ASAN_OPTIONS
46
Jeff King85b81b32017-09-05 09:04:04 -040047# If LSAN is in effect we _do_ want leak checking, but we still
48# want to abort so that we notice the problems.
49: ${LSAN_OPTIONS=abort_on_error=1}
50export LSAN_OPTIONS
51
Johannes Schindelin8abfdf42018-11-14 08:32:11 -080052if test ! -f "$GIT_BUILD_DIR"/GIT-BUILD-OPTIONS
Ramkumar Ramachandra2006f0a2012-09-17 22:36:19 +053053then
Johannes Schindelin8abfdf42018-11-14 08:32:11 -080054 echo >&2 'error: GIT-BUILD-OPTIONS missing (has Git been built?).'
Ramkumar Ramachandra2006f0a2012-09-17 22:36:19 +053055 exit 1
56fi
Junio C Hamano3c8f12c2012-06-24 22:01:35 -070057. "$GIT_BUILD_DIR"/GIT-BUILD-OPTIONS
58export PERL_PATH SHELL_PATH
59
Patrick Steinhardtade15522021-07-20 08:32:26 +020060# In t0000, we need to override test directories of nested testcases. In case
61# the developer has TEST_OUTPUT_DIRECTORY part of his build options, then we'd
62# reset this value to instead contain what the developer has specified. We thus
63# have this knob to allow overriding the directory.
64if test -n "${TEST_OUTPUT_DIRECTORY_OVERRIDE}"
65then
66 TEST_OUTPUT_DIRECTORY="${TEST_OUTPUT_DIRECTORY_OVERRIDE}"
67fi
68
Johannes Schindelinb02e7d52019-04-12 02:37:24 -070069# Disallow the use of abbreviated options in the test suite by default
70if test -z "${GIT_TEST_DISALLOW_ABBREVIATED_OPTIONS}"
71then
72 GIT_TEST_DISALLOW_ABBREVIATED_OPTIONS=true
73 export GIT_TEST_DISALLOW_ABBREVIATED_OPTIONS
74fi
75
Ævar Arnfjörð Bjarmason97c8aac2021-05-10 16:19:09 +020076# Explicitly set the default branch name for testing, to avoid the
77# transitory "git init" warning under --verbose.
78: ${GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME:=master}
79export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
80
Junio C Hamanoc2116a12008-03-06 19:04:26 -080081################################################################
82# It appears that people try to run tests without building...
Johannes Schindelin8abfdf42018-11-14 08:32:11 -080083"${GIT_TEST_INSTALLED:-$GIT_BUILD_DIR}/git$X" >/dev/null
Junio C Hamanoe1970ce2005-05-13 22:50:32 -070084if test $? != 1
85then
Johannes Schindelined306e42018-11-14 08:32:10 -080086 if test -n "$GIT_TEST_INSTALLED"
87 then
88 echo >&2 "error: there is no working Git at '$GIT_TEST_INSTALLED'"
89 else
90 echo >&2 'error: you do not seem to have built git yet.'
91 fi
Pavel Roskind9bdd392005-08-10 22:10:01 -040092 exit 1
Junio C Hamanoe1970ce2005-05-13 22:50:32 -070093fi
Junio C Hamanoc2116a12008-03-06 19:04:26 -080094
SZEDER Gábor8cf58002019-01-05 02:08:55 +010095store_arg_to=
Matheus Tavares78dc0882020-03-22 12:58:57 -030096opt_required_arg=
97# $1: option string
98# $2: name of the var where the arg will be stored
99mark_option_requires_arg () {
100 if test -n "$opt_required_arg"
SZEDER Gábor8cf58002019-01-05 02:08:55 +0100101 then
Matheus Tavares78dc0882020-03-22 12:58:57 -0300102 echo "error: options that require args cannot be bundled" \
103 "together: '$opt_required_arg' and '$1'" >&2
104 exit 1
SZEDER Gábor8cf58002019-01-05 02:08:55 +0100105 fi
Matheus Tavares78dc0882020-03-22 12:58:57 -0300106 opt_required_arg=$1
107 store_arg_to=$2
108}
109
110parse_option () {
111 local opt="$1"
SZEDER Gábor8cf58002019-01-05 02:08:55 +0100112
113 case "$opt" in
114 -d|--d|--de|--deb|--debu|--debug)
115 debug=t ;;
116 -i|--i|--im|--imm|--imme|--immed|--immedi|--immedia|--immediat|--immediate)
117 immediate=t ;;
118 -l|--l|--lo|--lon|--long|--long-|--long-t|--long-te|--long-tes|--long-test|--long-tests)
119 GIT_TEST_LONG=t; export GIT_TEST_LONG ;;
120 -r)
Matheus Tavares78dc0882020-03-22 12:58:57 -0300121 mark_option_requires_arg "$opt" run_list
SZEDER Gábor8cf58002019-01-05 02:08:55 +0100122 ;;
123 --run=*)
124 run_list=${opt#--*=} ;;
125 -h|--h|--he|--hel|--help)
126 help=t ;;
127 -v|--v|--ve|--ver|--verb|--verbo|--verbos|--verbose)
128 verbose=t ;;
129 --verbose-only=*)
130 verbose_only=${opt#--*=}
131 ;;
132 -q|--q|--qu|--qui|--quie|--quiet)
133 # Ignore --quiet under a TAP::Harness. Saying how many tests
134 # passed without the ok/not ok details is always an error.
135 test -z "$HARNESS_ACTIVE" && quiet=t ;;
136 --with-dashes)
137 with_dashes=t ;;
Johannes Schindelindd167a32019-01-29 06:19:37 -0800138 --no-bin-wrappers)
139 no_bin_wrappers=t ;;
SZEDER Gábor8cf58002019-01-05 02:08:55 +0100140 --no-color)
141 color= ;;
142 --va|--val|--valg|--valgr|--valgri|--valgrin|--valgrind)
143 valgrind=memcheck
144 tee=t
145 ;;
146 --valgrind=*)
147 valgrind=${opt#--*=}
148 tee=t
149 ;;
150 --valgrind-only=*)
151 valgrind_only=${opt#--*=}
152 tee=t
153 ;;
154 --tee)
155 tee=t ;;
156 --root=*)
157 root=${opt#--*=} ;;
158 --chain-lint)
159 GIT_TEST_CHAIN_LINT=1 ;;
160 --no-chain-lint)
161 GIT_TEST_CHAIN_LINT=0 ;;
162 -x)
163 trace=t ;;
164 -V|--verbose-log)
165 verbose_log=t
166 tee=t
167 ;;
Johannes Schindelin22231902019-01-29 06:19:27 -0800168 --write-junit-xml)
169 write_junit_xml=t
170 ;;
SZEDER Gáborfb7d1e32019-01-05 02:08:59 +0100171 --stress)
172 stress=t ;;
173 --stress=*)
Johannes Schindelinf5457372019-03-03 06:44:55 -0800174 echo "error: --stress does not accept an argument: '$opt'" >&2
175 echo "did you mean --stress-jobs=${opt#*=} or --stress-limit=${opt#*=}?" >&2
176 exit 1
177 ;;
178 --stress-jobs=*)
179 stress=t;
SZEDER Gábor134768c2021-01-26 23:05:33 +0100180 stress_jobs=${opt#--*=}
181 case "$stress_jobs" in
SZEDER Gábor7d661e52019-02-11 20:58:03 +0100182 *[!0-9]*|0*|"")
Johannes Schindelinf5457372019-03-03 06:44:55 -0800183 echo "error: --stress-jobs=<N> requires the number of jobs to run" >&2
SZEDER Gáborfb7d1e32019-01-05 02:08:59 +0100184 exit 1
185 ;;
186 *) # Good.
187 ;;
188 esac
189 ;;
SZEDER Gábor76e27fb2019-02-08 12:50:45 +0100190 --stress-limit=*)
Johannes Schindelinde69e6f2019-03-03 06:44:54 -0800191 stress=t;
SZEDER Gábor76e27fb2019-02-08 12:50:45 +0100192 stress_limit=${opt#--*=}
193 case "$stress_limit" in
SZEDER Gábor7d661e52019-02-11 20:58:03 +0100194 *[!0-9]*|0*|"")
SZEDER Gábor76e27fb2019-02-08 12:50:45 +0100195 echo "error: --stress-limit=<N> requires the number of repetitions" >&2
196 exit 1
197 ;;
198 *) # Good.
199 ;;
200 esac
201 ;;
SZEDER Gábor8cf58002019-01-05 02:08:55 +0100202 *)
203 echo "error: unknown test option '$opt'" >&2; exit 1 ;;
204 esac
Matheus Tavares78dc0882020-03-22 12:58:57 -0300205}
SZEDER Gábor8cf58002019-01-05 02:08:55 +0100206
Matheus Tavares78dc0882020-03-22 12:58:57 -0300207# Parse options while taking care to leave $@ intact, so we will still
208# have all the original command line options when executing the test
209# script again for '--tee' and '--verbose-log' later.
210for opt
211do
212 if test -n "$store_arg_to"
213 then
214 eval $store_arg_to=\$opt
215 store_arg_to=
216 opt_required_arg=
217 continue
218 fi
219
220 case "$opt" in
221 --*|-?)
222 parse_option "$opt" ;;
223 -?*)
224 # bundled short options must be fed separately to parse_option
225 opt=${opt#-}
226 while test -n "$opt"
227 do
228 extra=${opt#?}
229 this=${opt%$extra}
230 opt=$extra
231 parse_option "-$this"
232 done
233 ;;
234 *)
235 echo "error: unknown test option '$opt'" >&2; exit 1 ;;
236 esac
SZEDER Gábor8cf58002019-01-05 02:08:55 +0100237done
238if test -n "$store_arg_to"
239then
Matheus Tavares78dc0882020-03-22 12:58:57 -0300240 echo "error: $opt_required_arg requires an argument" >&2
SZEDER Gábor8cf58002019-01-05 02:08:55 +0100241 exit 1
242fi
243
244if test -n "$valgrind_only"
245then
246 test -z "$valgrind" && valgrind=memcheck
247 test -z "$verbose" && verbose_only="$valgrind_only"
248elif test -n "$valgrind"
249then
250 test -z "$verbose_log" && verbose=t
251fi
252
SZEDER Gáborfb7d1e32019-01-05 02:08:59 +0100253if test -n "$stress"
254then
255 verbose=t
256 trace=t
257 immediate=t
258fi
259
260TEST_STRESS_JOB_SFX="${GIT_TEST_STRESS_JOB_NR:+.stress-$GIT_TEST_STRESS_JOB_NR}"
SZEDER Gábor62c379b2019-01-05 02:08:56 +0100261TEST_NAME="$(basename "$0" .sh)"
SZEDER Gáborffe1afe2019-08-05 23:04:47 +0200262TEST_NUMBER="${TEST_NAME%%-*}"
263TEST_NUMBER="${TEST_NUMBER#t}"
SZEDER Gábor62c379b2019-01-05 02:08:56 +0100264TEST_RESULTS_DIR="$TEST_OUTPUT_DIRECTORY/test-results"
SZEDER Gáborfb7d1e32019-01-05 02:08:59 +0100265TEST_RESULTS_BASE="$TEST_RESULTS_DIR/$TEST_NAME$TEST_STRESS_JOB_SFX"
266TRASH_DIRECTORY="trash directory.$TEST_NAME$TEST_STRESS_JOB_SFX"
SZEDER Gábor61f292d2019-01-05 02:08:57 +0100267test -n "$root" && TRASH_DIRECTORY="$root/$TRASH_DIRECTORY"
268case "$TRASH_DIRECTORY" in
269/*) ;; # absolute path is good
270 *) TRASH_DIRECTORY="$TEST_OUTPUT_DIRECTORY/$TRASH_DIRECTORY" ;;
271esac
SZEDER Gábor62c379b2019-01-05 02:08:56 +0100272
SZEDER Gáborfb7d1e32019-01-05 02:08:59 +0100273# If --stress was passed, run this test repeatedly in several parallel loops.
274if test "$GIT_TEST_STRESS_STARTED" = "done"
275then
276 : # Don't stress test again.
277elif test -n "$stress"
278then
SZEDER Gábor134768c2021-01-26 23:05:33 +0100279 if test -n "$stress_jobs"
SZEDER Gáborfb7d1e32019-01-05 02:08:59 +0100280 then
SZEDER Gábor134768c2021-01-26 23:05:33 +0100281 job_count=$stress_jobs
SZEDER Gáborfb7d1e32019-01-05 02:08:59 +0100282 elif test -n "$GIT_TEST_STRESS_LOAD"
283 then
284 job_count="$GIT_TEST_STRESS_LOAD"
285 elif job_count=$(getconf _NPROCESSORS_ONLN 2>/dev/null) &&
286 test -n "$job_count"
287 then
288 job_count=$((2 * $job_count))
289 else
290 job_count=8
291 fi
292
293 mkdir -p "$TEST_RESULTS_DIR"
294 stressfail="$TEST_RESULTS_BASE.stress-failed"
295 rm -f "$stressfail"
296
297 stress_exit=0
298 trap '
299 kill $job_pids 2>/dev/null
300 wait
301 stress_exit=1
302 ' TERM INT HUP
303
304 job_pids=
305 job_nr=0
306 while test $job_nr -lt "$job_count"
307 do
308 (
309 GIT_TEST_STRESS_STARTED=done
310 GIT_TEST_STRESS_JOB_NR=$job_nr
311 export GIT_TEST_STRESS_STARTED GIT_TEST_STRESS_JOB_NR
312
313 trap '
314 kill $test_pid 2>/dev/null
315 wait
316 exit 1
317 ' TERM INT
318
SZEDER Gábor76e27fb2019-02-08 12:50:45 +0100319 cnt=1
320 while ! test -e "$stressfail" &&
321 { test -z "$stress_limit" ||
322 test $cnt -le $stress_limit ; }
SZEDER Gáborfb7d1e32019-01-05 02:08:59 +0100323 do
324 $TEST_SHELL_PATH "$0" "$@" >"$TEST_RESULTS_BASE.stress-$job_nr.out" 2>&1 &
325 test_pid=$!
326
327 if wait $test_pid
328 then
329 printf "OK %2d.%d\n" $GIT_TEST_STRESS_JOB_NR $cnt
330 else
331 echo $GIT_TEST_STRESS_JOB_NR >>"$stressfail"
332 printf "FAIL %2d.%d\n" $GIT_TEST_STRESS_JOB_NR $cnt
333 fi
334 cnt=$(($cnt + 1))
335 done
336 ) &
337 job_pids="$job_pids $!"
338 job_nr=$(($job_nr + 1))
339 done
340
341 wait
342
343 if test -f "$stressfail"
344 then
SZEDER Gábor76e27fb2019-02-08 12:50:45 +0100345 stress_exit=1
SZEDER Gáborfb7d1e32019-01-05 02:08:59 +0100346 echo "Log(s) of failed test run(s):"
347 for failed_job_nr in $(sort -n "$stressfail")
348 do
349 echo "Contents of '$TEST_RESULTS_BASE.stress-$failed_job_nr.out':"
350 cat "$TEST_RESULTS_BASE.stress-$failed_job_nr.out"
351 done
352 rm -rf "$TRASH_DIRECTORY.stress-failed"
353 # Move the last one.
354 mv "$TRASH_DIRECTORY.stress-$failed_job_nr" "$TRASH_DIRECTORY.stress-failed"
355 fi
356
357 exit $stress_exit
358fi
359
Ramkumar Ramachandra4cde5192012-09-22 10:25:10 +0530360# if --tee was passed, write the output not only to the terminal, but
361# additionally to the file test-results/$BASENAME.out, too.
SZEDER Gábor8cf58002019-01-05 02:08:55 +0100362if test "$GIT_TEST_TEE_STARTED" = "done"
363then
364 : # do not redirect again
365elif test -n "$tee"
366then
SZEDER Gábor62c379b2019-01-05 02:08:56 +0100367 mkdir -p "$TEST_RESULTS_DIR"
Jeff King452320f2016-10-21 06:48:00 -0400368
369 # Make this filename available to the sub-process in case it is using
370 # --verbose-log.
SZEDER Gábor62c379b2019-01-05 02:08:56 +0100371 GIT_TEST_TEE_OUTPUT_FILE=$TEST_RESULTS_BASE.out
Jeff King452320f2016-10-21 06:48:00 -0400372 export GIT_TEST_TEE_OUTPUT_FILE
373
374 # Truncate before calling "tee -a" to get rid of the results
375 # from any previous runs.
376 >"$GIT_TEST_TEE_OUTPUT_FILE"
377
Jeff King3f824e92017-12-08 05:47:22 -0500378 (GIT_TEST_TEE_STARTED=done ${TEST_SHELL_PATH} "$0" "$@" 2>&1;
SZEDER Gábor62c379b2019-01-05 02:08:56 +0100379 echo $? >"$TEST_RESULTS_BASE.exit") | tee -a "$GIT_TEST_TEE_OUTPUT_FILE"
380 test "$(cat "$TEST_RESULTS_BASE.exit")" = 0
Ramkumar Ramachandra4cde5192012-09-22 10:25:10 +0530381 exit
SZEDER Gábor8cf58002019-01-05 02:08:55 +0100382fi
383
384if test -n "$trace" && test -n "$test_untraceable"
385then
386 # '-x' tracing requested, but this test script can't be reliably
387 # traced, unless it is run with a Bash version supporting
388 # BASH_XTRACEFD (introduced in Bash v4.1).
389 #
390 # Perform this version check _after_ the test script was
391 # potentially re-executed with $TEST_SHELL_PATH for '--tee' or
392 # '--verbose-log', so the right shell is checked and the
393 # warning is issued only once.
394 if test -n "$BASH_VERSION" && eval '
395 test ${BASH_VERSINFO[0]} -gt 4 || {
396 test ${BASH_VERSINFO[0]} -eq 4 &&
397 test ${BASH_VERSINFO[1]} -ge 1
398 }
399 '
400 then
401 : Executed by a Bash version supporting BASH_XTRACEFD. Good.
402 else
403 echo >&2 "warning: ignoring -x; '$0' is untraceable without BASH_XTRACEFD"
404 trace=
405 fi
406fi
407if test -n "$trace" && test -z "$verbose_log"
408then
409 verbose=t
410fi
Ramkumar Ramachandra4cde5192012-09-22 10:25:10 +0530411
Felipe Contreras390b44e2021-08-05 14:48:25 -0500412# Since bash 5.0, checkwinsize is enabled by default which does
413# update the COLUMNS variable every time a non-builtin command
414# completes, even for non-interactive shells.
415# Disable that since we are aiming for repeatability.
416test -n "$BASH_VERSION" && shopt -u checkwinsize 2>/dev/null
417
Junio C Hamanoe1970ce2005-05-13 22:50:32 -0700418# For repeatability, reset the environment to known value.
Richard Hansend5c1b7c2015-06-17 17:11:21 -0400419# TERM is sanitized below, after saving color control sequences.
Junio C Hamanoe1970ce2005-05-13 22:50:32 -0700420LANG=C
421LC_ALL=C
422PAGER=cat
423TZ=UTC
Ævar Arnfjörð Bjarmasonc49a1772021-06-29 13:29:36 +0200424COLUMNS=80
425export LANG LC_ALL PAGER TZ COLUMNS
Eric Wong8ff99e72006-07-11 12:01:54 -0700426EDITOR=:
Ævar Arnfjörð Bjarmason6cdccfc2018-11-08 21:15:29 +0000427
Stefano Lattarini661bfd12012-03-02 19:48:36 +0100428# A call to "unset" with no arguments causes at least Solaris 10
429# /usr/xpg4/bin/sh and /bin/ksh to bail out. So keep the unsets
430# deriving from the command substitution clustered with the other
431# ones.
Ævar Arnfjörð Bjarmasonc49a1772021-06-29 13:29:36 +0200432unset VISUAL EMAIL LANGUAGE $("$PERL_PATH" -e '
Jonathan Nieder95a1d122011-03-15 05:10:45 -0500433 my @env = keys %ENV;
Jens Lehmann730477f2011-03-28 21:16:09 +0200434 my $ok = join("|", qw(
435 TRACE
436 DEBUG
Jens Lehmann730477f2011-03-28 21:16:09 +0200437 TEST
438 .*_TEST
439 PROVE
440 VALGRIND
René Scharfeac001282013-01-06 18:47:57 +0100441 UNZIP
Nguyễn Thái Ngọc Duyedb54082013-01-15 20:50:56 +0700442 PERF_
Jeff Kinge2a0ccc2014-05-22 05:28:50 -0400443 CURL_VERBOSE
Elia Pinto4527aa12016-09-05 10:24:42 +0000444 TRACE_CURL
Jens Lehmann730477f2011-03-28 21:16:09 +0200445 ));
446 my @vars = grep(/^GIT_/ && !/^GIT_($ok)/o, @env);
Jonathan Nieder95a1d122011-03-15 05:10:45 -0500447 print join("\n", @vars);
448')
Genki Sky7976e902018-02-15 21:46:04 -0500449unset XDG_CACHE_HOME
Jeff King5adf84e2012-07-24 07:53:05 -0400450unset XDG_CONFIG_HOME
Benoit Person8bade1e2013-07-04 22:38:55 +0200451unset GITPERLLIB
Prarit Bhargavad8b82172019-10-29 08:09:14 -0400452TEST_AUTHOR_LOCALNAME=author
453TEST_AUTHOR_DOMAIN=example.com
454GIT_AUTHOR_EMAIL=${TEST_AUTHOR_LOCALNAME}@${TEST_AUTHOR_DOMAIN}
Junio C Hamano29e55cd2006-02-10 19:11:23 -0800455GIT_AUTHOR_NAME='A U Thor'
Jeff Kingf2e39372020-07-09 16:42:04 -0400456GIT_AUTHOR_DATE='1112354055 +0200'
Prarit Bhargavad8b82172019-10-29 08:09:14 -0400457TEST_COMMITTER_LOCALNAME=committer
458TEST_COMMITTER_DOMAIN=example.com
459GIT_COMMITTER_EMAIL=${TEST_COMMITTER_LOCALNAME}@${TEST_COMMITTER_DOMAIN}
Junio C Hamano29e55cd2006-02-10 19:11:23 -0800460GIT_COMMITTER_NAME='C O Mitter'
Jeff Kingf2e39372020-07-09 16:42:04 -0400461GIT_COMMITTER_DATE='1112354055 +0200'
Shawn O. Pearce8d0fc482007-02-04 00:45:47 -0500462GIT_MERGE_VERBOSITY=5
Junio C Hamanof8246282012-01-10 22:44:45 -0800463GIT_MERGE_AUTOEDIT=no
464export GIT_MERGE_VERBOSITY GIT_MERGE_AUTOEDIT
Junio C Hamano29e55cd2006-02-10 19:11:23 -0800465export GIT_AUTHOR_EMAIL GIT_AUTHOR_NAME
466export GIT_COMMITTER_EMAIL GIT_COMMITTER_NAME
Jeff Kingf2e39372020-07-09 16:42:04 -0400467export GIT_COMMITTER_DATE GIT_AUTHOR_DATE
Jonathan Niederd33738d2009-11-11 17:56:07 -0600468export EDITOR
Junio C Hamanoe1970ce2005-05-13 22:50:32 -0700469
brian m. carlson02a32db2020-07-29 23:14:24 +0000470GIT_DEFAULT_HASH="${GIT_TEST_DEFAULT_HASH:-sha1}"
471export GIT_DEFAULT_HASH
Elijah Newrenf3b964a2021-03-20 00:03:56 +0000472GIT_TEST_MERGE_ALGORITHM="${GIT_TEST_MERGE_ALGORITHM:-ort}"
473export GIT_TEST_MERGE_ALGORITHM
brian m. carlson02a32db2020-07-29 23:14:24 +0000474
Karsten Blees124647c2014-07-12 02:03:01 +0200475# Tests using GIT_TRACE typically don't want <timestamp> <file>:<line> output
476GIT_TRACE_BARE=1
477export GIT_TRACE_BARE
478
Ben Peart1f357b02018-09-18 23:29:36 +0000479# Use specific version of the index file format
480if test -n "${GIT_TEST_INDEX_VERSION:+isset}"
Thomas Gummerer5d9fc882014-02-23 21:49:58 +0100481then
Ben Peart1f357b02018-09-18 23:29:36 +0000482 GIT_INDEX_VERSION="$GIT_TEST_INDEX_VERSION"
Thomas Gummerer5d9fc882014-02-23 21:49:58 +0100483 export GIT_INDEX_VERSION
484fi
485
Jeff King5338ed22020-10-21 23:24:00 -0400486if test -n "$GIT_TEST_PERL_FATAL_WARNINGS"
487then
488 GIT_PERL_FATAL_WARNINGS=1
489 export GIT_PERL_FATAL_WARNINGS
490fi
491
Elia Pintoa731fa92012-09-14 09:54:22 -0700492# Add libc MALLOC and MALLOC_PERTURB test
493# only if we are not executing the test with valgrind
SZEDER Gábor8cf58002019-01-05 02:08:55 +0100494if test -n "$valgrind" ||
René Scharfeee1431b2012-09-26 22:16:39 +0200495 test -n "$TEST_NO_MALLOC_CHECK"
Junio C Hamano1b3185f2012-09-14 20:38:24 -0700496then
497 setup_malloc_check () {
498 : nothing
499 }
500 teardown_malloc_check () {
501 : nothing
502 }
503else
504 setup_malloc_check () {
505 MALLOC_CHECK_=3 MALLOC_PERTURB_=165
506 export MALLOC_CHECK_ MALLOC_PERTURB_
507 }
508 teardown_malloc_check () {
509 unset MALLOC_CHECK_ MALLOC_PERTURB_
510 }
511fi
Elia Pintoa731fa92012-09-14 09:54:22 -0700512
Junio C Hamano886a3902007-04-24 11:21:47 -0700513# Protect ourselves from common misconfiguration to export
514# CDPATH into the environment
515unset CDPATH
516
Bert Wesarg5565f472009-11-18 17:15:19 +0100517unset GREP_OPTIONS
René Scharfeac001282013-01-06 18:47:57 +0100518unset UNZIP
Bert Wesarg5565f472009-11-18 17:15:19 +0100519
Robin Rosenberg3d5c0cc2006-09-23 00:35:20 +0200520case $(echo $GIT_TRACE |tr "[A-Z]" "[a-z]") in
Ramsay Jones1c0cc752012-09-01 19:11:49 +01005211|2|true)
Jeff King025232e2015-03-13 00:50:56 -0400522 GIT_TRACE=4
Ramsay Jones1c0cc752012-09-01 19:11:49 +0100523 ;;
Christian Couder6ce4e612006-09-02 18:23:48 +0200524esac
525
Junio C Hamano3f4ab622011-08-08 11:51:00 -0700526# Line feed
527LF='
528'
529
Denton Liubd482d62019-09-05 15:10:05 -0700530# Single quote
531SQ=\'
532
Jeff Kinga42643a2014-12-15 18:15:20 -0500533# UTF-8 ZERO WIDTH NON-JOINER, which HFS+ ignores
534# when case-folding filenames
535u200c=$(printf '\342\200\214')
536
Ævar Arnfjörð Bjarmason70507912021-09-11 13:17:51 +0200537export _x05 _x35 LF u200c EMPTY_TREE EMPTY_BLOB ZERO_OID OID_REGEX
Thomas Rast342e9ef2012-02-17 11:25:09 +0100538
Junio C Hamanoe1970ce2005-05-13 22:50:32 -0700539# Each test should start with something like this, after copyright notices:
540#
541# test_description='Description of this test...
542# This test checks if command xyzzy does the right thing...
543# '
544# . ./test-lib.sh
Richard Hansend5c1b7c2015-06-17 17:11:21 -0400545test "x$TERM" != "xdumb" && (
Richard Hansenca92a662015-06-17 15:06:25 -0400546 test -t 1 &&
547 tput bold >/dev/null 2>&1 &&
548 tput setaf 1 >/dev/null 2>&1 &&
549 tput sgr0 >/dev/null 2>&1
550 ) &&
551 color=t
Junio C Hamanoe1970ce2005-05-13 22:50:32 -0700552
Richard Hansenca92a662015-06-17 15:06:25 -0400553if test -n "$color"
554then
Richard Hansend5c1b7c2015-06-17 17:11:21 -0400555 # Save the color control sequences now rather than run tput
556 # each time say_color() is called. This is done for two
557 # reasons:
558 # * TERM will be changed to dumb
559 # * HOME will be changed to a temporary directory and tput
560 # might need to read ~/.terminfo from the original HOME
561 # directory to get the control sequences
562 # Note: This approach assumes the control sequences don't end
563 # in a newline for any terminal of interest (command
564 # substitutions strip trailing newlines). Given that most
565 # (all?) terminals in common use are related to ECMA-48, this
566 # shouldn't be a problem.
567 say_color_error=$(tput bold; tput setaf 1) # bold red
568 say_color_skip=$(tput setaf 4) # blue
569 say_color_warn=$(tput setaf 3) # brown/yellow
570 say_color_pass=$(tput setaf 2) # green
571 say_color_info=$(tput setaf 6) # cyan
572 say_color_reset=$(tput sgr0)
573 say_color_="" # no formatting for normal text
Richard Hansenca92a662015-06-17 15:06:25 -0400574 say_color () {
Richard Hansend5c1b7c2015-06-17 17:11:21 -0400575 test -z "$1" && test -n "$quiet" && return
576 eval "say_color_color=\$say_color_$1"
Richard Hansenca92a662015-06-17 15:06:25 -0400577 shift
Richard Hansend5c1b7c2015-06-17 17:11:21 -0400578 printf "%s\\n" "$say_color_color$*$say_color_reset"
Richard Hansenca92a662015-06-17 15:06:25 -0400579 }
580else
581 say_color() {
582 test -z "$1" && test -n "$quiet" && return
583 shift
584 printf "%s\n" "$*"
585 }
586fi
587
Philippe Blainadd52402021-09-06 04:38:59 +0000588USER_TERM="$TERM"
Richard Hansend5c1b7c2015-06-17 17:11:21 -0400589TERM=dumb
Philippe Blainadd52402021-09-06 04:38:59 +0000590export TERM USER_TERM
Richard Hansend5c1b7c2015-06-17 17:11:21 -0400591
Ævar Arnfjörð Bjarmason8583bf72021-10-14 02:47:28 +0200592_error_exit () {
Johannes Schindelinab7d8542019-10-04 08:09:34 -0700593 finalize_junit_xml
Clemens Buchacher6e7b5aa2009-06-01 14:14:41 +0200594 GIT_EXIT_OK=t
Pierre Habouzit55db1df2007-10-24 22:03:38 +0200595 exit 1
596}
597
Ævar Arnfjörð Bjarmason8583bf72021-10-14 02:47:28 +0200598error () {
599 say_color error "error: $*"
600 _error_exit
601}
602
SZEDER Gábor165293a2018-11-19 14:13:26 +0100603BUG () {
604 error >&7 "bug in the test script: $*"
605}
606
Ævar Arnfjörð Bjarmason234383c2021-10-14 02:47:29 +0200607BAIL_OUT () {
608 test $# -ne 1 && BUG "1 param"
609
610 # Do not change "Bail out! " string. It's part of TAP syntax:
611 # https://testanything.org/tap-specification.html
612 local bail_out="Bail out! "
613 local message="$1"
614
615 say_color error $bail_out "$message"
616 _error_exit
617}
618
Pierre Habouzit55db1df2007-10-24 22:03:38 +0200619say () {
620 say_color info "$*"
621}
622
Jeff King614fe012016-10-22 00:45:06 -0400623if test -n "$HARNESS_ACTIVE"
624then
625 if test "$verbose" = t || test -n "$verbose_only"
626 then
Ævar Arnfjörð Bjarmason234383c2021-10-14 02:47:29 +0200627 BAIL_OUT 'verbose mode forbidden under TAP harness; try --verbose-log'
Jeff King614fe012016-10-22 00:45:06 -0400628 fi
629fi
630
Michele Ballabio570f3222007-11-10 15:17:25 +0100631test "${test_description}" != "" ||
632error "Test script did not set test_description."
633
634if test "$help" = "t"
635then
Uwe Storbeckcb1aefd2014-03-18 01:14:11 +0100636 printf '%s\n' "$test_description"
Michele Ballabio570f3222007-11-10 15:17:25 +0100637 exit 0
638fi
639
Pavel Roskin4d9d62f2005-08-10 23:56:21 -0400640exec 5>&1
Jeff King781f76b2011-12-15 01:55:29 -0500641exec 6<&0
SZEDER Gábor4ecae3c2017-03-18 17:13:59 +0100642exec 7>&2
Jeff King452320f2016-10-21 06:48:00 -0400643if test "$verbose_log" = "t"
644then
645 exec 3>>"$GIT_TEST_TEE_OUTPUT_FILE" 4>&3
646elif test "$verbose" = "t"
Junio C Hamanoe1970ce2005-05-13 22:50:32 -0700647then
648 exec 4>&2 3>&1
649else
650 exec 4>/dev/null 3>/dev/null
651fi
652
Jeff Kingd88785e2016-05-11 09:44:04 -0400653# Send any "-x" output directly to stderr to avoid polluting tests
654# which capture stderr. We can do this unconditionally since it
655# has no effect if tracing isn't turned on.
656#
657# Note that this sets up the trace fd as soon as we assign the variable, so it
658# must come after the creation of descriptor 4 above. Likewise, we must never
659# unset this, as it has the side effect of closing descriptor 4, which we
660# use to show verbose tests to the user.
661#
662# Note also that we don't need or want to export it. The tracing is local to
663# this shell, and we would not want to influence any shells we exec.
664BASH_XTRACEFD=4
665
Junio C Hamanoe1970ce2005-05-13 22:50:32 -0700666test_failure=0
667test_count=0
Junio C Hamano41ac4142008-02-01 01:50:53 -0800668test_fixed=0
669test_broken=0
Sverre Rabbelier2d84e9f2008-06-08 16:04:33 +0200670test_success=0
Junio C Hamanoe1970ce2005-05-13 22:50:32 -0700671
Fabian Stelzer49da4042021-11-20 16:03:59 +0100672test_missing_prereq=
673
Ævar Arnfjörð Bjarmasond998bd42010-06-24 17:44:46 +0000674test_external_has_tap=0
675
Clemens Buchacherfaa4bc32008-02-27 20:28:45 +0100676die () {
Clemens Buchacher6e7b5aa2009-06-01 14:14:41 +0200677 code=$?
Johannes Schindelin900721e2019-03-13 13:24:11 +0100678 # This is responsible for running the atexit commands even when a
679 # test script run with '--immediate' fails, or when the user hits
680 # ctrl-C, i.e. when 'test_done' is not invoked at all.
681 test_atexit_handler || code=$?
Clemens Buchacher6e7b5aa2009-06-01 14:14:41 +0200682 if test -n "$GIT_EXIT_OK"
683 then
684 exit $code
685 else
686 echo >&5 "FATAL: Unexpected exit with code $code"
687 exit 1
688 fi
Clemens Buchacherfaa4bc32008-02-27 20:28:45 +0100689}
690
Clemens Buchacher6e7b5aa2009-06-01 14:14:41 +0200691GIT_EXIT_OK=
Markus Heidelberg35641312009-01-20 00:43:26 +0100692trap 'die' EXIT
SZEDER Gáborc5c39f42019-03-13 13:24:09 +0100693# Disable '-x' tracing, because with some shells, notably dash, it
694# prevents running the cleanup commands when a test script run with
695# '--verbose-log -x' is interrupted.
696trap '{ code=$?; set +x; } 2>/dev/null; exit $code' INT TERM HUP
Pavel Roskin41184272005-08-11 12:00:40 -0400697
Thomas Rast12a29b12012-02-17 11:25:08 +0100698# The user-facing functions are loaded from a separate file so that
699# test_perf subshells can have them too
Junio C Hamano3c8f12c2012-06-24 22:01:35 -0700700. "$TEST_DIRECTORY/test-lib-functions.sh"
Jonathan Nieder05236a52010-10-17 02:36:58 +0800701
Junio C Hamano886856a2005-05-14 00:24:27 -0700702# You are not expected to call test_ok_ and test_failure_ directly, use
Torstein Hegge3fa36662013-10-27 10:56:33 +0100703# the test_expect_* functions instead.
Junio C Hamano886856a2005-05-14 00:24:27 -0700704
705test_ok_ () {
Johannes Schindelin22231902019-01-29 06:19:27 -0800706 if test -n "$write_junit_xml"
707 then
708 write_junit_xml_testcase "$*"
709 fi
Johannes Sixtd5d9de12009-02-05 20:59:27 +0100710 test_success=$(($test_success + 1))
Thomas Rast633fe502013-10-19 23:06:08 +0200711 say_color "" "ok $test_count - $@"
Junio C Hamanoe1970ce2005-05-13 22:50:32 -0700712}
713
Junio C Hamano886856a2005-05-14 00:24:27 -0700714test_failure_ () {
Johannes Schindelin22231902019-01-29 06:19:27 -0800715 if test -n "$write_junit_xml"
716 then
717 junit_insert="<failure message=\"not ok $test_count -"
718 junit_insert="$junit_insert $(xml_attr_encode "$1")\">"
719 junit_insert="$junit_insert $(xml_attr_encode \
Johannes Schindelinaf9912e2019-01-29 06:19:34 -0800720 "$(if test -n "$GIT_TEST_TEE_OUTPUT_FILE"
721 then
722 test-tool path-utils skip-n-bytes \
723 "$GIT_TEST_TEE_OUTPUT_FILE" $GIT_TEST_TEE_OFFSET
724 else
725 printf '%s\n' "$@" | sed 1d
726 fi)")"
Johannes Schindelin22231902019-01-29 06:19:27 -0800727 junit_insert="$junit_insert</failure>"
Johannes Schindelinaf9912e2019-01-29 06:19:34 -0800728 if test -n "$GIT_TEST_TEE_OUTPUT_FILE"
729 then
730 junit_insert="$junit_insert<system-err>$(xml_attr_encode \
731 "$(cat "$GIT_TEST_TEE_OUTPUT_FILE")")</system-err>"
732 fi
Johannes Schindelin22231902019-01-29 06:19:27 -0800733 write_junit_xml_testcase "$1" " $junit_insert"
734 fi
Johannes Sixtd5d9de12009-02-05 20:59:27 +0100735 test_failure=$(($test_failure + 1))
Junio C Hamanoe31600b2020-05-15 09:47:51 -0700736 say_color error "not ok $test_count - $1"
Junio C Hamanobf0dd8a2005-07-22 19:09:34 -0700737 shift
Uwe Storbeckcb1aefd2014-03-18 01:14:11 +0100738 printf '%s\n' "$*" | sed -e 's/^/# /'
Ævar Arnfjörð Bjarmason8583bf72021-10-14 02:47:28 +0200739 test "$immediate" = "" || _error_exit
Junio C Hamano886856a2005-05-14 00:24:27 -0700740}
741
Junio C Hamano41ac4142008-02-01 01:50:53 -0800742test_known_broken_ok_ () {
Johannes Schindelin22231902019-01-29 06:19:27 -0800743 if test -n "$write_junit_xml"
744 then
745 write_junit_xml_testcase "$* (breakage fixed)"
746 fi
Junio C Hamano41ac4142008-02-01 01:50:53 -0800747 test_fixed=$(($test_fixed+1))
Thomas Rast633fe502013-10-19 23:06:08 +0200748 say_color error "ok $test_count - $@ # TODO known breakage vanished"
Junio C Hamano41ac4142008-02-01 01:50:53 -0800749}
750
751test_known_broken_failure_ () {
Johannes Schindelin22231902019-01-29 06:19:27 -0800752 if test -n "$write_junit_xml"
753 then
754 write_junit_xml_testcase "$* (known breakage)"
755 fi
Junio C Hamano41ac4142008-02-01 01:50:53 -0800756 test_broken=$(($test_broken+1))
Thomas Rast633fe502013-10-19 23:06:08 +0200757 say_color warn "not ok $test_count - $@ # TODO known breakage"
Junio C Hamano41ac4142008-02-01 01:50:53 -0800758}
Junio C Hamano886856a2005-05-14 00:24:27 -0700759
760test_debug () {
Junio C Hamano8e832eb2005-08-10 22:53:27 -0700761 test "$debug" = "" || eval "$1"
Junio C Hamanoe1970ce2005-05-13 22:50:32 -0700762}
763
Thomas Raste6a6ddc2013-06-18 14:25:58 +0200764match_pattern_list () {
765 arg="$1"
766 shift
767 test -z "$*" && return 1
Jeff King560bf512021-06-16 06:23:07 -0400768 # We need to use "$*" to get field-splitting, but we want to
769 # disable globbing, since we are matching against an arbitrary
770 # $arg, not what's in the filesystem. Using "set -f" accomplishes
771 # that, but we must do it in a subshell to avoid impacting the
772 # rest of the script. The exit value of the subshell becomes
773 # the function's return value.
774 (
775 set -f
776 for pattern_ in $*
777 do
778 case "$arg" in
779 $pattern_)
780 exit 0
781 ;;
782 esac
783 done
784 exit 1
785 )
Thomas Raste6a6ddc2013-06-18 14:25:58 +0200786}
787
Ilya Bobyr0445e6f2014-04-30 02:50:44 -0700788match_test_selector_list () {
Elijah Newrenf21ac362020-10-18 00:23:45 +0000789 operation="$1"
790 shift
Ilya Bobyr0445e6f2014-04-30 02:50:44 -0700791 title="$1"
792 shift
793 arg="$1"
794 shift
795 test -z "$1" && return 0
796
Elijah Newrenf21ac362020-10-18 00:23:45 +0000797 # Commas are accepted as separators.
Ilya Bobyr0445e6f2014-04-30 02:50:44 -0700798 OLDIFS=$IFS
Elijah Newrenf21ac362020-10-18 00:23:45 +0000799 IFS=','
Ilya Bobyr0445e6f2014-04-30 02:50:44 -0700800 set -- $1
801 IFS=$OLDIFS
802
803 # If the first selector is negative we include by default.
804 include=
805 case "$1" in
806 !*) include=t ;;
807 esac
808
809 for selector
810 do
811 orig_selector=$selector
812
813 positive=t
814 case "$selector" in
815 !*)
816 positive=
817 selector=${selector##?}
818 ;;
819 esac
820
821 test -z "$selector" && continue
822
823 case "$selector" in
824 *-*)
825 if expr "z${selector%%-*}" : "z[0-9]*[^0-9]" >/dev/null
826 then
Elijah Newrenf21ac362020-10-18 00:23:45 +0000827 echo "error: $operation: invalid non-numeric in range" \
Ilya Bobyr0445e6f2014-04-30 02:50:44 -0700828 "start: '$orig_selector'" >&2
829 exit 1
830 fi
831 if expr "z${selector#*-}" : "z[0-9]*[^0-9]" >/dev/null
832 then
Elijah Newrenf21ac362020-10-18 00:23:45 +0000833 echo "error: $operation: invalid non-numeric in range" \
Ilya Bobyr0445e6f2014-04-30 02:50:44 -0700834 "end: '$orig_selector'" >&2
835 exit 1
836 fi
837 ;;
838 *)
839 if expr "z$selector" : "z[0-9]*[^0-9]" >/dev/null
840 then
Elijah Newrenf21ac362020-10-18 00:23:45 +0000841 case "$title" in *${selector}*)
842 include=$positive
843 ;;
844 esac
845 continue
Ilya Bobyr0445e6f2014-04-30 02:50:44 -0700846 fi
847 esac
848
849 # Short cut for "obvious" cases
850 test -z "$include" && test -z "$positive" && continue
851 test -n "$include" && test -n "$positive" && continue
852
853 case "$selector" in
854 -*)
855 if test $arg -le ${selector#-}
856 then
857 include=$positive
858 fi
859 ;;
860 *-)
861 if test $arg -ge ${selector%-}
862 then
863 include=$positive
864 fi
865 ;;
866 *-*)
867 if test ${selector%%-*} -le $arg \
868 && test $arg -le ${selector#*-}
869 then
870 include=$positive
871 fi
872 ;;
873 *)
874 if test $arg -eq $selector
875 then
876 include=$positive
877 fi
878 ;;
879 esac
880 done
881
882 test -n "$include"
883}
884
Thomas Rastff09af32013-06-23 20:12:56 +0200885maybe_teardown_verbose () {
886 test -z "$verbose_only" && return
887 exec 4>/dev/null 3>/dev/null
888 verbose=
889}
890
891last_verbose=t
892maybe_setup_verbose () {
893 test -z "$verbose_only" && return
Jeff King560bf512021-06-16 06:23:07 -0400894 if match_pattern_list $test_count "$verbose_only"
Thomas Rastff09af32013-06-23 20:12:56 +0200895 then
896 exec 4>&2 3>&1
897 # Emit a delimiting blank line when going from
898 # non-verbose to verbose. Within verbose mode the
899 # delimiter is printed by test_expect_*. The choice
900 # of the initial $last_verbose is such that before
901 # test 1, we do not print it.
902 test -z "$last_verbose" && echo >&3 ""
903 verbose=t
904 else
905 exec 4>/dev/null 3>/dev/null
906 verbose=
907 fi
908 last_verbose=$verbose
909}
910
Thomas Rast5dfc3682013-06-23 20:12:57 +0200911maybe_teardown_valgrind () {
912 test -z "$GIT_VALGRIND" && return
913 GIT_VALGRIND_ENABLED=
914}
915
916maybe_setup_valgrind () {
917 test -z "$GIT_VALGRIND" && return
Thomas Rast26a07302013-10-19 23:06:07 +0200918 if test -z "$valgrind_only"
Thomas Rast5dfc3682013-06-23 20:12:57 +0200919 then
920 GIT_VALGRIND_ENABLED=t
921 return
922 fi
923 GIT_VALGRIND_ENABLED=
Jeff King560bf512021-06-16 06:23:07 -0400924 if match_pattern_list $test_count "$valgrind_only"
Thomas Rast5dfc3682013-06-23 20:12:57 +0200925 then
926 GIT_VALGRIND_ENABLED=t
927 fi
928}
929
Johannes Schindelin477dcad2020-03-26 15:35:26 +0000930trace_level_=0
Jeff King9b5fe782015-08-06 01:33:57 -0400931want_trace () {
Jeff Kingf5ba2de2017-12-08 05:47:17 -0500932 test "$trace" = t && {
933 test "$verbose" = t || test "$verbose_log" = t
934 }
Jeff King9b5fe782015-08-06 01:33:57 -0400935}
936
Jeff Kinga136f6d2014-10-10 02:47:27 -0400937# This is a separate function because some tests use
938# "return" to end a test_expect_success block early
939# (and we want to make sure we run any cleanup like
940# "set +x").
941test_eval_inner_ () {
942 # Do not add anything extra (including LF) after '$*'
943 eval "
Johannes Schindelin477dcad2020-03-26 15:35:26 +0000944 want_trace && trace_level_=$(($trace_level_+1)) && set -x
Jeff Kinga136f6d2014-10-10 02:47:27 -0400945 $*"
946}
947
Jonathan Niedera7c58f22011-08-08 03:17:09 +0200948test_eval_ () {
Jeff King90c8a1d2017-12-08 05:47:08 -0500949 # If "-x" tracing is in effect, then we want to avoid polluting stderr
950 # with non-test commands. But once in "set -x" mode, we cannot prevent
Jeff Kinga136f6d2014-10-10 02:47:27 -0400951 # the shell from printing the "set +x" to turn it off (nor the saving
952 # of $? before that). But we can make sure that the output goes to
953 # /dev/null.
954 #
Jeff King90c8a1d2017-12-08 05:47:08 -0500955 # There are a few subtleties here:
956 #
957 # - we have to redirect descriptor 4 in addition to 2, to cover
958 # BASH_XTRACEFD
959 #
960 # - the actual eval has to come before the redirection block (since
961 # it needs to see descriptor 4 to set up its stderr)
962 #
963 # - likewise, any error message we print must be outside the block to
964 # access descriptor 4
965 #
966 # - checking $? has to come immediately after the eval, but it must
967 # be _inside_ the block to avoid polluting the "set -x" output
968 #
969
970 test_eval_inner_ "$@" </dev/null >&3 2>&4
Jeff Kinga136f6d2014-10-10 02:47:27 -0400971 {
Jeff Kinga136f6d2014-10-10 02:47:27 -0400972 test_eval_ret_=$?
Jeff King9b5fe782015-08-06 01:33:57 -0400973 if want_trace
Jeff Kinga136f6d2014-10-10 02:47:27 -0400974 then
Johannes Schindelin477dcad2020-03-26 15:35:26 +0000975 test 1 = $trace_level_ && set +x
976 trace_level_=$(($trace_level_-1))
Jeff Kinga136f6d2014-10-10 02:47:27 -0400977 fi
Jeff King90c8a1d2017-12-08 05:47:08 -0500978 } 2>/dev/null 4>&2
979
980 if test "$test_eval_ret_" != 0 && want_trace
981 then
982 say_color error >&4 "error: last command exited with \$?=$test_eval_ret_"
983 fi
Jeff Kinga136f6d2014-10-10 02:47:27 -0400984 return $test_eval_ret_
Jonathan Niedera7c58f22011-08-08 03:17:09 +0200985}
986
Pavel Roskin4d9d62f2005-08-10 23:56:21 -0400987test_run_ () {
Jonathan Niederb6b0afd2010-05-06 03:41:10 -0500988 test_cleanup=:
Junio C Hamanob5867442011-06-27 11:02:22 -0700989 expecting_failure=$2
Jeff Kingbb79af92015-03-20 06:05:48 -0400990
Jeff King92b269f2015-04-22 16:09:57 -0400991 if test "${GIT_TEST_CHAIN_LINT:-1}" != 0; then
Jeff King2a01ef82015-08-06 01:31:47 -0400992 # turn off tracing for this test-eval, as it simply creates
993 # confusing noise in the "-x" output
994 trace_tmp=$trace
995 trace=
Jeff Kingbb79af92015-03-20 06:05:48 -0400996 # 117 is magic because it is unlikely to match the exit
997 # code of other programs
Jeff King2d86a962021-05-13 02:25:53 -0400998 if test "OK-117" != "$(test_eval_ "(exit 117) && $1${LF}${LF}echo OK-\$?" 3>&1)" ||
999 {
1000 test "${GIT_TEST_CHAIN_LINT_HARDER:-${GIT_TEST_CHAIN_LINT_HARDER_DEFAULT:-1}}" != 0 &&
1001 $(printf '%s\n' "$1" | sed -f "$GIT_BUILD_DIR/t/chainlint.sed" | grep -q '?![A-Z][A-Z]*?!')
1002 }
Junio C Hamano99a64e42017-03-22 22:43:18 -07001003 then
SZEDER Gábor165293a2018-11-19 14:13:26 +01001004 BUG "broken &&-chain or run-away HERE-DOC: $1"
Jeff Kingbb79af92015-03-20 06:05:48 -04001005 fi
Jeff King2a01ef82015-08-06 01:31:47 -04001006 trace=$trace_tmp
Jeff Kingbb79af92015-03-20 06:05:48 -04001007 fi
1008
Thomas Rasta57397b2013-06-17 11:18:46 +02001009 setup_malloc_check
Jonathan Niedera7c58f22011-08-08 03:17:09 +02001010 test_eval_ "$1"
Jonathan Niederb6b0afd2010-05-06 03:41:10 -05001011 eval_ret=$?
Thomas Rasta57397b2013-06-17 11:18:46 +02001012 teardown_malloc_check
Junio C Hamanob5867442011-06-27 11:02:22 -07001013
Jeff Kinga136f6d2014-10-10 02:47:27 -04001014 if test -z "$immediate" || test $eval_ret = 0 ||
1015 test -n "$expecting_failure" && test "$test_cleanup" != ":"
Junio C Hamanob5867442011-06-27 11:02:22 -07001016 then
Junio C Hamano1b3185f2012-09-14 20:38:24 -07001017 setup_malloc_check
Jonathan Niedera7c58f22011-08-08 03:17:09 +02001018 test_eval_ "$test_cleanup"
Junio C Hamano1b3185f2012-09-14 20:38:24 -07001019 teardown_malloc_check
Junio C Hamanob5867442011-06-27 11:02:22 -07001020 fi
Ramsay Jones1c0cc752012-09-01 19:11:49 +01001021 if test "$verbose" = "t" && test -n "$HARNESS_ACTIVE"
1022 then
Ævar Arnfjörð Bjarmason57e15382010-06-24 17:44:47 +00001023 echo ""
1024 fi
Jonathan Niederaa0bcf92011-08-08 03:15:34 +02001025 return "$eval_ret"
Pavel Roskin4d9d62f2005-08-10 23:56:21 -04001026}
1027
Thomas Rastae753422013-06-18 14:25:59 +02001028test_start_ () {
Johannes Sixt8586f982009-02-05 21:20:56 +01001029 test_count=$(($test_count+1))
Thomas Rastff09af32013-06-23 20:12:56 +02001030 maybe_setup_verbose
Thomas Rast5dfc3682013-06-23 20:12:57 +02001031 maybe_setup_valgrind
Johannes Schindelin22231902019-01-29 06:19:27 -08001032 if test -n "$write_junit_xml"
1033 then
1034 junit_start=$(test-tool date getnanos)
1035 fi
Thomas Rastae753422013-06-18 14:25:59 +02001036}
1037
1038test_finish_ () {
1039 echo >&3 ""
Thomas Rast5dfc3682013-06-23 20:12:57 +02001040 maybe_teardown_valgrind
Thomas Rastff09af32013-06-23 20:12:56 +02001041 maybe_teardown_verbose
Johannes Schindelinaf9912e2019-01-29 06:19:34 -08001042 if test -n "$GIT_TEST_TEE_OFFSET"
1043 then
1044 GIT_TEST_TEE_OFFSET=$(test-tool path-utils file-size \
1045 "$GIT_TEST_TEE_OUTPUT_FILE")
1046 fi
Thomas Rastae753422013-06-18 14:25:59 +02001047}
1048
1049test_skip () {
Junio C Hamano04ece592006-12-28 17:58:00 -08001050 to_skip=
Ilya Bobyref2ac682014-04-30 02:50:43 -07001051 skipped_reason=
Jeff King560bf512021-06-16 06:23:07 -04001052 if match_pattern_list $this_test.$test_count "$GIT_SKIP_TESTS"
Thomas Raste6a6ddc2013-06-18 14:25:58 +02001053 then
1054 to_skip=t
Ilya Bobyref2ac682014-04-30 02:50:43 -07001055 skipped_reason="GIT_SKIP_TESTS"
Thomas Raste6a6ddc2013-06-18 14:25:58 +02001056 fi
SZEDER Gábore0316692019-11-12 13:24:38 +01001057 if test -z "$to_skip" && test -n "$run_list" &&
Elijah Newrenf21ac362020-10-18 00:23:45 +00001058 ! match_test_selector_list '--run' "$1" $test_count "$run_list"
SZEDER Gábore0316692019-11-12 13:24:38 +01001059 then
1060 to_skip=t
1061 skipped_reason="--run"
1062 fi
Jonathan Nieder05236a52010-10-17 02:36:58 +08001063 if test -z "$to_skip" && test -n "$test_prereq" &&
1064 ! test_have_prereq "$test_prereq"
Johannes Sixta7bb3942009-03-01 21:04:46 +01001065 then
1066 to_skip=t
Ilya Bobyref2ac682014-04-30 02:50:43 -07001067
Jonathan Nieder07431fc2010-08-24 02:34:10 -05001068 of_prereq=
Jonathan Nieder05236a52010-10-17 02:36:58 +08001069 if test "$missing_prereq" != "$test_prereq"
Jonathan Nieder07431fc2010-08-24 02:34:10 -05001070 then
Jonathan Nieder05236a52010-10-17 02:36:58 +08001071 of_prereq=" of $test_prereq"
Jonathan Nieder07431fc2010-08-24 02:34:10 -05001072 fi
Ilya Bobyref2ac682014-04-30 02:50:43 -07001073 skipped_reason="missing $missing_prereq${of_prereq}"
Fabian Stelzer49da4042021-11-20 16:03:59 +01001074
1075 # Keep a list of all the missing prereq for result aggregation
1076 if test -z "$missing_prereq"
1077 then
1078 test_missing_prereq=$missing_prereq
1079 else
1080 test_missing_prereq="$test_missing_prereq,$missing_prereq"
1081 fi
Ilya Bobyref2ac682014-04-30 02:50:43 -07001082 fi
Jonathan Nieder07431fc2010-08-24 02:34:10 -05001083
Ilya Bobyref2ac682014-04-30 02:50:43 -07001084 case "$to_skip" in
1085 t)
Johannes Schindelin22231902019-01-29 06:19:27 -08001086 if test -n "$write_junit_xml"
1087 then
1088 message="$(xml_attr_encode "$skipped_reason")"
1089 write_junit_xml_testcase "$1" \
1090 " <skipped message=\"$message\" />"
1091 fi
1092
Ilya Bobyref2ac682014-04-30 02:50:43 -07001093 say_color skip "ok $test_count # skip $1 ($skipped_reason)"
Junio C Hamano04ece592006-12-28 17:58:00 -08001094 : true
1095 ;;
1096 *)
1097 false
1098 ;;
1099 esac
1100}
1101
Thomas Rast342e9ef2012-02-17 11:25:09 +01001102# stub; perf-lib overrides it
1103test_at_end_hook_ () {
1104 :
1105}
1106
Johannes Schindelin22231902019-01-29 06:19:27 -08001107write_junit_xml () {
1108 case "$1" in
1109 --truncate)
1110 >"$junit_xml_path"
1111 junit_have_testcase=
1112 shift
1113 ;;
1114 esac
1115 printf '%s\n' "$@" >>"$junit_xml_path"
1116}
1117
1118xml_attr_encode () {
1119 printf '%s\n' "$@" | test-tool xml-encode
1120}
1121
1122write_junit_xml_testcase () {
1123 junit_attrs="name=\"$(xml_attr_encode "$this_test.$test_count $1")\""
1124 shift
1125 junit_attrs="$junit_attrs classname=\"$this_test\""
1126 junit_attrs="$junit_attrs time=\"$(test-tool \
1127 date getnanos $junit_start)\""
1128 write_junit_xml "$(printf '%s\n' \
1129 " <testcase $junit_attrs>" "$@" " </testcase>")"
1130 junit_have_testcase=t
1131}
1132
Johannes Schindelinab7d8542019-10-04 08:09:34 -07001133finalize_junit_xml () {
1134 if test -n "$write_junit_xml" && test -n "$junit_xml_path"
1135 then
1136 test -n "$junit_have_testcase" || {
1137 junit_start=$(test-tool date getnanos)
1138 write_junit_xml_testcase "all tests skipped"
1139 }
1140
1141 # adjust the overall time
1142 junit_time=$(test-tool date getnanos $junit_suite_start)
Johannes Schindelin076ee3e2020-02-12 11:27:55 +00001143 sed -e "s/\(<testsuite.*\) time=\"[^\"]*\"/\1/" \
1144 -e "s/<testsuite [^>]*/& time=\"$junit_time\"/" \
Johannes Schindelind3507cc2020-03-23 12:44:35 +00001145 -e '/^ *<\/testsuite/d' \
Johannes Schindelinab7d8542019-10-04 08:09:34 -07001146 <"$junit_xml_path" >"$junit_xml_path.new"
1147 mv "$junit_xml_path.new" "$junit_xml_path"
1148
1149 write_junit_xml " </testsuite>" "</testsuites>"
1150 write_junit_xml=
1151 fi
1152}
1153
Johannes Schindelin900721e2019-03-13 13:24:11 +01001154test_atexit_cleanup=:
1155test_atexit_handler () {
1156 # In a succeeding test script 'test_atexit_handler' is invoked
1157 # twice: first from 'test_done', then from 'die' in the trap on
1158 # EXIT.
1159 # This condition and resetting 'test_atexit_cleanup' below makes
1160 # sure that the registered cleanup commands are run only once.
1161 test : != "$test_atexit_cleanup" || return 0
1162
1163 setup_malloc_check
1164 test_eval_ "$test_atexit_cleanup"
1165 test_atexit_cleanup=:
1166 teardown_malloc_check
1167}
1168
Junio C Hamanoe1970ce2005-05-13 22:50:32 -07001169test_done () {
Clemens Buchacher6e7b5aa2009-06-01 14:14:41 +02001170 GIT_EXIT_OK=t
Sverre Rabbelier2d84e9f2008-06-08 16:04:33 +02001171
Johannes Schindelin900721e2019-03-13 13:24:11 +01001172 # Run the atexit commands _before_ the trash directory is
1173 # removed, so the commands can access pidfiles and socket files.
1174 test_atexit_handler
1175
Johannes Schindelinab7d8542019-10-04 08:09:34 -07001176 finalize_junit_xml
Johannes Schindelin22231902019-01-29 06:19:27 -08001177
Ramsay Jones1c0cc752012-09-01 19:11:49 +01001178 if test -z "$HARNESS_ACTIVE"
1179 then
SZEDER Gábor62c379b2019-01-05 02:08:56 +01001180 mkdir -p "$TEST_RESULTS_DIR"
Ævar Arnfjörð Bjarmason8ef1abe2010-08-11 19:37:31 +00001181
SZEDER Gábor62c379b2019-01-05 02:08:56 +01001182 cat >"$TEST_RESULTS_BASE.counts" <<-EOF
Mathias Lafeldtc54e6be2011-04-29 14:30:30 +02001183 total $test_count
1184 success $test_success
1185 fixed $test_fixed
1186 broken $test_broken
1187 failed $test_failure
Fabian Stelzer49da4042021-11-20 16:03:59 +01001188 missing_prereq $test_missing_prereq
Mathias Lafeldtc54e6be2011-04-29 14:30:30 +02001189
1190 EOF
Ævar Arnfjörð Bjarmason8ef1abe2010-08-11 19:37:31 +00001191 fi
Junio C Hamano41ac4142008-02-01 01:50:53 -08001192
1193 if test "$test_fixed" != 0
1194 then
Thomas Rast633fe502013-10-19 23:06:08 +02001195 say_color error "# $test_fixed known breakage(s) vanished; please update test(s)"
Junio C Hamano41ac4142008-02-01 01:50:53 -08001196 fi
1197 if test "$test_broken" != 0
1198 then
Thomas Rast633fe502013-10-19 23:06:08 +02001199 say_color warn "# still have $test_broken known breakage(s)"
Adam Spiersb73d9a22012-12-16 18:28:15 +00001200 fi
1201 if test "$test_broken" != 0 || test "$test_fixed" != 0
1202 then
1203 test_remaining=$(( $test_count - $test_broken - $test_fixed ))
1204 msg="remaining $test_remaining test(s)"
Junio C Hamano11d54b82008-02-03 00:23:02 -08001205 else
Adam Spiersb73d9a22012-12-16 18:28:15 +00001206 test_remaining=$test_count
Junio C Hamano11d54b82008-02-03 00:23:02 -08001207 msg="$test_count test(s)"
Junio C Hamano41ac4142008-02-01 01:50:53 -08001208 fi
Junio C Hamanoe1970ce2005-05-13 22:50:32 -07001209 case "$test_failure" in
Junio C Hamano10b94e22005-12-09 17:32:18 -08001210 0)
Ramsay Jones1c0cc752012-09-01 19:11:49 +01001211 if test $test_external_has_tap -eq 0
1212 then
Adam Spiersb73d9a22012-12-16 18:28:15 +00001213 if test $test_remaining -gt 0
Ramsay Jonesd87bd7c2012-09-01 19:26:21 +01001214 then
Thomas Rast633fe502013-10-19 23:06:08 +02001215 say_color pass "# passed all $msg"
Ramsay Jonesd87bd7c2012-09-01 19:26:21 +01001216 fi
Junio C Hamanoc7018be2017-05-18 11:52:20 +09001217
1218 # Maybe print SKIP message
1219 test -z "$skip_all" || skip_all="# SKIP $skip_all"
1220 case "$test_count" in
1221 0)
1222 say "1..$test_count${skip_all:+ $skip_all}"
1223 ;;
1224 *)
1225 test -z "$skip_all" ||
1226 say_color warn "$skip_all"
1227 say "1..$test_count"
1228 ;;
1229 esac
Ævar Arnfjörð Bjarmasond998bd42010-06-24 17:44:46 +00001230 fi
Johannes Schindelinabc5d372008-08-08 13:08:37 +02001231
Ævar Arnfjörð Bjarmasonedc23842021-05-10 16:19:00 +02001232 if test -z "$debug" && test -n "$remove_trash"
Junio C Hamano4d0912a2017-04-24 23:39:47 -07001233 then
Junio C Hamano06478da2017-04-23 17:15:09 -07001234 test -d "$TRASH_DIRECTORY" ||
Junio C Hamano4d0912a2017-04-24 23:39:47 -07001235 error "Tests passed but trash directory already removed before test cleanup; aborting"
Johannes Schindelinabc5d372008-08-08 13:08:37 +02001236
Junio C Hamano06478da2017-04-23 17:15:09 -07001237 cd "$TRASH_DIRECTORY/.." &&
Johannes Schindelin046e90d2019-01-29 06:19:35 -08001238 rm -fr "$TRASH_DIRECTORY" || {
1239 # try again in a bit
1240 sleep 5;
1241 rm -fr "$TRASH_DIRECTORY"
1242 } ||
Junio C Hamano4d0912a2017-04-24 23:39:47 -07001243 error "Tests passed but test cleanup failed; aborting"
Junio C Hamano4d0912a2017-04-24 23:39:47 -07001244 fi
Thomas Rast342e9ef2012-02-17 11:25:09 +01001245 test_at_end_hook_
1246
Junio C Hamanoe1970ce2005-05-13 22:50:32 -07001247 exit 0 ;;
1248
1249 *)
Ramsay Jones1c0cc752012-09-01 19:11:49 +01001250 if test $test_external_has_tap -eq 0
1251 then
Thomas Rast633fe502013-10-19 23:06:08 +02001252 say_color error "# failed $test_failure among $msg"
1253 say "1..$test_count"
Ævar Arnfjörð Bjarmasond998bd42010-06-24 17:44:46 +00001254 fi
Ævar Arnfjörð Bjarmason5099b992010-06-24 21:52:12 +00001255
Junio C Hamanoe1970ce2005-05-13 22:50:32 -07001256 exit 1 ;;
1257
1258 esac
1259}
1260
Matthew Ogilviee4597aa2009-12-02 22:14:06 -07001261if test -n "$valgrind"
Johannes Schindelin4e1be632009-02-04 00:25:59 +01001262then
Johannes Schindelin4e1be632009-02-04 00:25:59 +01001263 make_symlink () {
1264 test -h "$2" &&
1265 test "$1" = "$(readlink "$2")" || {
1266 # be super paranoid
1267 if mkdir "$2".lock
1268 then
1269 rm -f "$2" &&
1270 ln -s "$1" "$2" &&
1271 rm -r "$2".lock
1272 else
1273 while test -d "$2".lock
1274 do
1275 say "Waiting for lock on $2."
1276 sleep 1
1277 done
1278 fi
1279 }
1280 }
1281
1282 make_valgrind_symlink () {
Jeff King36bfb0e2011-06-17 16:36:32 -04001283 # handle only executables, unless they are shell libraries that
Jonathan Nieder11d62142013-11-25 13:03:52 -08001284 # need to be in the exec-path.
Jeff King36bfb0e2011-06-17 16:36:32 -04001285 test -x "$1" ||
Ævar Arnfjörð Bjarmason2a59a6e2018-08-24 15:20:11 +00001286 test "# " = "$(test_copy_bytes 2 <"$1")" ||
Jeff King36bfb0e2011-06-17 16:36:32 -04001287 return;
Johannes Schindelin4e1be632009-02-04 00:25:59 +01001288
1289 base=$(basename "$1")
René Scharfe28fab7b2016-10-28 00:14:00 +02001290 case "$base" in
1291 test-*)
1292 symlink_target="$GIT_BUILD_DIR/t/helper/$base"
1293 ;;
1294 *)
1295 symlink_target="$GIT_BUILD_DIR/$base"
1296 ;;
1297 esac
Johannes Schindelin4e1be632009-02-04 00:25:59 +01001298 # do not override scripts
1299 if test -x "$symlink_target" &&
1300 test ! -d "$symlink_target" &&
Ævar Arnfjörð Bjarmason2a59a6e2018-08-24 15:20:11 +00001301 test "#!" != "$(test_copy_bytes 2 <"$symlink_target")"
Johannes Schindelin4e1be632009-02-04 00:25:59 +01001302 then
1303 symlink_target=../valgrind.sh
1304 fi
Johannes Schindelinefd92ff2009-02-04 00:26:08 +01001305 case "$base" in
1306 *.sh|*.perl)
1307 symlink_target=../unprocessed-script
1308 esac
Johannes Schindelin4e1be632009-02-04 00:25:59 +01001309 # create the link, or replace it if it is out of date
1310 make_symlink "$symlink_target" "$GIT_VALGRIND/bin/$base" || exit
1311 }
1312
Thomas Rast26a07302013-10-19 23:06:07 +02001313 # override all git executables in TEST_DIRECTORY/..
1314 GIT_VALGRIND=$TEST_DIRECTORY/valgrind
1315 mkdir -p "$GIT_VALGRIND"/bin
Johannes Schindelin503e2242016-07-11 13:45:08 +02001316 for file in $GIT_BUILD_DIR/git* $GIT_BUILD_DIR/t/helper/test-*
Thomas Rast26a07302013-10-19 23:06:07 +02001317 do
1318 make_valgrind_symlink $file
1319 done
1320 # special-case the mergetools loadables
1321 make_symlink "$GIT_BUILD_DIR"/mergetools "$GIT_VALGRIND/bin/mergetools"
1322 OLDIFS=$IFS
1323 IFS=:
1324 for path in $PATH
1325 do
1326 ls "$path"/git-* 2> /dev/null |
1327 while read file
Johannes Schindelinefd92ff2009-02-04 00:26:08 +01001328 do
Thomas Rast26a07302013-10-19 23:06:07 +02001329 make_valgrind_symlink "$file"
Johannes Schindelinefd92ff2009-02-04 00:26:08 +01001330 done
Thomas Rast26a07302013-10-19 23:06:07 +02001331 done
1332 IFS=$OLDIFS
Johannes Schindelin4e1be632009-02-04 00:25:59 +01001333 PATH=$GIT_VALGRIND/bin:$PATH
1334 GIT_EXEC_PATH=$GIT_VALGRIND/bin
1335 export GIT_VALGRIND
Thomas Rast952af352013-03-31 10:00:16 +02001336 GIT_VALGRIND_MODE="$valgrind"
1337 export GIT_VALGRIND_MODE
Thomas Rast5dfc3682013-06-23 20:12:57 +02001338 GIT_VALGRIND_ENABLED=t
Thomas Rast26a07302013-10-19 23:06:07 +02001339 test -n "$valgrind_only" && GIT_VALGRIND_ENABLED=
Thomas Rast5dfc3682013-06-23 20:12:57 +02001340 export GIT_VALGRIND_ENABLED
Ramsay Jones1c0cc752012-09-01 19:11:49 +01001341elif test -n "$GIT_TEST_INSTALLED"
1342then
Matthew Ogilviee4597aa2009-12-02 22:14:06 -07001343 GIT_EXEC_PATH=$($GIT_TEST_INSTALLED/git --exec-path) ||
1344 error "Cannot run git from $GIT_TEST_INSTALLED."
Johannes Schindelin16df35c2018-11-12 05:48:33 -08001345 PATH=$GIT_TEST_INSTALLED:$GIT_BUILD_DIR/t/helper:$PATH
Matthew Ogilviee4597aa2009-12-02 22:14:06 -07001346 GIT_EXEC_PATH=${GIT_TEST_EXEC_PATH:-$GIT_EXEC_PATH}
1347else # normal case, use ../bin-wrappers only unless $with_dashes:
Johannes Schindelindd167a32019-01-29 06:19:37 -08001348 if test -n "$no_bin_wrappers"
Ramsay Jones1c0cc752012-09-01 19:11:49 +01001349 then
Matthew Ogilviee4597aa2009-12-02 22:14:06 -07001350 with_dashes=t
Johannes Schindelindd167a32019-01-29 06:19:37 -08001351 else
1352 git_bin_dir="$GIT_BUILD_DIR/bin-wrappers"
1353 if ! test -x "$git_bin_dir/git"
1354 then
1355 if test -z "$with_dashes"
1356 then
1357 say "$git_bin_dir/git is not executable; using GIT_EXEC_PATH"
1358 fi
1359 with_dashes=t
1360 fi
1361 PATH="$git_bin_dir:$PATH"
Matthew Ogilviee4597aa2009-12-02 22:14:06 -07001362 fi
Ævar Arnfjörð Bjarmason6cec5c62010-08-19 16:08:10 +00001363 GIT_EXEC_PATH=$GIT_BUILD_DIR
Ramsay Jones1c0cc752012-09-01 19:11:49 +01001364 if test -n "$with_dashes"
1365 then
Johannes Schindelinca7312d2019-01-29 06:19:35 -08001366 PATH="$GIT_BUILD_DIR:$GIT_BUILD_DIR/t/helper:$PATH"
Matthew Ogilviee4597aa2009-12-02 22:14:06 -07001367 fi
Johannes Schindelin4e1be632009-02-04 00:25:59 +01001368fi
Ævar Arnfjörð Bjarmason6cec5c62010-08-19 16:08:10 +00001369GIT_TEMPLATE_DIR="$GIT_BUILD_DIR"/templates/blt
Jeff King8bfa6bd2008-02-06 05:11:53 -05001370GIT_CONFIG_NOSYSTEM=1
Jonathan Nieder3c995be2011-03-15 04:05:10 -05001371GIT_ATTR_NOSYSTEM=1
SZEDER Gábor614c3d82021-08-29 11:25:36 +02001372GIT_CEILING_DIRECTORIES="$TRASH_DIRECTORY/.."
1373export PATH GIT_EXEC_PATH GIT_TEMPLATE_DIR GIT_CONFIG_NOSYSTEM GIT_ATTR_NOSYSTEM GIT_CEILING_DIRECTORIES
Junio C Hamano49ccb082005-12-07 21:52:28 -08001374
Junio C Hamano5e87eae2010-06-11 09:40:25 -07001375if test -z "$GIT_TEST_CMP"
1376then
1377 if test -n "$GIT_TEST_CMP_USE_COPIED_CONTEXT"
1378 then
1379 GIT_TEST_CMP="$DIFF -c"
1380 else
1381 GIT_TEST_CMP="$DIFF -u"
1382 fi
1383fi
1384
Ævar Arnfjörð Bjarmason20d2a302017-12-10 21:13:33 +00001385GITPERLLIB="$GIT_BUILD_DIR"/perl/build/lib
Petr Baudis6fcca932006-07-03 23:16:32 +02001386export GITPERLLIB
Ævar Arnfjörð Bjarmason6cec5c62010-08-19 16:08:10 +00001387test -d "$GIT_BUILD_DIR"/templates/blt || {
Junio C Hamanoeea42062005-12-10 20:55:32 -08001388 error "You haven't built things yet, have you?"
1389}
Junio C Hamanoe1970ce2005-05-13 22:50:32 -07001390
Johannes Schindelind6096152019-01-21 07:12:19 -08001391if ! test -x "$GIT_BUILD_DIR"/t/helper/test-tool$X
Ramsay Jones1c0cc752012-09-01 19:11:49 +01001392then
Nguyễn Thái Ngọc Duy0e496492018-03-24 08:44:31 +01001393 echo >&2 'You need to build test-tool:'
1394 echo >&2 'Run "make t/helper/test-tool" in the source (toplevel) directory'
Eric Wong56cf9802007-02-24 16:59:52 -08001395 exit 1
1396fi
1397
Ævar Arnfjörð Bjarmasonedc23842021-05-10 16:19:00 +02001398# Are we running this test at all?
1399remove_trash=
Johannes Sixtd5d9de12009-02-05 20:59:27 +01001400this_test=${0##*/}
1401this_test=${this_test%%-*}
Jeff King560bf512021-06-16 06:23:07 -04001402if match_pattern_list "$this_test" "$GIT_SKIP_TESTS"
Thomas Raste6a6ddc2013-06-18 14:25:58 +02001403then
1404 say_color info >&3 "skipping test $this_test altogether"
1405 skip_all="skip all tests in $this_test"
1406 test_done
1407fi
Johannes Sixtf17e9fb2009-03-11 21:17:26 +01001408
Ævar Arnfjörð Bjarmason956d2e42021-09-23 11:20:46 +02001409# skip non-whitelisted tests when compiled with SANITIZE=leak
1410if test -n "$SANITIZE_LEAK"
1411then
1412 if test_bool_env GIT_TEST_PASSING_SANITIZE_LEAK false
1413 then
1414 # We need to see it in "git env--helper" (via
1415 # test_bool_env)
1416 export TEST_PASSES_SANITIZE_LEAK
1417
1418 if ! test_bool_env TEST_PASSES_SANITIZE_LEAK false
1419 then
1420 skip_all="skipping $this_test under GIT_TEST_PASSING_SANITIZE_LEAK=true"
1421 test_done
1422 fi
1423 fi
1424elif test_bool_env GIT_TEST_PASSING_SANITIZE_LEAK false
1425then
Ævar Arnfjörð Bjarmason234383c2021-10-14 02:47:29 +02001426 BAIL_OUT "GIT_TEST_PASSING_SANITIZE_LEAK=true has no effect except when compiled with SANITIZE=leak"
Ævar Arnfjörð Bjarmason956d2e42021-09-23 11:20:46 +02001427fi
1428
Ævar Arnfjörð Bjarmasonedc23842021-05-10 16:19:00 +02001429# Last-minute variable setup
Philippe Blainadd52402021-09-06 04:38:59 +00001430USER_HOME="$HOME"
Ævar Arnfjörð Bjarmasonedc23842021-05-10 16:19:00 +02001431HOME="$TRASH_DIRECTORY"
1432GNUPGHOME="$HOME/gnupg-home-not-used"
Philippe Blainadd52402021-09-06 04:38:59 +00001433export HOME GNUPGHOME USER_HOME
Ævar Arnfjörð Bjarmasonedc23842021-05-10 16:19:00 +02001434
Ævar Arnfjörð Bjarmason5d22e182021-10-11 03:41:59 +02001435# "rm -rf" existing trash directory, even if a previous run left it
1436# with bad permissions.
1437remove_trash_directory () {
1438 dir="$1"
1439 if ! rm -rf "$dir" 2>/dev/null
1440 then
1441 chmod -R u+rwx "$dir"
1442 rm -rf "$dir"
1443 fi
1444 ! test -d "$dir"
1445}
1446
Johannes Sixtee9fb682009-03-13 22:55:27 +01001447# Test repository
Ævar Arnfjörð Bjarmason5d22e182021-10-11 03:41:59 +02001448remove_trash_directory "$TRASH_DIRECTORY" || {
Johannes Sixtf17e9fb2009-03-11 21:17:26 +01001449 GIT_EXIT_OK=t
Johannes Sixt704a3142009-03-04 22:38:24 +01001450 echo >&5 "FATAL: Cannot prepare test area"
1451 exit 1
Johannes Sixt6fd11062009-03-13 23:00:15 +01001452}
Johannes Sixtfb9a2be2009-03-25 13:21:15 +01001453
Ævar Arnfjörð Bjarmasonedc23842021-05-10 16:19:00 +02001454remove_trash=t
Johannes Sixt704a3142009-03-04 22:38:24 +01001455if test -z "$TEST_NO_CREATE_REPO"
Zbigniew Jędrzejewski-Szmekb0826872012-04-27 11:25:25 +02001456then
Ævar Arnfjörð Bjarmasonf0d4d392021-05-10 16:19:10 +02001457 git init "$TRASH_DIRECTORY" >&3 2>&4 ||
1458 error "cannot run git init"
Johan Herlandd4e1b472009-11-18 02:42:31 +01001459else
Michał Kiedrowicz8f852ce2011-05-09 23:52:07 +02001460 mkdir -p "$TRASH_DIRECTORY"
Ævar Arnfjörð Bjarmason5e9637c2011-11-18 00:14:42 +01001461fi
Jeff King1b19ccd2009-04-03 15:33:59 -04001462
Ævar Arnfjörð Bjarmasonbb946bb2011-02-22 23:41:21 +00001463# Use -P to resolve symlinks in our working directory so that the cwd
Jonathan Nieder30955222011-02-22 23:41:22 +00001464# in subprocesses like git equals our $PWD (for pathname comparisons).
1465cd -P "$TRASH_DIRECTORY" || exit 1
1466
Johannes Schindelin22231902019-01-29 06:19:27 -08001467if test -n "$write_junit_xml"
1468then
1469 junit_xml_dir="$TEST_OUTPUT_DIRECTORY/out"
1470 mkdir -p "$junit_xml_dir"
1471 junit_xml_base=${0##*/}
1472 junit_xml_path="$junit_xml_dir/TEST-${junit_xml_base%.sh}.xml"
1473 junit_attrs="name=\"${junit_xml_base%.sh}\""
1474 junit_attrs="$junit_attrs timestamp=\"$(TZ=UTC \
1475 date +%Y-%m-%dT%H:%M:%S)\""
1476 write_junit_xml --truncate "<testsuites>" " <testsuite $junit_attrs>"
1477 junit_suite_start=$(test-tool date getnanos)
Johannes Schindelinaf9912e2019-01-29 06:19:34 -08001478 if test -n "$GIT_TEST_TEE_OUTPUT_FILE"
1479 then
1480 GIT_TEST_TEE_OFFSET=0
1481 fi
Johannes Schindelin22231902019-01-29 06:19:27 -08001482fi
1483
brian m. carlson192b5172020-02-22 20:17:31 +00001484# Convenience
Ævar Arnfjörð Bjarmason70507912021-09-11 13:17:51 +02001485# A regexp to match 5 and 35 hexdigits
brian m. carlson192b5172020-02-22 20:17:31 +00001486_x05='[0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f]'
1487_x35="$_x05$_x05$_x05$_x05$_x05$_x05$_x05"
brian m. carlson192b5172020-02-22 20:17:31 +00001488
1489test_oid_init
1490
1491ZERO_OID=$(test_oid zero)
1492OID_REGEX=$(echo $ZERO_OID | sed -e 's/0/[0-9a-f]/g')
brian m. carlsona1142962020-05-13 00:53:41 +00001493OIDPATH_REGEX=$(test_oid_to_path $ZERO_OID | sed -e 's/0/[0-9a-f]/g')
brian m. carlson192b5172020-02-22 20:17:31 +00001494EMPTY_TREE=$(test_oid empty_tree)
1495EMPTY_BLOB=$(test_oid empty_blob)
brian m. carlson192b5172020-02-22 20:17:31 +00001496
Junio C Hamano11f470a2019-02-09 10:25:26 -08001497# Provide an implementation of the 'yes' utility; the upper bound
1498# limit is there to help Windows that cannot stop this loop from
1499# wasting cycles when the downstream stops reading, so do not be
1500# tempted to turn it into an infinite loop. cf. 6129c930 ("test-lib:
1501# limit the output of the yes utility", 2016-02-02)
Junio C Hamanoe1970ce2005-05-13 22:50:32 -07001502yes () {
1503 if test $# = 0
1504 then
1505 y=y
1506 else
1507 y="$*"
1508 fi
1509
Johannes Schindelin6129c932016-02-02 19:15:53 +01001510 i=0
1511 while test $i -lt 99
Junio C Hamanoe1970ce2005-05-13 22:50:32 -07001512 do
Johannes Schindelin6129c932016-02-02 19:15:53 +01001513 echo "$y"
1514 i=$(($i+1))
Junio C Hamanoe1970ce2005-05-13 22:50:32 -07001515 done
1516}
1517
Ævar Arnfjörð Bjarmasonc7400392019-06-21 12:18:12 +02001518# The GIT_TEST_FAIL_PREREQS code hooks into test_set_prereq(), and
1519# thus needs to be set up really early, and set an internal variable
1520# for convenience so the hot test_set_prereq() codepath doesn't need
SZEDER Gábor43a2afe2019-11-22 14:14:36 +01001521# to call "git env--helper" (via test_bool_env). Only do that work
1522# if needed by seeing if GIT_TEST_FAIL_PREREQS is set at all.
Ævar Arnfjörð Bjarmasonc7400392019-06-21 12:18:12 +02001523GIT_TEST_FAIL_PREREQS_INTERNAL=
1524if test -n "$GIT_TEST_FAIL_PREREQS"
1525then
SZEDER Gábor43a2afe2019-11-22 14:14:36 +01001526 if test_bool_env GIT_TEST_FAIL_PREREQS false
Ævar Arnfjörð Bjarmasonc7400392019-06-21 12:18:12 +02001527 then
1528 GIT_TEST_FAIL_PREREQS_INTERNAL=true
1529 test_set_prereq FAIL_PREREQS
1530 fi
1531else
1532 test_lazy_prereq FAIL_PREREQS '
SZEDER Gábor43a2afe2019-11-22 14:14:36 +01001533 test_bool_env GIT_TEST_FAIL_PREREQS false
Ævar Arnfjörð Bjarmasonc7400392019-06-21 12:18:12 +02001534 '
1535fi
1536
Ed Maste7187c7b2019-11-27 17:15:07 +00001537# Fix some commands on Windows, and other OS-specific things
Johannes Schindelind98b2c52016-07-21 18:02:54 +02001538uname_s=$(uname -s)
1539case $uname_s in
Junio C Hamanoe1970ce2005-05-13 22:50:32 -07001540*MINGW*)
1541 # Windows has its own (incompatible) sort and find
1542 sort () {
1543 /usr/bin/sort "$@"
1544 }
1545 find () {
1546 /usr/bin/find "$@"
1547 }
Junio C Hamanoe1970ce2005-05-13 22:50:32 -07001548 # git sees Windows-style pwd
1549 pwd () {
Johannes Sixt704a3142009-03-04 22:38:24 +01001550 builtin pwd -W
1551 }
1552 # no POSIX permissions
1553 # backslashes in pathspec are converted to '/'
Junio C Hamanoe1970ce2005-05-13 22:50:32 -07001554 # exec does not inherit the PID
1555 test_set_prereq MINGW
Brice Lambson5f4e02e2014-08-30 23:39:07 +02001556 test_set_prereq NATIVE_CRLF
Junio C Hamanoe1970ce2005-05-13 22:50:32 -07001557 test_set_prereq SED_STRIPS_CR
Mark Levedahl97669ee2013-07-18 17:44:57 -04001558 test_set_prereq GREP_STRIPS_CR
Adam Dinwoodiebccc37f2021-04-29 21:11:44 +01001559 test_set_prereq WINDOWS
Johannes Sixt4d715ac2013-10-26 21:17:15 +02001560 GIT_TEST_CMP=mingw_test_cmp
Junio C Hamanoe1970ce2005-05-13 22:50:32 -07001561 ;;
1562*CYGWIN*)
1563 test_set_prereq POSIXPERM
1564 test_set_prereq EXECKEEPSPID
1565 test_set_prereq CYGWIN
1566 test_set_prereq SED_STRIPS_CR
Mark Levedahl97669ee2013-07-18 17:44:57 -04001567 test_set_prereq GREP_STRIPS_CR
Adam Dinwoodiebccc37f2021-04-29 21:11:44 +01001568 test_set_prereq WINDOWS
Junio C Hamanoe1970ce2005-05-13 22:50:32 -07001569 ;;
1570*)
1571 test_set_prereq POSIXPERM
1572 test_set_prereq BSLASHPSPEC
1573 test_set_prereq EXECKEEPSPID
Junio C Hamanoe1970ce2005-05-13 22:50:32 -07001574 ;;
1575esac
1576
Greg Priceddcfc7c2020-05-15 22:33:38 -07001577# Detect arches where a few things don't work
1578uname_m=$(uname -m)
1579case $uname_m in
1580parisc* | hppa*)
1581 test_set_prereq HPPA
1582 ;;
1583esac
1584
Han-Wen Nienhuysc305e662021-05-31 16:56:29 +00001585test_set_prereq REFFILES
1586
Junio C Hamanoe1970ce2005-05-13 22:50:32 -07001587( COLUMNS=1 && test $COLUMNS = 1 ) && test_set_prereq COLUMNS_CAN_BE_1
1588test -z "$NO_PERL" && test_set_prereq PERL
Ævar Arnfjörð Bjarmason68c7d272017-05-25 19:45:31 +00001589test -z "$NO_PTHREADS" && test_set_prereq PTHREADS
Junio C Hamanoe1970ce2005-05-13 22:50:32 -07001590test -z "$NO_PYTHON" && test_set_prereq PYTHON
Ævar Arnfjörð Bjarmason75997302021-01-24 02:58:33 +01001591test -n "$USE_LIBPCRE2" && test_set_prereq PCRE
Ævar Arnfjörð Bjarmasonce9a2572017-11-23 14:16:57 +00001592test -n "$USE_LIBPCRE2" && test_set_prereq LIBPCRE2
Junio C Hamanoe1970ce2005-05-13 22:50:32 -07001593test -z "$NO_GETTEXT" && test_set_prereq GETTEXT
Ævar Arnfjörð Bjarmason2cdc2922021-09-23 11:20:45 +02001594test -n "$SANITIZE_LEAK" && test_set_prereq SANITIZE_LEAK
Junio C Hamanoe1970ce2005-05-13 22:50:32 -07001595
Nguyễn Thái Ngọc Duy4592e602018-08-18 16:41:28 +02001596if test -z "$GIT_TEST_CHECK_CACHE_TREE"
1597then
1598 GIT_TEST_CHECK_CACHE_TREE=true
1599 export GIT_TEST_CHECK_CACHE_TREE
1600fi
1601
Adam Spiers20073272013-04-11 03:07:04 +01001602test_lazy_prereq PIPE '
1603 # test whether the filesystem supports FIFOs
Ramsay Jones7b7bea22017-09-17 23:56:00 +01001604 test_have_prereq !MINGW,!CYGWIN &&
1605 rm -f testfifo && mkfifo testfifo
Adam Spiers20073272013-04-11 03:07:04 +01001606'
1607
Junio C Hamano04083f22012-07-26 15:50:45 -07001608test_lazy_prereq SYMLINKS '
1609 # test whether the filesystem supports symbolic links
1610 ln -s x y && test -h y
1611'
Ævar Arnfjörð Bjarmasonc91cfd12010-08-06 22:09:09 +00001612
Thomas Bétous3e7d4882021-08-02 21:07:30 +00001613test_lazy_prereq SYMLINKS_WINDOWS '
1614 # test whether symbolic links are enabled on Windows
1615 test_have_prereq MINGW &&
1616 cmd //c "mklink y x" &> /dev/null && test -h y
1617'
1618
Jonathan Niederb018c732013-11-25 13:02:16 -08001619test_lazy_prereq FILEMODE '
1620 test "$(git config --bool core.filemode)" = true
1621'
1622
Michael J Gruberac39aa62012-07-26 15:39:53 +02001623test_lazy_prereq CASE_INSENSITIVE_FS '
1624 echo good >CamelCase &&
1625 echo bad >camelcase &&
1626 test "$(cat CamelCase)" != good
1627'
1628
William Chargin6ec63302018-08-06 11:35:08 -07001629test_lazy_prereq FUNNYNAMES '
1630 test_have_prereq !MINGW &&
1631 touch -- \
1632 "FUNNYNAMES tab embedded" \
1633 "FUNNYNAMES \"quote embedded\"" \
1634 "FUNNYNAMES newline
1635embedded" 2>/dev/null &&
1636 rm -- \
1637 "FUNNYNAMES tab embedded" \
1638 "FUNNYNAMES \"quote embedded\"" \
1639 "FUNNYNAMES newline
1640embedded" 2>/dev/null
1641'
1642
Michael J Gruber5b0b5dd2012-07-26 15:39:56 +02001643test_lazy_prereq UTF8_NFD_TO_NFC '
1644 # check whether FS converts nfd unicode to nfc
1645 auml=$(printf "\303\244")
1646 aumlcdiar=$(printf "\141\314\210")
1647 >"$auml" &&
Torsten Bögershausen742ae102018-04-30 08:35:19 +02001648 test -f "$aumlcdiar"
Michael J Gruber5b0b5dd2012-07-26 15:39:56 +02001649'
1650
Jeff King09feffb2012-11-14 16:33:40 -08001651test_lazy_prereq AUTOIDENT '
1652 sane_unset GIT_AUTHOR_NAME &&
1653 sane_unset GIT_AUTHOR_EMAIL &&
1654 git var GIT_AUTHOR_IDENT
1655'
1656
Junio C Hamano6219bb22014-06-09 12:23:30 -07001657test_lazy_prereq EXPENSIVE '
1658 test -n "$GIT_TEST_LONG"
1659'
1660
Ævar Arnfjörð Bjarmason5b1fe6e2018-01-30 21:21:23 +00001661test_lazy_prereq EXPENSIVE_ON_WINDOWS '
1662 test_have_prereq EXPENSIVE || test_have_prereq !MINGW,!CYGWIN
1663'
1664
Junio C Hamanoe1ecd9e2014-06-09 13:54:25 -07001665test_lazy_prereq USR_BIN_TIME '
1666 test -x /usr/bin/time
1667'
1668
Jeff King1767c512015-01-16 04:16:49 -05001669test_lazy_prereq NOT_ROOT '
1670 uid=$(id -u) &&
1671 test "$uid" != 0
1672'
1673
Jonathan Tan63b747c2016-09-09 10:36:28 -07001674test_lazy_prereq JGIT '
Todd Zullingerabd0f282019-05-14 21:36:33 -04001675 jgit --version
Jonathan Tan63b747c2016-09-09 10:36:28 -07001676'
1677
Junio C Hamano719c3da2016-01-19 14:09:37 -08001678# SANITY is about "can you correctly predict what the filesystem would
1679# do by only looking at the permission bits of the files and
1680# directories?" A typical example of !SANITY is running the test
1681# suite as root, where a test may expect "chmod -r file && cat file"
1682# to fail because file is supposed to be unreadable after a successful
1683# chmod. In an environment (i.e. combination of what filesystem is
1684# being used and who is running the tests) that lacks SANITY, you may
1685# be able to delete or create a file when the containing directory
1686# doesn't have write permissions, or access a file even if the
1687# containing directory doesn't have read or execute permissions.
1688
Torsten Bögershausenf400e512015-01-27 16:39:01 +01001689test_lazy_prereq SANITY '
1690 mkdir SANETESTD.1 SANETESTD.2 &&
1691
1692 chmod +w SANETESTD.1 SANETESTD.2 &&
1693 >SANETESTD.1/x 2>SANETESTD.2/x &&
1694 chmod -w SANETESTD.1 &&
Junio C Hamano719c3da2016-01-19 14:09:37 -08001695 chmod -r SANETESTD.1/x &&
Torsten Bögershausenf400e512015-01-27 16:39:01 +01001696 chmod -rx SANETESTD.2 ||
SZEDER Gábor165293a2018-11-19 14:13:26 +01001697 BUG "cannot prepare SANETESTD"
Torsten Bögershausenf400e512015-01-27 16:39:01 +01001698
Junio C Hamano719c3da2016-01-19 14:09:37 -08001699 ! test -r SANETESTD.1/x &&
Torsten Bögershausenf400e512015-01-27 16:39:01 +01001700 ! rm SANETESTD.1/x && ! test -f SANETESTD.2/x
1701 status=$?
1702
1703 chmod +rwx SANETESTD.1 SANETESTD.2 &&
1704 rm -rf SANETESTD.1 SANETESTD.2 ||
SZEDER Gábor165293a2018-11-19 14:13:26 +01001705 BUG "cannot clean SANETESTD"
Torsten Bögershausenf400e512015-01-27 16:39:01 +01001706 return $status
1707'
Jeff Kingf838ce52013-03-10 21:31:47 -04001708
Johannes Schindelind98b2c52016-07-21 18:02:54 +02001709test FreeBSD != $uname_s || GIT_UNZIP=${GIT_UNZIP:-/usr/local/bin/unzip}
Jeff Kingf838ce52013-03-10 21:31:47 -04001710GIT_UNZIP=${GIT_UNZIP:-unzip}
1711test_lazy_prereq UNZIP '
1712 "$GIT_UNZIP" -v
1713 test $? -ne 127
1714'
Jeff King9a308de2015-03-13 00:53:07 -04001715
1716run_with_limited_cmdline () {
1717 (ulimit -s 128 && "$@")
1718}
1719
Ramsay Jones21dac1d2017-09-14 18:24:41 +01001720test_lazy_prereq CMDLINE_LIMIT '
Greg Priceddcfc7c2020-05-15 22:33:38 -07001721 test_have_prereq !HPPA,!MINGW,!CYGWIN &&
Ramsay Jones21dac1d2017-09-14 18:24:41 +01001722 run_with_limited_cmdline true
1723'
Jeff King6b9c38e2016-07-11 19:54:18 -04001724
Michael J Gruber4db464f2017-09-07 16:02:20 +02001725run_with_limited_stack () {
1726 (ulimit -s 128 && "$@")
1727}
1728
Ramsay Jones21dac1d2017-09-14 18:24:41 +01001729test_lazy_prereq ULIMIT_STACK_SIZE '
Greg Priceddcfc7c2020-05-15 22:33:38 -07001730 test_have_prereq !HPPA,!MINGW,!CYGWIN &&
Ramsay Jones21dac1d2017-09-14 18:24:41 +01001731 run_with_limited_stack true
1732'
Michael J Gruber4db464f2017-09-07 16:02:20 +02001733
Taylor Blaub30fdb42020-04-23 15:41:06 -06001734run_with_limited_open_files () {
1735 (ulimit -n 32 && "$@")
1736}
1737
1738test_lazy_prereq ULIMIT_FILE_DESCRIPTORS '
1739 test_have_prereq !MINGW,!CYGWIN &&
1740 run_with_limited_open_files true
1741'
1742
Jeff King6b9c38e2016-07-11 19:54:18 -04001743build_option () {
1744 git version --build-options |
1745 sed -ne "s/^$1: //p"
1746}
1747
1748test_lazy_prereq LONG_IS_64BIT '
1749 test 8 -le "$(build_option sizeof-long)"
1750'
Johannes Schindelina07fb052017-04-20 22:52:13 +02001751
Nguyễn Thái Ngọc Duya801a7c2018-03-24 08:44:36 +01001752test_lazy_prereq TIME_IS_64BIT 'test-tool date is64bit'
1753test_lazy_prereq TIME_T_IS_64BIT 'test-tool date time_t-is64bit'
Jeff Kinge9184b02018-04-03 10:01:57 -04001754
1755test_lazy_prereq CURL '
1756 curl --version
1757'
brian m. carlsond16ab632018-05-13 02:24:11 +00001758
1759# SHA1 is a test if the hash algorithm in use is SHA-1. This is both for tests
1760# which will not work with other hash algorithms and tests that work but don't
1761# test anything meaningful (e.g. special values which cause short collisions).
1762test_lazy_prereq SHA1 '
brian m. carlsonc49fe072020-07-29 23:14:25 +00001763 case "$GIT_DEFAULT_HASH" in
1764 sha1) true ;;
1765 "") test $(git hash-object /dev/null) = e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 ;;
1766 *) false ;;
1767 esac
brian m. carlsond16ab632018-05-13 02:24:11 +00001768'
Johannes Schindelin11aad462018-10-31 13:02:02 -07001769
Derrick Stolee2fec6042020-09-11 17:49:18 +00001770# Ensure that no test accidentally triggers a Git command
Derrick Stolee31345d52020-11-24 04:16:42 +00001771# that runs the actual maintenance scheduler, affecting a user's
1772# system permanently.
1773# Tests that verify the scheduler integration must set this locally
Derrick Stolee2fec6042020-09-11 17:49:18 +00001774# to avoid errors.
Derrick Stolee31345d52020-11-24 04:16:42 +00001775GIT_TEST_MAINT_SCHEDULER="none:exit 1"