Raw
1 # Test framework for git. See t/README for usage.
2 #
3 # Copyright (c) 2005 Junio C Hamano
4 #
5 # 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 https://www.gnu.org/licenses/ .
17
18 # Enable the use of errexit so that any unexpected failures will cause us to
19 # abort tests, even when outside of a specific test case.
20 #
21 # Note that we only enable this on Bash 5 and newer, or when explicitly
22 # requested by the user via `GIT_TEST_USE_SET_E=true`. This ib secause `set -e`
23 # has wildly different behaviour across shells. The list of default-enabled
24 # shells may be extended going forward.
25 if test -z "$GIT_TEST_USE_SET_E" && test "${BASH_VERSINFO:=0}" -ge 5
26 then
27 GIT_TEST_USE_SET_E=true
28 fi
29
30 # We cannot use `test-tool env-helper` here, as it's not yet available.
31 case "${GIT_TEST_USE_SET_E:-false}" in
32 1|on|true|yes)
33 set -e
34 ;;
35 0|off|false|no)
36 ;;
37 *)
38 echo "GIT_TEST_USE_SET_E requires a boolean" >&2
39 exit 1
40 ;;
41 esac
42
43 # Test the binaries we have just built. The tests are kept in
44 # t/ subdirectory and are run in 'trash directory' subdirectory.
45 if test -z "$TEST_DIRECTORY"
46 then
47 # ensure that TEST_DIRECTORY is an absolute path so that it
48 # is valid even if the current working directory is changed
49 TEST_DIRECTORY=$(pwd)
50 else
51 # The TEST_DIRECTORY will always be the path to the "t"
52 # directory in the git.git checkout. This is overridden by
53 # e.g. t/lib-subtest.sh, but only because its $(pwd) is
54 # different. Those tests still set "$TEST_DIRECTORY" to the
55 # same path.
56 #
57 # See use of "$GIT_BUILD_DIR" and "$TEST_DIRECTORY" below for
58 # hard assumptions about "$GIT_BUILD_DIR/t" existing and being
59 # the "$TEST_DIRECTORY", and e.g. "$TEST_DIRECTORY/helper"
60 # needing to exist.
61 TEST_DIRECTORY=$(cd "$TEST_DIRECTORY" && pwd) || exit 1
62 fi
63 GIT_BUILD_DIR="${GIT_BUILD_DIR:-${TEST_DIRECTORY%/t}}"
64 if test "$TEST_DIRECTORY" = "$GIT_BUILD_DIR"
65 then
66 echo "PANIC: Running in a $TEST_DIRECTORY that doesn't end in '/t'?" >&2
67 exit 1
68 fi
69 if test -f "$GIT_BUILD_DIR/GIT-BUILD-DIR"
70 then
71 GIT_BUILD_DIR="$(cat "$GIT_BUILD_DIR/GIT-BUILD-DIR")" || exit 1
72 # On Windows, we must convert Windows paths lest they contain a colon
73 case "$(uname -s)" in
74 *MINGW*)
75 GIT_BUILD_DIR="$(cygpath -au "$GIT_BUILD_DIR")"
76 ;;
77 esac
78 fi
79
80 # Prepend a string to a VAR using an arbitrary ":" delimiter, not
81 # adding the delimiter if VAR or VALUE is empty. I.e. a generalized:
82 #
83 # VAR=$1${VAR:+${1:+$2}$VAR}
84 #
85 # Usage (using ":" as the $2 delimiter):
86 #
87 # prepend_var VAR : VALUE
88 prepend_var () {
89 eval "$1=\"$3\${$1:+${3:+$2}\$$1}\""
90 }
91
92 # If [AL]SAN is in effect we want to abort so that we notice
93 # problems. The GIT_SAN_OPTIONS variable can be used to set common
94 # defaults shared between [AL]SAN_OPTIONS.
95 prepend_var GIT_SAN_OPTIONS : abort_on_error=1
96 prepend_var GIT_SAN_OPTIONS : strip_path_prefix="$GIT_BUILD_DIR/"
97
98 # If we were built with ASAN, it may complain about leaks
99 # of program-lifetime variables. Disable it by default to lower
100 # the noise level. This needs to happen at the start of the script,
101 # before we even do our "did we build git yet" check (since we don't
102 # want that one to complain to stderr).
103 prepend_var ASAN_OPTIONS : $GIT_SAN_OPTIONS
104 prepend_var ASAN_OPTIONS : detect_leaks=0
105 prepend_var ASAN_OPTIONS : strict_string_checks=1
106 export ASAN_OPTIONS
107
108 prepend_var LSAN_OPTIONS : $GIT_SAN_OPTIONS
109 prepend_var LSAN_OPTIONS : exitcode=0
110 prepend_var LSAN_OPTIONS : fast_unwind_on_malloc=0
111 export LSAN_OPTIONS
112
113 prepend_var UBSAN_OPTIONS : $GIT_SAN_OPTIONS
114 export UBSAN_OPTIONS
115
116 # The TEST_OUTPUT_DIRECTORY will be overwritten via GIT-BUILD-OPTIONS. So in
117 # case the caller has manually set up this variable via the environment we must
118 # make sure to not overwrite that value, and thus we save it into
119 # TEST_OUTPUT_DIRECTORY_OVERRIDE here.
120 if test -n "$TEST_OUTPUT_DIRECTORY" && test -z "$TEST_OUTPUT_DIRECTORY_OVERRIDE"
121 then
122 TEST_OUTPUT_DIRECTORY_OVERRIDE=$TEST_OUTPUT_DIRECTORY
123 fi
124
125 if test ! -f "$GIT_BUILD_DIR"/GIT-BUILD-OPTIONS
126 then
127 echo >&2 'error: GIT-BUILD-OPTIONS missing (has Git been built?).'
128 exit 1
129 fi
130 . "$GIT_BUILD_DIR"/GIT-BUILD-OPTIONS
131 export PERL_PATH SHELL_PATH
132
133 if test -z "$TEST_OUTPUT_DIRECTORY"
134 then
135 # Similarly, override this to store the test-results subdir
136 # elsewhere
137 TEST_OUTPUT_DIRECTORY=$TEST_DIRECTORY
138 fi
139
140 # In t0000, we need to override test directories of nested testcases. In case
141 # the developer has TEST_OUTPUT_DIRECTORY part of his build options, then we'd
142 # reset this value to instead contain what the developer has specified. We thus
143 # have this knob to allow overriding the directory.
144 if test -n "${TEST_OUTPUT_DIRECTORY_OVERRIDE}"
145 then
146 TEST_OUTPUT_DIRECTORY="${TEST_OUTPUT_DIRECTORY_OVERRIDE}"
147 fi
148
149 # Disallow the use of abbreviated options in the test suite by default
150 if test -z "${GIT_TEST_DISALLOW_ABBREVIATED_OPTIONS}"
151 then
152 GIT_TEST_DISALLOW_ABBREVIATED_OPTIONS=true
153 export GIT_TEST_DISALLOW_ABBREVIATED_OPTIONS
154 fi
155
156 # Explicitly set the default branch name for testing, to squelch hints
157 # from "git init" during the transition period. Should be removed
158 # after we decide to remove ADVICE_DEFAULT_BRANCH_NAME
159 if test -z "$WITH_BREAKING_CHANGES"
160 then
161 : ${GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME:=master}
162 else
163 : ${GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME:=main}
164 fi
165 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
166
167
168 ################################################################
169 # It appears that people try to run tests without building...
170 GIT_BINARY="${GIT_TEST_INSTALLED:-$GIT_BUILD_DIR}/git$X"
171
172 if ! "$GIT_BINARY" version >/dev/null
173 then
174 if test -n "$GIT_TEST_INSTALLED"
175 then
176 echo >&2 "error: there is no working Git at '$GIT_TEST_INSTALLED'"
177 else
178 echo >&2 'error: you do not seem to have built git yet.'
179 fi
180 exit 1
181 fi
182
183 store_arg_to=
184 opt_required_arg=
185 # $1: option string
186 # $2: name of the var where the arg will be stored
187 mark_option_requires_arg () {
188 if test -n "$opt_required_arg"
189 then
190 echo "error: options that require args cannot be bundled" \
191 "together: '$opt_required_arg' and '$1'" >&2
192 exit 1
193 fi
194 opt_required_arg=$1
195 store_arg_to=$2
196 }
197
198 # These functions can be overridden e.g. to output JUnit XML
199 start_test_output () { :; }
200 start_test_case_output () { :; }
201 finalize_test_case_output () { :; }
202 finalize_test_output () { :; }
203
204 parse_option () {
205 local opt="$1"
206
207 case "$opt" in
208 -d|--d|--de|--deb|--debu|--debug)
209 debug=t ;;
210 -i|--i|--im|--imm|--imme|--immed|--immedi|--immedia|--immediat|--immediate)
211 immediate=t ;;
212 -l|--l|--lo|--lon|--long|--long-|--long-t|--long-te|--long-tes|--long-test|--long-tests)
213 GIT_TEST_LONG=true; export GIT_TEST_LONG ;;
214 -r)
215 mark_option_requires_arg "$opt" run_list
216 ;;
217 --run=*)
218 run_list=${opt#--*=} ;;
219 -h|--h|--he|--hel|--help)
220 help=t ;;
221 -v|--v|--ve|--ver|--verb|--verbo|--verbos|--verbose)
222 verbose=t ;;
223 --verbose-only=*)
224 verbose_only=${opt#--*=}
225 ;;
226 -q|--q|--qu|--qui|--quie|--quiet)
227 # Ignore --quiet under a TAP::Harness. Saying how many tests
228 # passed without the ok/not ok details is always an error.
229 test -z "$HARNESS_ACTIVE" && quiet=t ;;
230 --with-dashes)
231 with_dashes=t ;;
232 --no-bin-wrappers)
233 no_bin_wrappers=t ;;
234 --no-color)
235 color= ;;
236 --va|--val|--valg|--valgr|--valgri|--valgrin|--valgrind)
237 valgrind=memcheck
238 tee=t
239 ;;
240 --valgrind=*)
241 valgrind=${opt#--*=}
242 tee=t
243 ;;
244 --valgrind-only=*)
245 valgrind_only=${opt#--*=}
246 tee=t
247 ;;
248 --tee)
249 tee=t ;;
250 --root=*)
251 root=${opt#--*=} ;;
252 --chain-lint)
253 GIT_TEST_CHAIN_LINT=1 ;;
254 --no-chain-lint)
255 GIT_TEST_CHAIN_LINT=0 ;;
256 -x)
257 trace=t ;;
258 -V|--verbose-log)
259 verbose_log=t
260 tee=t
261 ;;
262 --write-junit-xml)
263 . "$TEST_DIRECTORY/test-lib-junit.sh"
264 ;;
265 --github-workflow-markup)
266 . "$TEST_DIRECTORY/test-lib-github-workflow-markup.sh"
267 ;;
268 --stress)
269 stress=t ;;
270 --stress=*)
271 echo "error: --stress does not accept an argument: '$opt'" >&2
272 echo "did you mean --stress-jobs=${opt#*=} or --stress-limit=${opt#*=}?" >&2
273 exit 1
274 ;;
275 --stress-jobs=*)
276 stress=t;
277 stress_jobs=${opt#--*=}
278 case "$stress_jobs" in
279 *[!0-9]*|0*|"")
280 echo "error: --stress-jobs=<N> requires the number of jobs to run" >&2
281 exit 1
282 ;;
283 *) # Good.
284 ;;
285 esac
286 ;;
287 --stress-limit=*)
288 stress=t;
289 stress_limit=${opt#--*=}
290 case "$stress_limit" in
291 *[!0-9]*|0*|"")
292 echo "error: --stress-limit=<N> requires the number of repetitions" >&2
293 exit 1
294 ;;
295 *) # Good.
296 ;;
297 esac
298 ;;
299 --invert-exit-code)
300 invert_exit_code=t
301 ;;
302 *)
303 echo "error: unknown test option '$opt'" >&2; exit 1 ;;
304 esac
305 }
306
307 # Parse options while taking care to leave $@ intact, so we will still
308 # have all the original command line options when executing the test
309 # script again for '--tee' and '--verbose-log' later.
310 for opt
311 do
312 if test -n "$store_arg_to"
313 then
314 eval $store_arg_to=\$opt
315 store_arg_to=
316 opt_required_arg=
317 continue
318 fi
319
320 case "$opt" in
321 --*|-?)
322 parse_option "$opt" ;;
323 -?*)
324 # bundled short options must be fed separately to parse_option
325 opt=${opt#-}
326 while test -n "$opt"
327 do
328 extra=${opt#?}
329 this=${opt%$extra}
330 opt=$extra
331 parse_option "-$this"
332 done
333 ;;
334 *)
335 echo "error: unknown test option '$opt'" >&2; exit 1 ;;
336 esac
337 done
338 if test -n "$store_arg_to"
339 then
340 echo "error: $opt_required_arg requires an argument" >&2
341 exit 1
342 fi
343
344 if test -n "$valgrind_only"
345 then
346 test -z "$valgrind" && valgrind=memcheck
347 test -z "$verbose" && verbose_only="$valgrind_only"
348 elif test -n "$valgrind"
349 then
350 test -z "$verbose_log" && verbose=t
351 fi
352
353 if test -n "$stress"
354 then
355 verbose=t
356 trace=t
357 immediate=t
358 fi
359
360 TEST_STRESS_JOB_SFX="${GIT_TEST_STRESS_JOB_NR:+.stress-$GIT_TEST_STRESS_JOB_NR}"
361 TEST_NAME="$(basename "$0" .sh)"
362 TEST_NUMBER="${TEST_NAME%%-*}"
363 TEST_NUMBER="${TEST_NUMBER#t}"
364 TEST_RESULTS_DIR="$TEST_OUTPUT_DIRECTORY/test-results"
365 TEST_RESULTS_BASE="$TEST_RESULTS_DIR/$TEST_NAME$TEST_STRESS_JOB_SFX"
366 TEST_RESULTS_SAN_FILE_PFX=trace
367 TEST_RESULTS_SAN_DIR_SFX=leak
368 TEST_RESULTS_SAN_FILE=
369 TEST_RESULTS_SAN_DIR="$TEST_RESULTS_BASE.$TEST_RESULTS_SAN_DIR_SFX"
370 TRASH_DIRECTORY="trash directory.$TEST_NAME$TEST_STRESS_JOB_SFX"
371 test -n "$root" && TRASH_DIRECTORY="$root/$TRASH_DIRECTORY"
372 case "$TRASH_DIRECTORY" in
373 /*) ;; # absolute path is good
374 *) TRASH_DIRECTORY="$TEST_OUTPUT_DIRECTORY/$TRASH_DIRECTORY" ;;
375 esac
376
377 # If --stress was passed, run this test repeatedly in several parallel loops.
378 if test "$GIT_TEST_STRESS_STARTED" = "done"
379 then
380 : # Don't stress test again.
381 elif test -n "$stress"
382 then
383 if test -n "$stress_jobs"
384 then
385 job_count=$stress_jobs
386 elif test -n "$GIT_TEST_STRESS_LOAD"
387 then
388 job_count="$GIT_TEST_STRESS_LOAD"
389 elif job_count=$(getconf _NPROCESSORS_ONLN 2>/dev/null) &&
390 test -n "$job_count"
391 then
392 job_count=$((2 * $job_count))
393 else
394 job_count=8
395 fi
396
397 mkdir -p "$TEST_RESULTS_DIR"
398 stressfail="$TEST_RESULTS_BASE.stress-failed"
399 rm -f "$stressfail"
400
401 stress_exit=0
402 trap '
403 kill $job_pids 2>/dev/null
404 wait
405 stress_exit=1
406 ' TERM INT HUP
407
408 job_pids=
409 job_nr=0
410 while test $job_nr -lt "$job_count"
411 do
412 (
413 GIT_TEST_STRESS_STARTED=done
414 GIT_TEST_STRESS_JOB_NR=$job_nr
415 export GIT_TEST_STRESS_STARTED GIT_TEST_STRESS_JOB_NR
416
417 trap '
418 kill $test_pid 2>/dev/null
419 wait
420 exit 1
421 ' TERM INT
422
423 cnt=1
424 while ! test -e "$stressfail" &&
425 { test -z "$stress_limit" ||
426 test $cnt -le $stress_limit ; }
427 do
428 $TEST_SHELL_PATH "$0" "$@" >"$TEST_RESULTS_BASE.stress-$job_nr.out" 2>&1 &
429 test_pid=$!
430
431 if wait $test_pid
432 then
433 printf "OK %2d.%d\n" $GIT_TEST_STRESS_JOB_NR $cnt
434 else
435 echo $GIT_TEST_STRESS_JOB_NR >>"$stressfail"
436 printf "FAIL %2d.%d\n" $GIT_TEST_STRESS_JOB_NR $cnt
437 fi
438 cnt=$(($cnt + 1))
439 done
440 ) &
441 job_pids="$job_pids $!"
442 job_nr=$(($job_nr + 1))
443 done
444
445 wait
446
447 if test -f "$stressfail"
448 then
449 stress_exit=1
450 echo "Log(s) of failed test run(s):"
451 for failed_job_nr in $(sort -n "$stressfail")
452 do
453 echo "Contents of '$TEST_RESULTS_BASE.stress-$failed_job_nr.out':"
454 cat "$TEST_RESULTS_BASE.stress-$failed_job_nr.out"
455 done
456 rm -rf "$TRASH_DIRECTORY.stress-failed"
457 # Move the last one.
458 mv "$TRASH_DIRECTORY.stress-$failed_job_nr" "$TRASH_DIRECTORY.stress-failed"
459 fi
460
461 exit $stress_exit
462 fi
463
464 # if --tee was passed, write the output not only to the terminal, but
465 # additionally to the file test-results/$BASENAME.out, too.
466 if test "$GIT_TEST_TEE_STARTED" = "done"
467 then
468 : # do not redirect again
469 elif test -n "$tee"
470 then
471 mkdir -p "$TEST_RESULTS_DIR"
472
473 # Make this filename available to the sub-process in case it is using
474 # --verbose-log.
475 GIT_TEST_TEE_OUTPUT_FILE=$TEST_RESULTS_BASE.out
476 export GIT_TEST_TEE_OUTPUT_FILE
477
478 # Truncate before calling "tee -a" to get rid of the results
479 # from any previous runs.
480 >"$GIT_TEST_TEE_OUTPUT_FILE"
481
482 (
483 ret=0 && GIT_TEST_TEE_STARTED=done ${TEST_SHELL_PATH} "$0" "$@" 2>&1 || ret=$?
484 echo "$ret" >"$TEST_RESULTS_BASE.exit"
485 ) | tee -a "$GIT_TEST_TEE_OUTPUT_FILE"
486 test "$(cat "$TEST_RESULTS_BASE.exit")" = 0
487 exit
488 fi
489
490 if test -n "$trace" && test -n "$test_untraceable"
491 then
492 # '-x' tracing requested, but this test script can't be reliably
493 # traced, unless it is run with a Bash version supporting
494 # BASH_XTRACEFD (introduced in Bash v4.1).
495 #
496 # Perform this version check _after_ the test script was
497 # potentially re-executed with $TEST_SHELL_PATH for '--tee' or
498 # '--verbose-log', so the right shell is checked and the
499 # warning is issued only once.
500 if test -n "$BASH_VERSION" && eval '
501 test ${BASH_VERSINFO[0]} -gt 4 || {
502 test ${BASH_VERSINFO[0]} -eq 4 &&
503 test ${BASH_VERSINFO[1]} -ge 1
504 }
505 '
506 then
507 : Executed by a Bash version supporting BASH_XTRACEFD. Good.
508 else
509 echo >&2 "# warning: ignoring -x; '$0' is untraceable without BASH_XTRACEFD"
510 trace=
511 fi
512 fi
513 if test -n "$trace" && test -z "$verbose_log"
514 then
515 verbose=t
516 fi
517
518 # Since bash 5.0, checkwinsize is enabled by default which does
519 # update the COLUMNS variable every time a non-builtin command
520 # completes, even for non-interactive shells.
521 # Disable that since we are aiming for repeatability.
522 test -n "$BASH_VERSION" && shopt -u checkwinsize 2>/dev/null
523
524 # For repeatability, reset the environment to known value.
525 # TERM is sanitized below, after saving color control sequences.
526 LANG=C
527 LC_ALL=C
528 PAGER=cat
529 TZ=UTC
530 COLUMNS=80
531 export LANG LC_ALL PAGER TZ COLUMNS
532 EDITOR=:
533
534 # A call to "unset" with no arguments causes at least Solaris 10
535 # /usr/xpg4/bin/sh and /bin/ksh to bail out. So keep the unsets
536 # deriving from the command substitution clustered with the other
537 # ones.
538 unset VISUAL EMAIL LANGUAGE $(env | sed -n \
539 -e '/^GIT_TRACE/d' \
540 -e '/^GIT_DEBUG/d' \
541 -e '/^GIT_TEST/d' \
542 -e '/^GIT_.*_TEST/d' \
543 -e '/^GIT_PROVE/d' \
544 -e '/^GIT_VALGRIND/d' \
545 -e '/^GIT_UNZIP/d' \
546 -e '/^GIT_PERF_/d' \
547 -e '/^GIT_CURL_VERBOSE/d' \
548 -e '/^GIT_TRACE_CURL/d' \
549 -e '/^GIT_BUILD_DIR/d' \
550 -e 's/^\(GIT_[^=]*\)=.*/\1/p'
551 )
552 unset XDG_CACHE_HOME
553 unset XDG_CONFIG_HOME
554 unset GITPERLLIB
555 unset GIT_TRACE2_PARENT_NAME
556 unset GIT_TRACE2_PARENT_SID
557 TEST_AUTHOR_LOCALNAME=author
558 TEST_AUTHOR_DOMAIN=example.com
559 GIT_AUTHOR_EMAIL=${TEST_AUTHOR_LOCALNAME}@${TEST_AUTHOR_DOMAIN}
560 GIT_AUTHOR_NAME='A U Thor'
561 GIT_AUTHOR_DATE='1112354055 +0200'
562 TEST_COMMITTER_LOCALNAME=committer
563 TEST_COMMITTER_DOMAIN=example.com
564 GIT_COMMITTER_EMAIL=${TEST_COMMITTER_LOCALNAME}@${TEST_COMMITTER_DOMAIN}
565 GIT_COMMITTER_NAME='C O Mitter'
566 GIT_COMMITTER_DATE='1112354055 +0200'
567 GIT_MERGE_VERBOSITY=5
568 GIT_MERGE_AUTOEDIT=no
569 export GIT_MERGE_VERBOSITY GIT_MERGE_AUTOEDIT
570 export GIT_AUTHOR_EMAIL GIT_AUTHOR_NAME
571 export GIT_COMMITTER_EMAIL GIT_COMMITTER_NAME
572 export GIT_COMMITTER_DATE GIT_AUTHOR_DATE
573 export EDITOR
574
575 GIT_TEST_BUILTIN_HASH=$("$GIT_BINARY" version --build-options | sed -ne 's/^default-hash: //p')
576 GIT_DEFAULT_HASH="${GIT_TEST_DEFAULT_HASH:-$GIT_TEST_BUILTIN_HASH}"
577 export GIT_DEFAULT_HASH
578 GIT_DEFAULT_REF_FORMAT="${GIT_TEST_DEFAULT_REF_FORMAT:-files}"
579 export GIT_DEFAULT_REF_FORMAT
580
581 # Tests using GIT_TRACE typically don't want <timestamp> <file>:<line> output
582 GIT_TRACE_BARE=1
583 export GIT_TRACE_BARE
584
585 # Some tests scan the GIT_TRACE2_EVENT feed for events, but the
586 # default depth is 2, which frequently causes issues when the
587 # events are wrapped in new regions. Set it to a sufficiently
588 # large depth to avoid custom changes in the test suite.
589 GIT_TRACE2_EVENT_NESTING=100
590 export GIT_TRACE2_EVENT_NESTING
591
592 # Use specific version of the index file format
593 if test -n "${GIT_TEST_INDEX_VERSION:+isset}"
594 then
595 GIT_INDEX_VERSION="$GIT_TEST_INDEX_VERSION"
596 export GIT_INDEX_VERSION
597 fi
598
599 if test -n "$GIT_TEST_PERL_FATAL_WARNINGS"
600 then
601 GIT_PERL_FATAL_WARNINGS=1
602 export GIT_PERL_FATAL_WARNINGS
603 fi
604
605 case $GIT_TEST_FSYNC in
606 '')
607 GIT_TEST_FSYNC=0
608 export GIT_TEST_FSYNC
609 ;;
610 esac
611
612 # Protect ourselves from common misconfiguration to export
613 # CDPATH into the environment
614 unset CDPATH
615
616 unset GREP_OPTIONS
617 unset UNZIP
618
619 case $(echo $GIT_TRACE |tr "[A-Z]" "[a-z]") in
620 1|2|true)
621 GIT_TRACE=4
622 ;;
623 esac
624
625 # Line feed
626 LF='
627 '
628
629 # Single quote
630 SQ=\'
631
632 # UTF-8 ZERO WIDTH NON-JOINER, which HFS+ ignores
633 # when case-folding filenames
634 u200c=$(printf '\342\200\214')
635
636 export _x05 _x35 LF u200c EMPTY_TREE EMPTY_BLOB ZERO_OID OID_REGEX
637
638 test "x$TERM" != "xdumb" && (
639 test -t 1 &&
640 tput bold >/dev/null 2>&1 &&
641 tput setaf 1 >/dev/null 2>&1 &&
642 tput sgr0 >/dev/null 2>&1
643 ) &&
644 color=t
645
646 if test -n "$color"
647 then
648 # Save the color control sequences now rather than run tput
649 # each time say_color() is called. This is done for two
650 # reasons:
651 # * TERM will be changed to dumb
652 # * HOME will be changed to a temporary directory and tput
653 # might need to read ~/.terminfo from the original HOME
654 # directory to get the control sequences
655 # Note: This approach assumes the control sequences don't end
656 # in a newline for any terminal of interest (command
657 # substitutions strip trailing newlines). Given that most
658 # (all?) terminals in common use are related to ECMA-48, this
659 # shouldn't be a problem.
660 say_color_error=$(tput bold; tput setaf 1) # bold red
661 say_color_skip=$(tput setaf 4) # blue
662 say_color_warn=$(tput setaf 3) # brown/yellow
663 say_color_pass=$(tput setaf 2) # green
664 say_color_info=$(tput setaf 6) # cyan
665 say_color_reset=$(tput sgr0)
666 say_color_="" # no formatting for normal text
667 say_color () {
668 test -z "$1" && test -n "$quiet" && return
669 eval "say_color_color=\$say_color_$1"
670 shift
671 printf "%s\\n" "$say_color_color$*$say_color_reset"
672 }
673 else
674 say_color() {
675 test -z "$1" && test -n "$quiet" && return
676 shift
677 printf "%s\n" "$*"
678 }
679 fi
680
681 USER_TERM="$TERM"
682 TERM=dumb
683 export TERM USER_TERM
684
685 # What is written by tests to stdout and stderr is sent to different places
686 # depending on the test mode (e.g. /dev/null in non-verbose mode, piped to tee
687 # with --tee option, etc.). We save the original stdin to FD #6 and stdout and
688 # stderr to #5 and #7, so that the test framework can use them (e.g. for
689 # printing errors within the test framework) independently of the test mode.
690 exec 5>&1
691 exec 6<&0
692 exec 7>&2
693
694 _error_exit () {
695 finalize_test_output
696 GIT_EXIT_OK=t
697 exit 1
698 }
699
700 error () {
701 say_color error "error: $*"
702 _error_exit
703 }
704
705 BUG () {
706 error >&7 "bug in the test script: $*"
707 }
708
709 BAIL_OUT () {
710 test $# -ne 1 && BUG "1 param"
711
712 # Do not change "Bail out! " string. It's part of TAP syntax:
713 # https://testanything.org/tap-specification.html
714 local bail_out="Bail out! "
715 local message="$1"
716
717 say_color >&5 error $bail_out "$message"
718 _error_exit
719 }
720
721 say () {
722 say_color info "$*"
723 }
724
725 if test -n "$HARNESS_ACTIVE"
726 then
727 if test "$verbose" = t || test -n "$verbose_only"
728 then
729 BAIL_OUT 'verbose mode forbidden under TAP harness; try --verbose-log'
730 fi
731 fi
732
733 test "${test_description}" != "" ||
734 error "Test script did not set test_description."
735
736 if test "$help" = "t"
737 then
738 printf '%s\n' "$test_description"
739 exit 0
740 fi
741
742 if test "$verbose_log" = "t"
743 then
744 exec 3>>"$GIT_TEST_TEE_OUTPUT_FILE" 4>&3
745 elif test "$verbose" = "t"
746 then
747 exec 4>&2 3>&2
748 else
749 exec 4>/dev/null 3>/dev/null
750 fi
751
752 # Send any "-x" output directly to stderr to avoid polluting tests
753 # which capture stderr. We can do this unconditionally since it
754 # has no effect if tracing isn't turned on.
755 #
756 # Note that this sets up the trace fd as soon as we assign the variable, so it
757 # must come after the creation of descriptor 4 above. Likewise, we must never
758 # unset this, as it has the side effect of closing descriptor 4, which we
759 # use to show verbose tests to the user.
760 #
761 # Note also that we don't need or want to export it. The tracing is local to
762 # this shell, and we would not want to influence any shells we exec.
763 BASH_XTRACEFD=4
764
765 test_failure=0
766 test_count=0
767 test_fixed=0
768 test_broken=0
769 test_success=0
770
771 test_missing_prereq=
772
773 test_external_has_tap=0
774
775 die () {
776 code=$?
777 # This is responsible for running the atexit commands even when a
778 # test script run with '--immediate' fails, or when the user hits
779 # ctrl-C, i.e. when 'test_done' is not invoked at all.
780 test_atexit_handler || code=$?
781 if test -n "$GIT_EXIT_OK"
782 then
783 exit $code
784 else
785 echo >&5 "FATAL: Unexpected exit with code $code"
786 exit 1
787 fi
788 }
789
790 GIT_EXIT_OK=
791 trap 'die' EXIT
792 # Disable '-x' tracing, because with some shells, notably dash, it
793 # prevents running the cleanup commands when a test script run with
794 # '--verbose-log -x' is interrupted.
795 trap '{ code=$?; set +x; } 2>/dev/null; exit $code' INT TERM HUP
796
797 # The user-facing functions are loaded from a separate file so that
798 # test_perf subshells can have them too
799 . "$TEST_DIRECTORY/test-lib-functions.sh"
800
801 # You are not expected to call test_ok_ and test_failure_ directly, use
802 # the test_expect_* functions instead.
803
804 test_ok_ () {
805 test_success=$(($test_success + 1))
806 say_color "" "ok $test_count - $@"
807 finalize_test_case_output ok "$@"
808 }
809
810 _invert_exit_code_failure_end_blurb () {
811 say_color warn "# faked up failures as TODO & now exiting with 0 due to --invert-exit-code"
812 }
813
814 test_failure_ () {
815 failure_label=$1
816 test_failure=$(($test_failure + 1))
817 local pfx=""
818 if test -n "$invert_exit_code" # && test -n "$HARNESS_ACTIVE"
819 then
820 pfx="# TODO induced breakage (--invert-exit-code):"
821 fi
822 say_color error "not ok $test_count - ${pfx:+$pfx }$1"
823 shift
824 printf '%s\n' "$*" | sed -e 's/^/# /'
825 if test -n "$immediate"
826 then
827 say_color error "1..$test_count"
828 if test -n "$invert_exit_code"
829 then
830 finalize_test_output
831 _invert_exit_code_failure_end_blurb
832 GIT_EXIT_OK=t
833 exit 0
834 fi
835 check_test_results_san_file_ "$test_failure"
836 _error_exit
837 fi
838 finalize_test_case_output failure "$failure_label" "$@"
839 }
840
841 test_known_broken_ok_ () {
842 test_fixed=$(($test_fixed+1))
843 say_color error "ok $test_count - $1 # TODO known breakage vanished"
844 finalize_test_case_output fixed "$1"
845 }
846
847 test_known_broken_failure_ () {
848 test_broken=$(($test_broken+1))
849 say_color warn "not ok $test_count - $1 # TODO known breakage"
850 finalize_test_case_output broken "$1"
851 }
852
853 test_debug () {
854 test "$debug" = "" || eval "$1"
855 }
856
857 match_pattern_list () {
858 arg="$1"
859 shift
860 test -z "$*" && return 1
861 # We need to use "$*" to get field-splitting, but we want to
862 # disable globbing, since we are matching against an arbitrary
863 # $arg, not what's in the filesystem. Using "set -f" accomplishes
864 # that, but we must do it in a subshell to avoid impacting the
865 # rest of the script. The exit value of the subshell becomes
866 # the function's return value.
867 (
868 set -f
869 for pattern_ in $*
870 do
871 case "$arg" in
872 $pattern_)
873 exit 0
874 ;;
875 esac
876 done
877 exit 1
878 )
879 }
880
881 match_test_selector_list () {
882 operation="$1"
883 shift
884 title="$1"
885 shift
886 arg="$1"
887 shift
888 test -z "$1" && return 0
889
890 # Commas are accepted as separators.
891 OLDIFS=$IFS
892 IFS=','
893 set -- $1
894 IFS=$OLDIFS
895
896 # If the first selector is negative we include by default.
897 include=
898 case "$1" in
899 !*) include=t ;;
900 esac
901
902 for selector
903 do
904 orig_selector=$selector
905
906 positive=t
907 case "$selector" in
908 !*)
909 positive=
910 selector=${selector##?}
911 ;;
912 esac
913
914 test -z "$selector" && continue
915
916 case "$selector" in
917 *-*)
918 if expr "z${selector%%-*}" : "z[0-9]*[^0-9]" >/dev/null
919 then
920 echo "error: $operation: invalid non-numeric in range" \
921 "start: '$orig_selector'" >&2
922 exit 1
923 fi
924 if expr "z${selector#*-}" : "z[0-9]*[^0-9]" >/dev/null
925 then
926 echo "error: $operation: invalid non-numeric in range" \
927 "end: '$orig_selector'" >&2
928 exit 1
929 fi
930 ;;
931 *)
932 if expr "z$selector" : "z[0-9]*[^0-9]" >/dev/null
933 then
934 case "$title" in *${selector}*)
935 include=$positive
936 ;;
937 esac
938 continue
939 fi
940 esac
941
942 # Short cut for "obvious" cases
943 test -z "$include" && test -z "$positive" && continue
944 test -n "$include" && test -n "$positive" && continue
945
946 case "$selector" in
947 -*)
948 if test $arg -le ${selector#-}
949 then
950 include=$positive
951 fi
952 ;;
953 *-)
954 if test $arg -ge ${selector%-}
955 then
956 include=$positive
957 fi
958 ;;
959 *-*)
960 if test ${selector%%-*} -le $arg \
961 && test $arg -le ${selector#*-}
962 then
963 include=$positive
964 fi
965 ;;
966 *)
967 if test $arg -eq $selector
968 then
969 include=$positive
970 fi
971 ;;
972 esac
973 done
974
975 test -n "$include"
976 }
977
978 maybe_teardown_verbose () {
979 test -z "$verbose_only" && return
980 exec 4>/dev/null 3>/dev/null
981 verbose=
982 }
983
984 last_verbose=t
985 maybe_setup_verbose () {
986 test -z "$verbose_only" && return
987 if match_pattern_list $test_count "$verbose_only"
988 then
989 exec 4>&2 3>&2
990 # Emit a delimiting blank line when going from
991 # non-verbose to verbose. Within verbose mode the
992 # delimiter is printed by test_expect_*. The choice
993 # of the initial $last_verbose is such that before
994 # test 1, we do not print it.
995 test -z "$last_verbose" && echo >&3 ""
996 verbose=t
997 else
998 exec 4>/dev/null 3>/dev/null
999 verbose=
1000 fi
1001 last_verbose=$verbose
1002 }
1003
1004 maybe_teardown_valgrind () {
1005 test -z "$GIT_VALGRIND" && return
1006 GIT_VALGRIND_ENABLED=
1007 }
1008
1009 maybe_setup_valgrind () {
1010 test -z "$GIT_VALGRIND" && return
1011 if test -z "$valgrind_only"
1012 then
1013 GIT_VALGRIND_ENABLED=t
1014 return
1015 fi
1016 GIT_VALGRIND_ENABLED=
1017 if match_pattern_list $test_count "$valgrind_only"
1018 then
1019 GIT_VALGRIND_ENABLED=t
1020 fi
1021 }
1022
1023 trace_level_=0
1024 want_trace () {
1025 test "$trace" = t && {
1026 test "$verbose" = t || test "$verbose_log" = t
1027 }
1028 }
1029
1030 # This is a separate function because some tests use
1031 # "return" to end a test_expect_success block early
1032 # (and we want to make sure we run any cleanup like
1033 # "set +x").
1034 test_eval_inner_ () {
1035 eval "$*"
1036 }
1037
1038 test_eval_ () {
1039 # If "-x" tracing is in effect, then we want to avoid polluting stderr
1040 # with non-test commands. But once in "set -x" mode, we cannot prevent
1041 # the shell from printing the "set +x" to turn it off (nor the saving
1042 # of $? before that). But we can make sure that the output goes to
1043 # /dev/null.
1044 #
1045 # There are a few subtleties here:
1046 #
1047 # - we have to redirect descriptor 4 in addition to 2, to cover
1048 # BASH_XTRACEFD
1049 #
1050 # - the actual eval has to come before the redirection block (since
1051 # it needs to see descriptor 4 to set up its stderr)
1052 #
1053 # - likewise, any error message we print must be outside the block to
1054 # access descriptor 4
1055 #
1056 # - checking $? has to come immediately after the eval, but it must
1057 # be _inside_ the block to avoid polluting the "set -x" output
1058 #
1059
1060 # Do not add anything extra (including LF) after '$*'
1061 test_eval_inner_ </dev/null >&3 2>&4 "
1062 want_trace && trace_level_=$(($trace_level_+1)) && set -x
1063 $*"
1064 {
1065 test_eval_ret_=$?
1066 if want_trace
1067 then
1068 test 1 = $trace_level_ && set +x
1069 trace_level_=$(($trace_level_-1))
1070 fi
1071 } 2>/dev/null 4>&2
1072
1073 if test "$test_eval_ret_" != 0 && want_trace
1074 then
1075 say_color error >&4 "error: last command exited with \$?=$test_eval_ret_"
1076 fi
1077 return $test_eval_ret_
1078 }
1079
1080 fail_117 () {
1081 return 117
1082 }
1083
1084 test_run_ () {
1085 test_cleanup=:
1086 expecting_failure=$2
1087
1088 if test "${GIT_TEST_CHAIN_LINT:-1}" != 0; then
1089 # 117 is magic because it is unlikely to match the exit
1090 # code of other programs
1091 test_eval_inner_ "fail_117 && $1" </dev/null >&3 2>&4
1092 if test $? != 117
1093 then
1094 BUG "broken &&-chain: $1"
1095 fi
1096 fi
1097
1098 setup_malloc_check
1099 test_eval_ "$1"
1100 eval_ret=$?
1101 teardown_malloc_check
1102
1103 if test -z "$immediate" || test $eval_ret = 0 ||
1104 test -n "$expecting_failure" && test "$test_cleanup" != ":"
1105 then
1106 setup_malloc_check
1107 test_eval_ "$test_cleanup"
1108 teardown_malloc_check
1109 fi
1110 if test "$verbose" = "t" && test -n "$HARNESS_ACTIVE"
1111 then
1112 echo ""
1113 fi
1114 return "$eval_ret"
1115 }
1116
1117 test_start_ () {
1118 test_count=$(($test_count+1))
1119 maybe_setup_verbose
1120 maybe_setup_valgrind
1121 start_test_case_output "$@"
1122 }
1123
1124 test_finish_ () {
1125 echo >&3 ""
1126 maybe_teardown_valgrind
1127 maybe_teardown_verbose
1128 if test -n "$GIT_TEST_TEE_OFFSET"
1129 then
1130 GIT_TEST_TEE_OFFSET=$(test-tool path-utils file-size \
1131 "$GIT_TEST_TEE_OUTPUT_FILE")
1132 fi
1133 }
1134
1135 test_skip () {
1136 to_skip=
1137 skipped_reason=
1138 if match_pattern_list $this_test.$test_count "$GIT_SKIP_TESTS"
1139 then
1140 to_skip=t
1141 skipped_reason="GIT_SKIP_TESTS"
1142 fi
1143 if test -z "$to_skip" && test -n "$run_list" &&
1144 ! match_test_selector_list '--run' "$1" $test_count "$run_list"
1145 then
1146 to_skip=t
1147 skipped_reason="--run"
1148 fi
1149 if test -z "$to_skip" && test -n "$test_prereq" &&
1150 ! test_have_prereq "$test_prereq"
1151 then
1152 to_skip=t
1153
1154 of_prereq=
1155 if test "$missing_prereq" != "$test_prereq"
1156 then
1157 of_prereq=" of $test_prereq"
1158 fi
1159 skipped_reason="missing $missing_prereq${of_prereq}"
1160
1161 # Keep a list of all the missing prereq for result aggregation
1162 if test -z "$missing_prereq"
1163 then
1164 test_missing_prereq=$missing_prereq
1165 else
1166 test_missing_prereq="$test_missing_prereq,$missing_prereq"
1167 fi
1168 fi
1169
1170 case "$to_skip" in
1171 t)
1172
1173 say_color skip "ok $test_count # skip $1 ($skipped_reason)"
1174 : true
1175 finalize_test_case_output skip "$@"
1176 ;;
1177 *)
1178 false
1179 ;;
1180 esac
1181 }
1182
1183 # stub; perf-lib overrides it
1184 test_at_end_hook_ () {
1185 :
1186 }
1187
1188 test_atexit_cleanup=:
1189 test_atexit_handler () {
1190 # In a succeeding test script 'test_atexit_handler' is invoked
1191 # twice: first from 'test_done', then from 'die' in the trap on
1192 # EXIT.
1193 # This condition and resetting 'test_atexit_cleanup' below makes
1194 # sure that the registered cleanup commands are run only once.
1195 test : != "$test_atexit_cleanup" || return 0
1196
1197 setup_malloc_check
1198 test_eval_ "$test_atexit_cleanup"
1199 test_atexit_cleanup=:
1200 teardown_malloc_check
1201 }
1202
1203 check_test_results_san_file_has_entries_ () {
1204 test -z "$TEST_RESULTS_SAN_FILE" && return 1
1205
1206 # Lines marked with DEDUP_TOKEN show unique leaks. We only care that we
1207 # found at least one.
1208 #
1209 # But also suppress any false positives caused by bugs or races in the
1210 # sanitizer itself.
1211 grep -s ^DEDUP_TOKEN "$TEST_RESULTS_SAN_FILE".* |
1212 grep -qv sanitizer::GetThreadStackTopAndBottom
1213 }
1214
1215 check_test_results_san_file_ () {
1216 if ! check_test_results_san_file_has_entries_
1217 then
1218 return
1219 fi &&
1220 say_color >&4 error "$(cat "$TEST_RESULTS_SAN_FILE".*)" &&
1221
1222 if test "$test_failure" = 0
1223 then
1224 say >&4 "Our logs revealed a memory leak, exit non-zero!" &&
1225 invert_exit_code=t
1226 else
1227 say >&4 "Our logs revealed a memory leak..."
1228 fi
1229 }
1230
1231 test_done () {
1232 # Run the atexit commands _before_ the trash directory is
1233 # removed, so the commands can access pidfiles and socket files.
1234 test_atexit_handler
1235
1236 finalize_test_output
1237
1238 if test -z "$HARNESS_ACTIVE"
1239 then
1240 mkdir -p "$TEST_RESULTS_DIR"
1241
1242 cat >"$TEST_RESULTS_BASE.counts" <<-EOF
1243 total $test_count
1244 success $test_success
1245 fixed $test_fixed
1246 broken $test_broken
1247 failed $test_failure
1248 missing_prereq $test_missing_prereq
1249
1250 EOF
1251 fi
1252
1253 if test "$test_fixed" != 0
1254 then
1255 say_color error "# $test_fixed known breakage(s) vanished; please update test(s)"
1256 fi
1257 if test "$test_broken" != 0
1258 then
1259 say_color warn "# still have $test_broken known breakage(s)"
1260 fi
1261 if test "$test_broken" != 0 || test "$test_fixed" != 0
1262 then
1263 test_remaining=$(( $test_count - $test_broken - $test_fixed ))
1264 msg="remaining $test_remaining test(s)"
1265 else
1266 test_remaining=$test_count
1267 msg="$test_count test(s)"
1268 fi
1269 case "$test_failure" in
1270 0)
1271 if test $test_remaining -gt 0
1272 then
1273 say_color pass "# passed all $msg"
1274 fi
1275
1276 # Maybe print SKIP message
1277 test -z "$skip_all" || skip_all="# SKIP $skip_all"
1278 case "$test_count" in
1279 0)
1280 say "1..$test_count${skip_all:+ $skip_all}"
1281 ;;
1282 *)
1283 test -z "$skip_all" ||
1284 say_color warn "$skip_all"
1285 say "1..$test_count"
1286 ;;
1287 esac
1288
1289 if test -n "$stress" && test -n "$invert_exit_code"
1290 then
1291 # We're about to move our "$TRASH_DIRECTORY"
1292 # to "$TRASH_DIRECTORY.stress-failed" if
1293 # --stress is combined with
1294 # --invert-exit-code.
1295 say "with --stress and --invert-exit-code we're not removing '$TRASH_DIRECTORY'"
1296 elif test -z "$debug" && test -n "$remove_trash"
1297 then
1298 test -d "$TRASH_DIRECTORY" ||
1299 error "Tests passed but trash directory already removed before test cleanup; aborting"
1300
1301 cd "$TRASH_DIRECTORY/.." &&
1302 rm -fr "$TRASH_DIRECTORY" 2>/dev/null || {
1303 # try again in a bit
1304 sleep 5;
1305 rm -fr "$TRASH_DIRECTORY" 2>/dev/null
1306 } ||
1307 error "Tests passed but test cleanup failed; aborting"
1308 fi
1309
1310 check_test_results_san_file_ "$test_failure"
1311
1312 if test "$test_fixed" != 0
1313 then
1314 if test -z "$invert_exit_code"
1315 then
1316 GIT_EXIT_OK=t
1317 exit 1
1318 fi
1319 elif test -z "$skip_all" && test -n "$invert_exit_code"
1320 then
1321 say_color warn "# faking up non-zero exit with --invert-exit-code"
1322 GIT_EXIT_OK=t
1323 exit 1
1324 fi
1325
1326 test_at_end_hook_
1327
1328 GIT_EXIT_OK=t
1329 exit 0 ;;
1330
1331 *)
1332 say_color error "# failed $test_failure among $msg"
1333 say "1..$test_count"
1334
1335 check_test_results_san_file_ "$test_failure"
1336
1337 if test -n "$invert_exit_code"
1338 then
1339 _invert_exit_code_failure_end_blurb
1340 GIT_EXIT_OK=t
1341 exit 0
1342 fi
1343
1344 GIT_EXIT_OK=t
1345 exit 1 ;;
1346
1347 esac
1348 }
1349
1350 if test -n "$valgrind"
1351 then
1352 make_symlink () {
1353 test -h "$2" &&
1354 test "$1" = "$(readlink "$2")" || {
1355 # be super paranoid
1356 if mkdir "$2".lock
1357 then
1358 rm -f "$2" &&
1359 ln -s "$1" "$2" &&
1360 rm -r "$2".lock
1361 else
1362 while test -d "$2".lock
1363 do
1364 say "Waiting for lock on $2."
1365 sleep 1
1366 done
1367 fi
1368 }
1369 }
1370
1371 make_valgrind_symlink () {
1372 # handle only executables, unless they are shell libraries that
1373 # need to be in the exec-path.
1374 test -x "$1" ||
1375 test "# " = "$(test_copy_bytes 2 <"$1")" ||
1376 return;
1377
1378 base=$(basename "$1")
1379 case "$base" in
1380 test-*)
1381 symlink_target="$GIT_BUILD_DIR/t/helper/$base"
1382 ;;
1383 *)
1384 symlink_target="$GIT_BUILD_DIR/$base"
1385 ;;
1386 esac
1387 # do not override scripts
1388 if test -x "$symlink_target" &&
1389 test ! -d "$symlink_target" &&
1390 test "#!" != "$(test_copy_bytes 2 <"$symlink_target")"
1391 then
1392 symlink_target=../valgrind.sh
1393 fi
1394 case "$base" in
1395 *.sh|*.perl)
1396 symlink_target=../unprocessed-script
1397 esac
1398 # create the link, or replace it if it is out of date
1399 make_symlink "$symlink_target" "$GIT_VALGRIND/bin/$base" || exit
1400 }
1401
1402 # override all git executables in TEST_DIRECTORY/..
1403 GIT_VALGRIND=$TEST_DIRECTORY/valgrind
1404 mkdir -p "$GIT_VALGRIND"/bin
1405 for file in $GIT_BUILD_DIR/git* $GIT_BUILD_DIR/t/helper/test-*
1406 do
1407 make_valgrind_symlink $file
1408 done
1409 # special-case the mergetools loadables
1410 make_symlink "$GIT_BUILD_DIR"/mergetools "$GIT_VALGRIND/bin/mergetools"
1411 OLDIFS=$IFS
1412 IFS=:
1413 for path in $PATH
1414 do
1415 ls "$path"/git-* 2> /dev/null |
1416 while read file
1417 do
1418 make_valgrind_symlink "$file"
1419 done
1420 done
1421 IFS=$OLDIFS
1422 PATH=$GIT_VALGRIND/bin:$PATH
1423 GIT_EXEC_PATH=$GIT_VALGRIND/bin
1424 export GIT_VALGRIND
1425 GIT_VALGRIND_MODE="$valgrind"
1426 export GIT_VALGRIND_MODE
1427 GIT_VALGRIND_ENABLED=t
1428 test -n "$valgrind_only" && GIT_VALGRIND_ENABLED=
1429 export GIT_VALGRIND_ENABLED
1430 elif test -n "$GIT_TEST_INSTALLED"
1431 then
1432 GIT_EXEC_PATH=$($GIT_TEST_INSTALLED/git --exec-path) ||
1433 error "Cannot run git from $GIT_TEST_INSTALLED."
1434 PATH=$GIT_TEST_INSTALLED:$GIT_BUILD_DIR/t/helper:$PATH
1435 GIT_EXEC_PATH=${GIT_TEST_EXEC_PATH:-$GIT_EXEC_PATH}
1436 else # normal case, use ../bin-wrappers only unless $with_dashes:
1437 if test -n "$no_bin_wrappers"
1438 then
1439 with_dashes=t
1440 else
1441 git_bin_dir="$GIT_BUILD_DIR/bin-wrappers"
1442 if ! test -x "$git_bin_dir/git"
1443 then
1444 if test -z "$with_dashes"
1445 then
1446 say "$git_bin_dir/git is not executable; using GIT_EXEC_PATH"
1447 fi
1448 with_dashes=t
1449 fi
1450 PATH="$git_bin_dir:$PATH"
1451 fi
1452 GIT_EXEC_PATH=$GIT_BUILD_DIR
1453 if test -n "$with_dashes"
1454 then
1455 PATH="$GIT_BUILD_DIR:$GIT_BUILD_DIR/t/helper:$PATH"
1456 fi
1457 fi
1458 GIT_TEMPLATE_DIR="$GIT_TEST_TEMPLATE_DIR"
1459 GIT_CONFIG_NOSYSTEM=1
1460 GIT_ATTR_NOSYSTEM=1
1461 GIT_CEILING_DIRECTORIES="$TRASH_DIRECTORY/.."
1462 export PATH GIT_EXEC_PATH GIT_TEMPLATE_DIR GIT_CONFIG_NOSYSTEM GIT_ATTR_NOSYSTEM GIT_CEILING_DIRECTORIES
1463
1464 # Add libc MALLOC and MALLOC_PERTURB test only if we are not executing
1465 # the test with valgrind and have not compiled with conflict SANITIZE
1466 # options.
1467 if test -n "$valgrind" ||
1468 test -n "$SANITIZE_ADDRESS" ||
1469 test -n "$SANITIZE_LEAK" ||
1470 test -n "$TEST_NO_MALLOC_CHECK"
1471 then
1472 setup_malloc_check () {
1473 : nothing
1474 }
1475 teardown_malloc_check () {
1476 : nothing
1477 }
1478 else
1479 _USE_GLIBC_TUNABLES=
1480 _USE_GLIBC_PRELOAD=libc_malloc_debug.so.0
1481 if _GLIBC_VERSION=$(getconf GNU_LIBC_VERSION 2>/dev/null) &&
1482 _GLIBC_VERSION=${_GLIBC_VERSION#"glibc "} &&
1483 expr 2.34 \<= "$_GLIBC_VERSION" >/dev/null &&
1484 stderr=$(LD_PRELOAD=$_USE_GLIBC_PRELOAD git version 2>&1 >/dev/null) &&
1485 test -z "$stderr"
1486 then
1487 _USE_GLIBC_TUNABLES=YesPlease
1488 fi
1489 setup_malloc_check () {
1490 local g
1491 local t
1492 MALLOC_CHECK_=3 MALLOC_PERTURB_=165
1493 export MALLOC_CHECK_ MALLOC_PERTURB_
1494 if test -n "$_USE_GLIBC_TUNABLES"
1495 then
1496 g=
1497 LD_PRELOAD=$_USE_GLIBC_PRELOAD
1498 for t in \
1499 glibc.malloc.check=1 \
1500 glibc.malloc.perturb=165
1501 do
1502 g="${g#:}:$t"
1503 done
1504 GLIBC_TUNABLES=$g
1505 export LD_PRELOAD GLIBC_TUNABLES
1506 fi
1507 }
1508 teardown_malloc_check () {
1509 unset MALLOC_CHECK_ MALLOC_PERTURB_
1510 unset LD_PRELOAD GLIBC_TUNABLES
1511 }
1512 fi
1513
1514 if test -z "$GIT_TEST_CMP"
1515 then
1516 if test -n "$GIT_TEST_CMP_USE_COPIED_CONTEXT"
1517 then
1518 GIT_TEST_CMP="$DIFF -c"
1519 else
1520 GIT_TEST_CMP="$DIFF -u"
1521 fi
1522 fi
1523
1524 GITPERLLIB="$GIT_TEST_GITPERLLIB"
1525 export GITPERLLIB
1526 test -d "$GIT_TEMPLATE_DIR" || {
1527 BAIL_OUT "You haven't built things yet, have you?"
1528 }
1529
1530 if ! test -x "$GIT_BUILD_DIR"/t/helper/test-tool$X
1531 then
1532 BAIL_OUT 'You need to build test-tool; Run "make t/helper/test-tool" in the source (toplevel) directory'
1533 fi
1534
1535 if test -n "$HARNESS_ACTIVE"
1536 then
1537 say "TAP version 13"
1538 say "pragma +strict"
1539 fi
1540
1541 # Are we running this test at all?
1542 remove_trash=
1543 this_test=${0##*/}
1544 this_test=${this_test%%-*}
1545 if match_pattern_list "$this_test" "$GIT_SKIP_TESTS"
1546 then
1547 say_color info >&3 "skipping test $this_test altogether"
1548 skip_all="skip all tests in $this_test"
1549 test_done
1550 fi
1551
1552 if test -n "$SANITIZE_LEAK"
1553 then
1554 rm -rf "$TEST_RESULTS_SAN_DIR"
1555 if ! mkdir -p "$TEST_RESULTS_SAN_DIR"
1556 then
1557 BAIL_OUT "cannot create $TEST_RESULTS_SAN_DIR"
1558 fi &&
1559 TEST_RESULTS_SAN_FILE="$TEST_RESULTS_SAN_DIR/$TEST_RESULTS_SAN_FILE_PFX"
1560
1561 # Don't litter *.leak dirs if there was nothing to report
1562 test_atexit "rmdir \"$TEST_RESULTS_SAN_DIR\" 2>/dev/null || :"
1563
1564 prepend_var LSAN_OPTIONS : dedup_token_length=9999
1565 prepend_var LSAN_OPTIONS : log_exe_name=1
1566 prepend_var LSAN_OPTIONS : log_path="'$TEST_RESULTS_SAN_FILE'"
1567 export LSAN_OPTIONS
1568 fi
1569
1570 if test -z "$PERL_PATH"
1571 then
1572 case "${GIT_TEST_CHAIN_LINT:-unset}" in
1573 unset)
1574 GIT_TEST_CHAIN_LINT=0
1575 ;;
1576 0)
1577 # The user has explicitly disabled the chain linter, so we
1578 # don't have anything to worry about.
1579 ;;
1580 *)
1581 BAIL_OUT 'You need Perl for the chain linter'
1582 ;;
1583 esac
1584 fi
1585
1586 if test "${GIT_TEST_CHAIN_LINT:-1}" != 0 &&
1587 test "${GIT_TEST_EXT_CHAIN_LINT:-1}" != 0
1588 then
1589 "$PERL_PATH" "$TEST_DIRECTORY/chainlint.pl" "$0" ||
1590 BUG "lint error (see 'LINT' annotations above)"
1591 fi
1592
1593 # Last-minute variable setup
1594 USER_HOME="$HOME"
1595 HOME="$TRASH_DIRECTORY"
1596 GNUPGHOME="$HOME/gnupg-home-not-used"
1597 export HOME GNUPGHOME USER_HOME
1598
1599 # "rm -rf" existing trash directory, even if a previous run left it
1600 # with bad permissions.
1601 remove_trash_directory () {
1602 dir="$1"
1603 if ! rm -rf "$dir" 2>/dev/null
1604 then
1605 chmod -R u+rwx "$dir"
1606 rm -rf "$dir"
1607 fi
1608 ! test -d "$dir"
1609 }
1610
1611 # Test repository
1612 remove_trash_directory "$TRASH_DIRECTORY" || {
1613 BAIL_OUT 'cannot prepare test area'
1614 }
1615
1616 remove_trash=t
1617 if test -z "$TEST_NO_CREATE_REPO"
1618 then
1619 git init \
1620 ${TEST_CREATE_REPO_NO_TEMPLATE:+--template=} \
1621 "$TRASH_DIRECTORY" >&3 2>&4 ||
1622 error "cannot run git init"
1623 else
1624 mkdir -p "$TRASH_DIRECTORY"
1625 fi
1626
1627 # Use -P to resolve symlinks in our working directory so that the cwd
1628 # in subprocesses like git equals our $PWD (for pathname comparisons).
1629 cd -P "$TRASH_DIRECTORY" || BAIL_OUT "cannot cd -P to \"$TRASH_DIRECTORY\""
1630 TRASH_DIRECTORY=$(pwd)
1631 HOME="$TRASH_DIRECTORY"
1632
1633 if test -n "$WITH_BREAKING_CHANGES"
1634 then
1635 git config --global safe.bareRepository all &&
1636 # Only write to .git/info/exclude when the directory exists
1637 # (i.e. when git init created the repo). If we mkdir -p it
1638 # ourselves, tests that expect to create .git/info/ themselves
1639 # (e.g. t0008) would fail.
1640 if test -d .git/info
1641 then
1642 echo "/.gitconfig" >>.git/info/exclude
1643 fi
1644 fi
1645
1646 start_test_output "$0"
1647
1648 # Convenience
1649 # A regexp to match 5 and 35 hexdigits
1650 _x05='[0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f]'
1651 _x35="$_x05$_x05$_x05$_x05$_x05$_x05$_x05"
1652
1653 test_oid_init
1654
1655 ZERO_OID=$(test_oid zero)
1656 OID_REGEX=$(echo $ZERO_OID | sed -e 's/0/[0-9a-f]/g')
1657 OIDPATH_REGEX=$(test_oid_to_path $ZERO_OID | sed -e 's/0/[0-9a-f]/g')
1658 EMPTY_TREE=$(test_oid empty_tree)
1659 EMPTY_BLOB=$(test_oid empty_blob)
1660
1661 # Provide an implementation of the 'yes' utility; the upper bound
1662 # limit is there to help Windows that cannot stop this loop from
1663 # wasting cycles when the downstream stops reading, so do not be
1664 # tempted to turn it into an infinite loop. cf. 6129c930 ("test-lib:
1665 # limit the output of the yes utility", 2016-02-02)
1666 yes () {
1667 if test $# = 0
1668 then
1669 y=y
1670 else
1671 y="$*"
1672 fi
1673
1674 i=0
1675 while test $i -lt 99
1676 do
1677 echo "$y"
1678 i=$(($i+1))
1679 done
1680 }
1681
1682 # The GIT_TEST_FAIL_PREREQS code hooks into test_set_prereq(), and
1683 # thus needs to be set up really early, and set an internal variable
1684 # for convenience so the hot test_set_prereq() codepath doesn't need
1685 # to call "test-tool env-helper" (via test_bool_env). Only do that work
1686 # if needed by seeing if GIT_TEST_FAIL_PREREQS is set at all.
1687 GIT_TEST_FAIL_PREREQS_INTERNAL=
1688 if test -n "$GIT_TEST_FAIL_PREREQS"
1689 then
1690 if test_bool_env GIT_TEST_FAIL_PREREQS false
1691 then
1692 GIT_TEST_FAIL_PREREQS_INTERNAL=true
1693 test_set_prereq FAIL_PREREQS
1694 fi
1695 else
1696 test_lazy_prereq FAIL_PREREQS '
1697 test_bool_env GIT_TEST_FAIL_PREREQS false
1698 '
1699 fi
1700
1701 # Fix some commands on Windows, and other OS-specific things
1702 uname_s=$(uname -s)
1703 case $uname_s in
1704 Darwin)
1705 test_set_prereq MACOS
1706 test_set_prereq POSIXPERM
1707 test_set_prereq BSLASHPSPEC
1708 test_set_prereq EXECKEEPSPID
1709 ;;
1710 *MINGW*)
1711 # Windows has its own (incompatible) sort and find
1712 sort () {
1713 /usr/bin/sort "$@"
1714 }
1715 find () {
1716 /usr/bin/find "$@"
1717 }
1718 # git sees Windows-style pwd
1719 pwd () {
1720 builtin pwd -W
1721 }
1722 # no POSIX permissions
1723 # backslashes in pathspec are converted to '/'
1724 # exec does not inherit the PID
1725 test_set_prereq MINGW
1726 test_set_prereq NATIVE_CRLF
1727 test_set_prereq SED_STRIPS_CR
1728 test_set_prereq GREP_STRIPS_CR
1729 test_set_prereq WINDOWS
1730 GIT_TEST_CMP="GIT_DIR=/dev/null git diff --no-index --ignore-cr-at-eol --"
1731 ;;
1732 *CYGWIN*)
1733 test_set_prereq POSIXPERM
1734 test_set_prereq EXECKEEPSPID
1735 test_set_prereq CYGWIN
1736 test_set_prereq SED_STRIPS_CR
1737 test_set_prereq GREP_STRIPS_CR
1738 test_set_prereq WINDOWS
1739 ;;
1740 *)
1741 test_set_prereq POSIXPERM
1742 test_set_prereq BSLASHPSPEC
1743 test_set_prereq EXECKEEPSPID
1744 ;;
1745 esac
1746
1747 # Detect arches where a few things don't work
1748 uname_m=$(uname -m)
1749 case $uname_m in
1750 parisc* | hppa*)
1751 test_set_prereq HPPA
1752 ;;
1753 esac
1754
1755 case "$GIT_DEFAULT_REF_FORMAT" in
1756 files)
1757 test_set_prereq REFFILES;;
1758 reftable)
1759 test_set_prereq REFTABLE;;
1760 *)
1761 echo 2>&1 "error: unknown ref format $GIT_DEFAULT_REF_FORMAT"
1762 exit 1
1763 ;;
1764 esac
1765
1766 ( COLUMNS=1 && test $COLUMNS = 1 ) && test_set_prereq COLUMNS_CAN_BE_1
1767 test -z "$NO_CURL" && test_set_prereq LIBCURL
1768 test -z "$NO_GITWEB" && test_set_prereq GITWEB
1769 test -z "$NO_PERL" && test_set_prereq PERL
1770 test -z "$NO_PTHREADS" && test_set_prereq PTHREADS
1771 test -z "$NO_PYTHON" && test_set_prereq PYTHON
1772 test -n "$USE_LIBPCRE2" && test_set_prereq PCRE
1773 test -n "$USE_LIBPCRE2" && test_set_prereq LIBPCRE2
1774 test -z "$NO_GETTEXT" && test_set_prereq GETTEXT
1775 test -n "$SANITIZE_LEAK" && test_set_prereq SANITIZE_LEAK
1776 test -n "$GIT_VALGRIND_ENABLED" && test_set_prereq VALGRIND
1777 test -n "$PERL_PATH" && test_set_prereq PERL_TEST_HELPERS
1778
1779 test_lazy_prereq ICONV '
1780 # We require Git to be built with iconv support, and we require the
1781 # iconv binary to exist.
1782 #
1783 # NEEDSWORK: We might eventually want to split this up into two
1784 # prerequisites: one for NO_ICONV, and one for the iconv(1) binary, as
1785 # some tests only depend on either of these.
1786 test -z "$NO_ICONV" &&
1787 iconv -f utf8 -t utf8 </dev/null
1788 '
1789
1790 if test -z "$GIT_TEST_CHECK_CACHE_TREE"
1791 then
1792 GIT_TEST_CHECK_CACHE_TREE=true
1793 export GIT_TEST_CHECK_CACHE_TREE
1794 fi
1795
1796 test_lazy_prereq PIPE '
1797 # test whether the filesystem supports FIFOs
1798 test_have_prereq !MINGW,!CYGWIN &&
1799 rm -f testfifo && mkfifo testfifo
1800 '
1801
1802 test_lazy_prereq SYMLINKS '
1803 # test whether the filesystem supports symbolic links
1804 ln -s x y && test -h y
1805 '
1806
1807 test_lazy_prereq SYMLINKS_WINDOWS '
1808 # test whether symbolic links are enabled on Windows
1809 test_have_prereq MINGW &&
1810 cmd //c "mklink y x" &> /dev/null && test -h y
1811 '
1812
1813 test_lazy_prereq FILEMODE '
1814 test "$(git config --bool core.filemode)" = true
1815 '
1816
1817 test_lazy_prereq CASE_INSENSITIVE_FS '
1818 echo good >CamelCase &&
1819 echo bad >camelcase &&
1820 test "$(cat CamelCase)" != good
1821 '
1822
1823 test_lazy_prereq FUNNYNAMES '
1824 test_have_prereq !MINGW &&
1825 touch -- \
1826 "FUNNYNAMES tab embedded" \
1827 "FUNNYNAMES \"quote embedded\"" \
1828 "FUNNYNAMES newline
1829 embedded" 2>/dev/null &&
1830 rm -- \
1831 "FUNNYNAMES tab embedded" \
1832 "FUNNYNAMES \"quote embedded\"" \
1833 "FUNNYNAMES newline
1834 embedded" 2>/dev/null
1835 '
1836
1837 test_lazy_prereq UTF8_NFD_TO_NFC '
1838 # check whether FS converts nfd unicode to nfc
1839 auml=$(printf "\303\244")
1840 aumlcdiar=$(printf "\141\314\210")
1841 >"$auml" &&
1842 test -f "$aumlcdiar"
1843 '
1844
1845 test_lazy_prereq AUTOIDENT '
1846 sane_unset GIT_AUTHOR_NAME &&
1847 sane_unset GIT_AUTHOR_EMAIL &&
1848 git var GIT_AUTHOR_IDENT
1849 '
1850
1851 test_lazy_prereq EXPENSIVE '
1852 test_bool_env GIT_TEST_LONG false
1853 '
1854
1855 test_lazy_prereq EXPENSIVE_ON_WINDOWS '
1856 test_have_prereq EXPENSIVE || test_have_prereq !MINGW,!CYGWIN
1857 '
1858
1859 test_lazy_prereq USR_BIN_TIME '
1860 test -x /usr/bin/time
1861 '
1862
1863 test_lazy_prereq NOT_ROOT '
1864 uid=$(id -u) &&
1865 test "$uid" != 0
1866 '
1867
1868 test_lazy_prereq JGIT '
1869 jgit --version
1870 '
1871
1872 # SANITY is about "can you correctly predict what the filesystem would
1873 # do by only looking at the permission bits of the files and
1874 # directories?" A typical example of !SANITY is running the test
1875 # suite as root, where a test may expect "chmod -r file && cat file"
1876 # to fail because file is supposed to be unreadable after a successful
1877 # chmod. In an environment (i.e. combination of what filesystem is
1878 # being used and who is running the tests) that lacks SANITY, you may
1879 # be able to delete or create a file when the containing directory
1880 # doesn't have write permissions, or access a file even if the
1881 # containing directory doesn't have read or execute permissions.
1882
1883 test_lazy_prereq SANITY '
1884 mkdir SANETESTD.1 SANETESTD.2 &&
1885
1886 chmod +w SANETESTD.1 SANETESTD.2 &&
1887 >SANETESTD.1/x 2>SANETESTD.2/x &&
1888 chmod -w SANETESTD.1 &&
1889 chmod -r SANETESTD.1/x &&
1890 chmod -rx SANETESTD.2 ||
1891 BUG "cannot prepare SANETESTD"
1892
1893 ! test -r SANETESTD.1/x &&
1894 ! rm SANETESTD.1/x && ! test -f SANETESTD.2/x
1895 status=$?
1896
1897 chmod +rwx SANETESTD.1 SANETESTD.2 &&
1898 rm -rf SANETESTD.1 SANETESTD.2 ||
1899 BUG "cannot clean SANETESTD"
1900 return $status
1901 '
1902
1903 test FreeBSD != $uname_s || GIT_UNZIP=${GIT_UNZIP:-/usr/local/bin/unzip}
1904 GIT_UNZIP=${GIT_UNZIP:-unzip}
1905 test_lazy_prereq UNZIP '
1906 "$GIT_UNZIP" -v
1907 test $? -ne 127
1908 '
1909
1910 run_with_limited_cmdline () {
1911 (ulimit -s 128 && "$@")
1912 }
1913
1914 test_lazy_prereq CMDLINE_LIMIT '
1915 test_have_prereq !HPPA,!MINGW,!CYGWIN &&
1916 run_with_limited_cmdline true
1917 '
1918
1919 run_with_limited_stack () {
1920 (ulimit -s 128 && "$@")
1921 }
1922
1923 test_lazy_prereq ULIMIT_STACK_SIZE '
1924 test_have_prereq !HPPA,!MINGW,!CYGWIN &&
1925 run_with_limited_stack true
1926 '
1927
1928 run_with_limited_open_files () {
1929 (ulimit -n 32 && "$@")
1930 }
1931
1932 test_lazy_prereq ULIMIT_FILE_DESCRIPTORS '
1933 test_have_prereq !MINGW,!CYGWIN &&
1934 run_with_limited_open_files true
1935 '
1936
1937 build_option () {
1938 git version --build-options |
1939 sed -ne "s/^$1: //p"
1940 }
1941
1942 test_lazy_prereq SIZE_T_IS_64BIT '
1943 test 8 -eq "$(build_option sizeof-size_t)"
1944 '
1945
1946 test_lazy_prereq LONG_IS_64BIT '
1947 test 8 -le "$(build_option sizeof-long)"
1948 '
1949
1950 test_lazy_prereq RUST '
1951 test "$(build_option rust)" = enabled
1952 '
1953
1954 test_lazy_prereq TIME_IS_64BIT 'test-tool date is64bit'
1955 test_lazy_prereq TIME_T_IS_64BIT 'test-tool date time_t-is64bit'
1956
1957 test_lazy_prereq CURL '
1958 curl --version
1959 '
1960
1961 test_lazy_prereq WITH_BREAKING_CHANGES '
1962 test -n "$WITH_BREAKING_CHANGES"
1963 '
1964
1965 test_lazy_prereq WITHOUT_BREAKING_CHANGES '
1966 # Signal that this prereq should not be used.
1967 exit 125
1968 '
1969
1970 # SHA1 is a test if the hash algorithm in use is SHA-1. This is both for tests
1971 # which will not work with other hash algorithms and tests that work but don't
1972 # test anything meaningful (e.g. special values which cause short collisions).
1973 test_lazy_prereq SHA1 '
1974 case "$GIT_DEFAULT_HASH" in
1975 sha1) true ;;
1976 "") test $(git hash-object /dev/null) = e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 ;;
1977 *) false ;;
1978 esac
1979 '
1980
1981 test_lazy_prereq DEFAULT_HASH_ALGORITHM '
1982 test "$GIT_TEST_BUILTIN_HASH" = "$GIT_DEFAULT_HASH"
1983 '
1984
1985 test_lazy_prereq DEFAULT_REPO_FORMAT '
1986 test_have_prereq SHA1,REFFILES
1987 '
1988 # BROKEN_OBJECTS is a test whether we can write deliberately broken objects and
1989 # expect them to work. When running using SHA-256 mode with SHA-1
1990 # compatibility, we cannot write such objects because there's no SHA-1
1991 # compatibility value for a nonexistent object.
1992 test_lazy_prereq BROKEN_OBJECTS '
1993 ! test_have_prereq COMPAT_HASH
1994 '
1995
1996 # COMPAT_HASH is a test if we're operating in a repository with SHA-256 with
1997 # SHA-1 compatibility.
1998 test_lazy_prereq COMPAT_HASH '
1999 test -n "$test_repo_compat_hash_algo"
2000 '
2001
2002 # Ensure that no test accidentally triggers a Git command
2003 # that runs the actual maintenance scheduler, affecting a user's
2004 # system permanently.
2005 # Tests that verify the scheduler integration must set this locally
2006 # to avoid errors.
2007 GIT_TEST_MAINT_SCHEDULER="none:exit 1"
2008 export GIT_TEST_MAINT_SCHEDULER
2009
2010 # Ensure that tests cannot race with background maintenance by default.
2011 GIT_TEST_MAINT_AUTO_DETACH="false"
2012 export GIT_TEST_MAINT_AUTO_DETACH
2013
2014 # Does this platform support `git fsmonitor--daemon`
2015 #
2016 test_lazy_prereq FSMONITOR_DAEMON '
2017 git version --build-options >output &&
2018 grep "feature: fsmonitor--daemon" output
2019 '