1 # Test framework for git, adapted for StGit. See t/README for usage.
3 # Copyright (c) 2005 Junio C Hamano
4 # Copyright (c) 2006 Yann Dirson - tuning for stgit
6 # This program is free software: you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation, either version 2 of the License, or
9 # (at your option) any later version.
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program. If not, see http://www.gnu.org/licenses/ .
19 # Test the binaries we have just built. The tests are kept in
20 # t/ subdirectory and are run in 'trash directory' subdirectory.
21 if test -z "$TEST_DIRECTORY"
23 # We allow tests to override this, in case they want to run tests
24 # outside of t/, e.g. for running tests on the test library
28 # ensure that TEST_DIRECTORY is an absolute path so that it
29 # is valid even if the current working directory is changed
30 TEST_DIRECTORY
=$
(cd "$TEST_DIRECTORY" && pwd) ||
exit 1
32 if test -z "$TEST_OUTPUT_DIRECTORY"
34 # Similarly, override this to store the test-results subdir
36 TEST_OUTPUT_DIRECTORY
=$TEST_DIRECTORY
38 STG_ROOT
=$
(cd "$TEST_DIRECTORY"/..
&& pwd) ||
exit 1
41 PERL_PATH
=${PERL:-perl}
42 SHELL_PATH
=${SHELL_PATH:-/bin/sh}
43 TEST_SHELL_PATH
=${TEST_SHELL_PATH:-$SHELL_PATH}
44 export PERL_PATH SHELL_PATH
48 # In t0000, we need to override test directories of nested testcases. In case
49 # the developer has TEST_OUTPUT_DIRECTORY part of his build options, then we'd
50 # reset this value to instead contain what the developer has specified. We thus
51 # have this knob to allow overriding the directory.
52 if test -n "${TEST_OUTPUT_DIRECTORY_OVERRIDE}"
54 TEST_OUTPUT_DIRECTORY
="${TEST_OUTPUT_DIRECTORY_OVERRIDE}"
57 # Explicitly set the default branch name for testing, to avoid the
58 # transitory "git init" warning under --verbose.
59 : ${GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME:=master}
60 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
65 # $2: name of the var where the arg will be stored
66 mark_option_requires_arg
() {
67 if test -n "$opt_required_arg"
69 echo "error: options that require args cannot be bundled" \
70 "together: '$opt_required_arg' and '$1'" >&2
81 -d|
--d|
--de|
--deb|
--debu|
--debug)
83 -i|
--i|
--im|
--imm|
--imme|
--immed|
--immedi|
--immedia|
--immediat|
--immediate)
85 -l|
--l|
--lo|
--lon|
--long|
--long-|
--long-t|
--long-te|
--long-tes|
--long-test|
--long-tests)
86 GIT_TEST_LONG
=t
; export GIT_TEST_LONG
;;
88 mark_option_requires_arg
"$opt" run_list
91 run_list
=${opt#--*=} ;;
92 -h|
--h|
--he|
--hel|
--help)
94 -v|
--v|
--ve|
--ver|
--verb|
--verbo|
--verbos|
--verbose)
98 verbose_only
=${opt#--*=}
100 -q|
--q|
--qu|
--qui|
--quie|
--quiet)
101 # Ignore --quiet under a TAP::Harness. Saying how many tests
102 # passed without the ok/not ok details is always an error.
103 test -z "$HARNESS_ACTIVE" && quiet
=t
;;
122 echo "error: --stress does not accept an argument: '$opt'" >&2
123 echo "did you mean --stress-jobs=${opt#*=} or --stress-limit=${opt#*=}?" >&2
128 stress_jobs
=${opt#--*=}
129 case "$stress_jobs" in
131 echo "error: --stress-jobs=<N> requires the number of jobs to run" >&2
140 stress_limit
=${opt#--*=}
141 case "$stress_limit" in
143 echo "error: --stress-limit=<N> requires the number of repetitions" >&2
151 echo "error: unknown test option '$opt'" >&2; exit 1 ;;
155 # Parse options while taking care to leave $@ intact, so we will still
156 # have all the original command line options when executing the test
157 # script again for '--tee' and '--verbose-log' later.
160 if test -n "$store_arg_to"
162 eval $store_arg_to=\
$opt
170 parse_option
"$opt" ;;
172 # bundled short options must be fed separately to parse_option
179 parse_option
"-$this"
183 echo "error: unknown test option '$opt'" >&2; exit 1 ;;
186 if test -n "$store_arg_to"
188 echo "error: $opt_required_arg requires an argument" >&2
200 TEST_STRESS_JOB_SFX
="${GIT_TEST_STRESS_JOB_NR:+.stress-$GIT_TEST_STRESS_JOB_NR}"
201 TEST_NAME
="$(basename "$0" .sh)"
202 TEST_NUMBER
="${TEST_NAME%%-*}"
203 TEST_NUMBER
="${TEST_NUMBER#t}"
204 TEST_RESULTS_DIR
="$TEST_OUTPUT_DIRECTORY/test-results"
205 TEST_RESULTS_BASE
="$TEST_RESULTS_DIR/$TEST_NAME$TEST_STRESS_JOB_SFX"
206 TRASH_DIRECTORY
="trash directory.$TEST_NAME$TEST_STRESS_JOB_SFX"
207 test -n "$root" && TRASH_DIRECTORY
="$root/$TRASH_DIRECTORY"
208 case "$TRASH_DIRECTORY" in
209 /*) ;; # absolute path is good
210 *) TRASH_DIRECTORY
="$TEST_OUTPUT_DIRECTORY/$TRASH_DIRECTORY" ;;
213 # If --stress was passed, run this test repeatedly in several parallel loops.
214 if test "$GIT_TEST_STRESS_STARTED" = "done"
216 : # Don't stress test again.
217 elif test -n "$stress"
219 if test -n "$stress_jobs"
221 job_count
=$stress_jobs
222 elif test -n "$GIT_TEST_STRESS_LOAD"
224 job_count
="$GIT_TEST_STRESS_LOAD"
225 elif job_count
=$
(getconf _NPROCESSORS_ONLN
2>/dev
/null
) &&
228 job_count
=$
((2 * $job_count))
233 mkdir
-p "$TEST_RESULTS_DIR"
234 stressfail
="$TEST_RESULTS_BASE.stress-failed"
239 kill $job_pids 2>/dev/null
246 while test $job_nr -lt "$job_count"
249 GIT_TEST_STRESS_STARTED
=done
250 GIT_TEST_STRESS_JOB_NR
=$job_nr
251 export GIT_TEST_STRESS_STARTED GIT_TEST_STRESS_JOB_NR
254 kill $test_pid 2>/dev/null
260 while ! test -e "$stressfail" &&
261 { test -z "$stress_limit" ||
262 test $cnt -le $stress_limit ; }
264 $TEST_SHELL_PATH "$0" "$@" >"$TEST_RESULTS_BASE.stress-$job_nr.out" 2>&1 &
269 printf "OK %2d.%d\n" $GIT_TEST_STRESS_JOB_NR $cnt
271 echo $GIT_TEST_STRESS_JOB_NR >>"$stressfail"
272 printf "FAIL %2d.%d\n" $GIT_TEST_STRESS_JOB_NR $cnt
277 job_pids
="$job_pids $!"
278 job_nr
=$
(($job_nr + 1))
283 if test -f "$stressfail"
286 echo "Log(s) of failed test run(s):"
287 for failed_job_nr
in $
(sort -n "$stressfail")
289 echo "Contents of '$TEST_RESULTS_BASE.stress-$failed_job_nr.out':"
290 cat "$TEST_RESULTS_BASE.stress-$failed_job_nr.out"
292 rm -rf "$TRASH_DIRECTORY.stress-failed"
294 mv "$TRASH_DIRECTORY.stress-$failed_job_nr" "$TRASH_DIRECTORY.stress-failed"
300 # if --tee was passed, write the output not only to the terminal, but
301 # additionally to the file test-results/$BASENAME.out, too.
302 if test "$GIT_TEST_TEE_STARTED" = "done"
304 : # do not redirect again
307 mkdir
-p "$TEST_RESULTS_DIR"
309 # Make this filename available to the sub-process in case it is using
311 GIT_TEST_TEE_OUTPUT_FILE
=$TEST_RESULTS_BASE.out
312 export GIT_TEST_TEE_OUTPUT_FILE
314 # Truncate before calling "tee -a" to get rid of the results
315 # from any previous runs.
316 >"$GIT_TEST_TEE_OUTPUT_FILE"
318 (GIT_TEST_TEE_STARTED
=done ${TEST_SHELL_PATH} "$0" "$@" 2>&1;
319 echo $?
>"$TEST_RESULTS_BASE.exit") |
tee -a "$GIT_TEST_TEE_OUTPUT_FILE"
320 test "$(cat "$TEST_RESULTS_BASE.
exit")" = 0
324 if test -n "$trace" && test -n "$test_untraceable"
326 # '-x' tracing requested, but this test script can't be reliably
327 # traced, unless it is run with a Bash version supporting
328 # BASH_XTRACEFD (introduced in Bash v4.1).
330 # Perform this version check _after_ the test script was
331 # potentially re-executed with $TEST_SHELL_PATH for '--tee' or
332 # '--verbose-log', so the right shell is checked and the
333 # warning is issued only once.
334 if test -n "$BASH_VERSION" && eval '
335 test ${BASH_VERSINFO[0]} -gt 4 || {
336 test ${BASH_VERSINFO[0]} -eq 4 &&
337 test ${BASH_VERSINFO[1]} -ge 1
341 : Executed by a Bash version supporting BASH_XTRACEFD. Good.
343 echo >&2 "warning: ignoring -x; '$0' is untraceable without BASH_XTRACEFD"
347 if test -n "$trace" && test -z "$verbose_log"
353 # Since bash 5.0, checkwinsize is enabled by default which does
354 # update the COLUMNS variable every time a non-builtin command
355 # completes, even for non-interactive shells.
356 # Disable that since we are aiming for repeatability.
357 test -n "$BASH_VERSION" && shopt -u checkwinsize
2>/dev
/null
359 export STGIT_DEBUG_LEVEL
361 # For repeatability, reset the environment to known value.
362 # TERM is sanitized below, after saving color control sequences.
363 LANG
=${STG_TEST_LANG:-C}
368 export LANG LC_ALL PAGER TZ COLUMNS
371 # A call to "unset" with no arguments causes at least Solaris 10
372 # /usr/xpg4/bin/sh and /bin/ksh to bail out. So keep the unsets
373 # deriving from the command substitution clustered with the other
375 unset VISUAL EMAIL LANGUAGE $
("$PERL_PATH" -e '
377 my $ok = join("|", qw(
389 my @vars = grep(/^GIT_/ && !/^GIT_($ok)/o, @env);
390 print join("\n", @vars);
393 unset XDG_CONFIG_HOME
395 TEST_AUTHOR_LOCALNAME
=author
396 TEST_AUTHOR_DOMAIN
=example.com
397 GIT_AUTHOR_EMAIL
=${TEST_AUTHOR_LOCALNAME}@
${TEST_AUTHOR_DOMAIN}
398 GIT_AUTHOR_NAME
='A Ú Thor'
399 TEST_COMMITTER_LOCALNAME
=committer
400 TEST_COMMITTER_DOMAIN
=example.com
401 GIT_COMMITTER_EMAIL
=${TEST_COMMITTER_LOCALNAME}@
${TEST_COMMITTER_DOMAIN}
402 GIT_COMMITTER_NAME
='C Ó Mitter'
403 GIT_MERGE_VERBOSITY
=5
404 GIT_MERGE_AUTOEDIT
=no
405 export GIT_MERGE_VERBOSITY GIT_MERGE_AUTOEDIT
406 export GIT_AUTHOR_EMAIL GIT_AUTHOR_NAME
407 export GIT_COMMITTER_EMAIL GIT_COMMITTER_NAME
410 GIT_DEFAULT_HASH
="${GIT_TEST_DEFAULT_HASH:-sha1}"
411 export GIT_DEFAULT_HASH
412 GIT_TEST_MERGE_ALGORITHM
="${GIT_TEST_MERGE_ALGORITHM:-ort}"
413 export GIT_TEST_MERGE_ALGORITHM
415 # Tests using GIT_TRACE typically don't want <timestamp> <file>:<line> output
417 export GIT_TRACE_BARE
419 # Use specific version of the index file format
420 if test -n "${GIT_TEST_INDEX_VERSION:+isset}"
422 GIT_INDEX_VERSION
="$GIT_TEST_INDEX_VERSION"
423 export GIT_INDEX_VERSION
426 if test -n "$GIT_TEST_PERL_FATAL_WARNINGS"
428 GIT_PERL_FATAL_WARNINGS
=1
429 export GIT_PERL_FATAL_WARNINGS
432 # Protect ourselves from common misconfiguration to export
433 # CDPATH into the environment
439 case $
(echo $GIT_TRACE |
tr "[A-Z]" "[a-z]") in
452 # UTF-8 ZERO WIDTH NON-JOINER, which HFS+ ignores
453 # when case-folding filenames
454 u200c
=$
(printf '\342\200\214')
456 export _x05 _x35 LF u200c EMPTY_TREE EMPTY_BLOB ZERO_OID OID_REGEX
458 # Each test should start with something like this, after copyright notices:
460 # test_description='Description of this test...
461 # This test checks if command xyzzy does the right thing...
464 test "x$TERM" != "xdumb" && (
466 tput bold
>/dev
/null
2>&1 &&
467 tput setaf
1 >/dev
/null
2>&1 &&
468 tput sgr0
>/dev
/null
2>&1
474 # Save the color control sequences now rather than run tput
475 # each time say_color() is called. This is done for two
477 # * TERM will be changed to dumb
478 # * HOME will be changed to a temporary directory and tput
479 # might need to read ~/.terminfo from the original HOME
480 # directory to get the control sequences
481 # Note: This approach assumes the control sequences don't end
482 # in a newline for any terminal of interest (command
483 # substitutions strip trailing newlines). Given that most
484 # (all?) terminals in common use are related to ECMA-48, this
485 # shouldn't be a problem.
486 say_color_error
=$
(tput bold
; tput setaf
1) # bold red
487 say_color_skip
=$
(tput setaf
4) # blue
488 say_color_warn
=$
(tput setaf
3) # brown/yellow
489 say_color_pass
=$
(tput setaf
2) # green
490 say_color_info
=$
(tput setaf
6) # cyan
491 say_color_reset
=$
(tput sgr0
)
492 say_color_
="" # no formatting for normal text
494 test -z "$1" && test -n "$quiet" && return
495 eval "say_color_color=\$say_color_$1"
497 printf "%s\\n" "$say_color_color$*$say_color_reset"
501 test -z "$1" && test -n "$quiet" && return
509 export TERM USER_TERM
518 say_color error
"error: $*"
523 error
>&7 "bug in the test script: $*"
527 test $# -ne 1 && BUG
"1 param"
529 # Do not change "Bail out! " string. It's part of TAP syntax:
530 # https://testanything.org/tap-specification.html
531 local bail_out
="Bail out! "
534 say_color error
$bail_out "$message"
542 if test -n "$HARNESS_ACTIVE"
544 if test "$verbose" = t ||
test -n "$verbose_only"
546 BAIL_OUT
'verbose mode forbidden under TAP harness; try --verbose-log'
550 test "${test_description}" != "" ||
551 error
"Test script did not set test_description."
553 if test "$help" = "t"
555 printf '%s\n' "$test_description"
562 if test "$verbose_log" = "t"
564 exec 3>>"$GIT_TEST_TEE_OUTPUT_FILE" 4>&3
565 elif test "$verbose" = "t"
569 exec 4>/dev
/null
3>/dev
/null
572 # Send any "-x" output directly to stderr to avoid polluting tests
573 # which capture stderr. We can do this unconditionally since it
574 # has no effect if tracing isn't turned on.
576 # Note that this sets up the trace fd as soon as we assign the variable, so it
577 # must come after the creation of descriptor 4 above. Likewise, we must never
578 # unset this, as it has the side effect of closing descriptor 4, which we
579 # use to show verbose tests to the user.
581 # Note also that we don't need or want to export it. The tracing is local to
582 # this shell, and we would not want to influence any shells we exec.
591 test_external_has_tap
=0
595 # This is responsible for running the atexit commands even when a
596 # test script run with '--immediate' fails, or when the user hits
597 # ctrl-C, i.e. when 'test_done' is not invoked at all.
598 test_atexit_handler || code
=$?
599 if test -n "$GIT_EXIT_OK"
603 echo >&5 "FATAL: Unexpected exit with code $code"
610 # Disable '-x' tracing, because with some shells, notably dash, it
611 # prevents running the cleanup commands when a test script run with
612 # '--verbose-log -x' is interrupted.
613 trap '{ code=$?; set +x; } 2>/dev/null; exit $code' INT TERM HUP
615 # The user-facing functions are loaded from a separate file so that
616 # test_perf subshells can have them too
617 .
"$TEST_DIRECTORY/test-lib-functions.sh"
619 # You are not expected to call test_ok_ and test_failure_ directly, use
620 # the test_expect_* functions instead.
623 if test -n "$write_junit_xml"
625 write_junit_xml_testcase
"$*"
627 test_success
=$
(($test_success + 1))
628 say_color
"" "ok $test_count - $@"
632 if test -n "$write_junit_xml"
634 junit_insert
="<failure message=\"not ok $test_count -"
635 junit_insert
="$junit_insert $(xml_attr_encode "$1")\">"
636 junit_insert
="$junit_insert $(xml_attr_encode \
637 "$
(if test -n "$GIT_TEST_TEE_OUTPUT_FILE"
639 test-tool path-utils skip-n-bytes \
640 "$GIT_TEST_TEE_OUTPUT_FILE" $GIT_TEST_TEE_OFFSET
642 printf '%s\n' "$@" |
sed 1d
644 junit_insert
="$junit_insert</failure>"
645 if test -n "$GIT_TEST_TEE_OUTPUT_FILE"
647 junit_insert
="$junit_insert<system-err>$(xml_attr_encode \
648 "$
(cat "$GIT_TEST_TEE_OUTPUT_FILE")")</system-err>"
650 write_junit_xml_testcase
"$1" " $junit_insert"
652 test_failure
=$
(($test_failure + 1))
653 say_color error
"not ok $test_count - $1"
655 printf '%s\n' "$*" |
sed -e 's/^/# /'
656 test "$immediate" = "" || _error_exit
659 test_known_broken_ok_
() {
660 if test -n "$write_junit_xml"
662 write_junit_xml_testcase
"$* (breakage fixed)"
664 test_fixed
=$
(($test_fixed+1))
665 say_color error
"ok $test_count - $@ # TODO known breakage vanished"
668 test_known_broken_failure_
() {
669 if test -n "$write_junit_xml"
671 write_junit_xml_testcase
"$* (known breakage)"
673 test_broken
=$
(($test_broken+1))
674 say_color warn
"not ok $test_count - $@ # TODO known breakage"
678 test "$debug" = "" ||
eval "$1"
681 match_pattern_list
() {
684 test -z "$*" && return 1
685 # We need to use "$*" to get field-splitting, but we want to
686 # disable globbing, since we are matching against an arbitrary
687 # $arg, not what's in the filesystem. Using "set -f" accomplishes
688 # that, but we must do it in a subshell to avoid impacting the
689 # rest of the script. The exit value of the subshell becomes
690 # the function's return value.
705 match_test_selector_list
() {
712 test -z "$1" && return 0
714 # Commas are accepted as separators.
720 # If the first selector is negative we include by default.
728 orig_selector
=$selector
734 selector
=${selector##?}
738 test -z "$selector" && continue
742 if expr "z${selector%%-*}" : "z[0-9]*[^0-9]" >/dev
/null
744 echo "error: $operation: invalid non-numeric in range" \
745 "start: '$orig_selector'" >&2
748 if expr "z${selector#*-}" : "z[0-9]*[^0-9]" >/dev
/null
750 echo "error: $operation: invalid non-numeric in range" \
751 "end: '$orig_selector'" >&2
756 if expr "z$selector" : "z[0-9]*[^0-9]" >/dev
/null
758 case "$title" in *${selector}*)
766 # Short cut for "obvious" cases
767 test -z "$include" && test -z "$positive" && continue
768 test -n "$include" && test -n "$positive" && continue
772 if test $arg -le ${selector#-}
778 if test $arg -ge ${selector%-}
784 if test ${selector%%-*} -le $arg \
785 && test $arg -le ${selector#*-}
791 if test $arg -eq $selector
802 maybe_teardown_verbose
() {
803 test -z "$verbose_only" && return
804 exec 4>/dev
/null
3>/dev
/null
809 maybe_setup_verbose
() {
810 test -z "$verbose_only" && return
811 if match_pattern_list
$test_count "$verbose_only"
814 # Emit a delimiting blank line when going from
815 # non-verbose to verbose. Within verbose mode the
816 # delimiter is printed by test_expect_*. The choice
817 # of the initial $last_verbose is such that before
818 # test 1, we do not print it.
819 test -z "$last_verbose" && echo >&3 ""
822 exec 4>/dev
/null
3>/dev
/null
825 last_verbose
=$verbose
830 test "$trace" = t
&& {
831 test "$verbose" = t ||
test "$verbose_log" = t
835 # This is a separate function because some tests use
836 # "return" to end a test_expect_success block early
837 # (and we want to make sure we run any cleanup like
839 test_eval_inner_
() {
840 # Do not add anything extra (including LF) after '$*'
842 want_trace && trace_level_=$(($trace_level_+1)) && set -x
847 # If "-x" tracing is in effect, then we want to avoid polluting stderr
848 # with non-test commands. But once in "set -x" mode, we cannot prevent
849 # the shell from printing the "set +x" to turn it off (nor the saving
850 # of $? before that). But we can make sure that the output goes to
853 # There are a few subtleties here:
855 # - we have to redirect descriptor 4 in addition to 2, to cover
858 # - the actual eval has to come before the redirection block (since
859 # it needs to see descriptor 4 to set up its stderr)
861 # - likewise, any error message we print must be outside the block to
862 # access descriptor 4
864 # - checking $? has to come immediately after the eval, but it must
865 # be _inside_ the block to avoid polluting the "set -x" output
868 test_eval_inner_
"$@" </dev
/null
>&3 2>&4
873 test 1 = $trace_level_ && set +x
874 trace_level_
=$
(($trace_level_-1))
878 if test "$test_eval_ret_" != 0 && want_trace
880 say_color error
>&4 "error: last command exited with \$?=$test_eval_ret_"
882 return $test_eval_ret_
892 if test -z "$immediate" ||
test $eval_ret = 0 ||
893 test -n "$expecting_failure" && test "$test_cleanup" != ":"
895 test_eval_
"$test_cleanup"
897 if test "$verbose" = "t" && test -n "$HARNESS_ACTIVE"
905 test_count
=$
(($test_count+1))
907 if test -n "$write_junit_xml"
909 junit_start
=$
(test-tool
date getnanos
)
915 maybe_teardown_verbose
916 if test -n "$GIT_TEST_TEE_OFFSET"
918 GIT_TEST_TEE_OFFSET
=$
(test-tool path-utils file-size \
919 "$GIT_TEST_TEE_OUTPUT_FILE")
926 if match_pattern_list
$this_test.
$test_count $STG_SKIP_TESTS
929 skipped_reason
="STG_SKIP_TESTS"
931 if test -z "$to_skip" && test -n "$run_list" &&
932 ! match_test_selector_list
'--run' "$1" $test_count "$run_list"
935 skipped_reason
="--run"
937 if test -z "$to_skip" && test -n "$test_prereq" &&
938 ! test_have_prereq
"$test_prereq"
943 if test "$missing_prereq" != "$test_prereq"
945 of_prereq
=" of $test_prereq"
947 skipped_reason
="missing $missing_prereq${of_prereq}"
952 if test -n "$write_junit_xml"
954 message
="$(xml_attr_encode "$skipped_reason")"
955 write_junit_xml_testcase
"$1" \
956 " <skipped message=\"$message\" />"
959 say_color skip
"ok $test_count # skip $1 ($skipped_reason)"
968 # stub; perf-lib overrides it
969 test_at_end_hook_
() {
981 printf '%s\n' "$@" >>"$junit_xml_path"
985 printf '%s\n' "$@" | test-tool xml-encode
988 write_junit_xml_testcase
() {
989 junit_attrs
="name=\"$(xml_attr_encode "$this_test.
$test_count $1")\""
991 junit_attrs
="$junit_attrs classname=\"$this_test\""
992 junit_attrs
="$junit_attrs time=\"$(test-tool \
993 date getnanos $junit_start)\""
994 write_junit_xml
"$(printf '%s\n' \
995 " <testcase
$junit_attrs>" "$@
" " </testcase
>")"
996 junit_have_testcase
=t
999 finalize_junit_xml
() {
1000 if test -n "$write_junit_xml" && test -n "$junit_xml_path"
1002 test -n "$junit_have_testcase" ||
{
1003 junit_start
=$
(test-tool
date getnanos
)
1004 write_junit_xml_testcase
"all tests skipped"
1007 # adjust the overall time
1008 junit_time
=$
(test-tool
date getnanos
$junit_suite_start)
1009 sed -e "s/\(<testsuite.*\) time=\"[^\"]*\"/\1/" \
1010 -e "s/<testsuite [^>]*/& time=\"$junit_time\"/" \
1011 -e '/^ *<\/testsuite/d' \
1012 <"$junit_xml_path" >"$junit_xml_path.new"
1013 mv "$junit_xml_path.new" "$junit_xml_path"
1015 write_junit_xml
" </testsuite>" "</testsuites>"
1020 test_atexit_cleanup
=:
1021 test_atexit_handler
() {
1022 # In a succeeding test script 'test_atexit_handler' is invoked
1023 # twice: first from 'test_done', then from 'die' in the trap on
1025 # This condition and resetting 'test_atexit_cleanup' below makes
1026 # sure that the registered cleanup commands are run only once.
1027 test : != "$test_atexit_cleanup" ||
return 0
1029 test_eval_
"$test_atexit_cleanup"
1030 test_atexit_cleanup
=:
1036 # Run the atexit commands _before_ the trash directory is
1037 # removed, so the commands can access pidfiles and socket files.
1042 if test -z "$HARNESS_ACTIVE"
1044 mkdir
-p "$TEST_RESULTS_DIR"
1046 cat >"$TEST_RESULTS_BASE.counts" <<-EOF
1048 success $test_success
1051 failed $test_failure
1056 if test "$test_fixed" != 0
1058 say_color error
"# $test_fixed known breakage(s) vanished; please update test(s)"
1060 if test "$test_broken" != 0
1062 say_color warn
"# still have $test_broken known breakage(s)"
1064 if test "$test_broken" != 0 ||
test "$test_fixed" != 0
1066 test_remaining
=$
(( $test_count - $test_broken - $test_fixed ))
1067 msg
="remaining $test_remaining test(s)"
1069 test_remaining
=$test_count
1070 msg
="$test_count test(s)"
1072 case "$test_failure" in
1074 if test $test_external_has_tap -eq 0
1076 if test $test_remaining -gt 0
1078 say_color pass
"# passed all $msg"
1081 # Maybe print SKIP message
1082 test -z "$skip_all" || skip_all
="# SKIP $skip_all"
1083 case "$test_count" in
1085 say
"1..$test_count${skip_all:+ $skip_all}"
1088 test -z "$skip_all" ||
1089 say_color warn
"$skip_all"
1090 say
"1..$test_count"
1095 if test -z "$debug" && test -n "$remove_trash"
1097 test -d "$TRASH_DIRECTORY" ||
1098 error
"Tests passed but trash directory already removed before test cleanup; aborting"
1100 cd "$TRASH_DIRECTORY/.." &&
1101 rm -fr "$TRASH_DIRECTORY" ||
{
1102 # try again in a bit
1104 rm -fr "$TRASH_DIRECTORY"
1106 error
"Tests passed but test cleanup failed; aborting"
1113 if test $test_external_has_tap -eq 0
1115 say_color error
"# failed $test_failure among $msg"
1116 say
"1..$test_count"
1124 if test -n "$STG_TEST_INSTALLED"
1126 PATH
=$STG_TEST_INSTALLED:$PATH
1128 PATH
="$TEST_DIRECTORY/test-bin:$PATH"
1129 PYTHONPATH
="$STG_ROOT":"$PYTHONPATH"
1131 GIT_EXEC_PATH
=$
(git
--exec-path) || error
"Cannot run git"
1132 unset GIT_TEMPLATE_DIR
1133 GIT_CONFIG_NOSYSTEM
=1
1135 GIT_CEILING_DIRECTORIES
="$TRASH_DIRECTORY/.."
1136 export PATH GIT_EXEC_PATH GIT_CONFIG_NOSYSTEM GIT_ATTR_NOSYSTEM GIT_CEILING_DIRECTORIES PYTHONPATH
1138 if test -z "$GIT_TEST_CMP"
1140 DIFF
="${DIFF:-diff}"
1141 if test -n "$GIT_TEST_CMP_USE_COPIED_CONTEXT"
1143 GIT_TEST_CMP
="$DIFF -c"
1145 GIT_TEST_CMP
="$DIFF -u"
1149 # Are we running this test at all?
1152 this_test
=${this_test%%-*}
1153 if match_pattern_list
"$this_test" "$STG_SKIP_TESTS"
1155 say_color info
>&3 "skipping test $this_test altogether"
1156 skip_all
="skip all tests in $this_test"
1160 # skip non-whitelisted tests when compiled with SANITIZE=leak
1161 if test -n "$SANITIZE_LEAK"
1163 if test_bool_env GIT_TEST_PASSING_SANITIZE_LEAK false
1165 # We need to see it in "git env--helper" (via
1167 export TEST_PASSES_SANITIZE_LEAK
1169 if ! test_bool_env TEST_PASSES_SANITIZE_LEAK false
1171 skip_all
="skipping $this_test under GIT_TEST_PASSING_SANITIZE_LEAK=true"
1175 elif test_bool_env GIT_TEST_PASSING_SANITIZE_LEAK false
1177 BAIL_OUT
"GIT_TEST_PASSING_SANITIZE_LEAK=true has no effect except when compiled with SANITIZE=leak"
1180 # Last-minute variable setup
1182 HOME
="$TRASH_DIRECTORY"
1183 GNUPGHOME
="$HOME/gnupg-home-not-used"
1184 export HOME GNUPGHOME USER_HOME
1186 # "rm -rf" existing trash directory, even if a previous run left it
1187 # with bad permissions.
1188 remove_trash_directory
() {
1190 if ! rm -rf "$dir" 2>/dev
/null
1192 chmod -R u
+rwx
"$dir"
1199 remove_trash_directory
"$TRASH_DIRECTORY" ||
{
1201 echo >&5 "FATAL: Cannot prepare test area"
1206 if test -z "$TEST_NO_CREATE_REPO"
1208 test_create_repo
"$TRASH_DIRECTORY"
1210 mkdir
-p "$TRASH_DIRECTORY"
1213 # Use -P to resolve symlinks in our working directory so that the cwd
1214 # in subprocesses like git equals our $PWD (for pathname comparisons).
1215 cd -P "$TRASH_DIRECTORY" ||
exit 1
1217 if test -n "$write_junit_xml"
1219 junit_xml_dir
="$TEST_OUTPUT_DIRECTORY/out"
1220 mkdir
-p "$junit_xml_dir"
1221 junit_xml_base
=${0##*/}
1222 junit_xml_path
="$junit_xml_dir/TEST-${junit_xml_base%.sh}.xml"
1223 junit_attrs
="name=\"${junit_xml_base%.sh}\""
1224 junit_attrs
="$junit_attrs timestamp=\"$(TZ=UTC \
1225 date +%Y-%m-%dT%H:%M:%S)\""
1226 write_junit_xml
--truncate "<testsuites>" " <testsuite $junit_attrs>"
1227 junit_suite_start
=$
(test-tool
date getnanos
)
1228 if test -n "$GIT_TEST_TEE_OUTPUT_FILE"
1230 GIT_TEST_TEE_OFFSET
=0
1235 # A regexp to match 5 and 35 hexdigits
1236 _x05
='[0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f]'
1237 _x35
="$_x05$_x05$_x05$_x05$_x05$_x05$_x05"
1241 ZERO_OID
=$
(test_oid zero
)
1242 OID_REGEX
=$
(echo $ZERO_OID |
sed -e 's/0/[0-9a-f]/g')
1243 OIDPATH_REGEX
=$
(test_oid_to_path
$ZERO_OID |
sed -e 's/0/[0-9a-f]/g')
1244 EMPTY_TREE
=$
(test_oid empty_tree
)
1245 EMPTY_BLOB
=$
(test_oid empty_blob
)
1247 # Provide an implementation of the 'yes' utility; the upper bound
1248 # limit is there to help Windows that cannot stop this loop from
1249 # wasting cycles when the downstream stops reading, so do not be
1250 # tempted to turn it into an infinite loop. cf. 6129c930 ("test-lib:
1251 # limit the output of the yes utility", 2016-02-02)
1261 while test $i -lt 99
1268 # The GIT_TEST_FAIL_PREREQS code hooks into test_set_prereq(), and
1269 # thus needs to be set up really early, and set an internal variable
1270 # for convenience so the hot test_set_prereq() codepath doesn't need
1271 # to call "git env--helper" (via test_bool_env). Only do that work
1272 # if needed by seeing if GIT_TEST_FAIL_PREREQS is set at all.
1273 GIT_TEST_FAIL_PREREQS_INTERNAL
=
1274 if test -n "$GIT_TEST_FAIL_PREREQS"
1276 if test_bool_env GIT_TEST_FAIL_PREREQS false
1278 GIT_TEST_FAIL_PREREQS_INTERNAL
=true
1279 test_set_prereq FAIL_PREREQS
1282 test_lazy_prereq FAIL_PREREQS
'
1283 test_bool_env GIT_TEST_FAIL_PREREQS false
1287 # Fix some commands on Windows, and other OS-specific things
1291 # Windows has its own (incompatible) sort and find
1298 # git sees Windows-style pwd
1302 # no POSIX permissions
1303 # backslashes in pathspec are converted to '/'
1304 # exec does not inherit the PID
1305 test_set_prereq MINGW
1306 test_set_prereq NATIVE_CRLF
1307 test_set_prereq SED_STRIPS_CR
1308 test_set_prereq GREP_STRIPS_CR
1309 test_set_prereq WINDOWS
1310 GIT_TEST_CMP
=mingw_test_cmp
1313 test_set_prereq POSIXPERM
1314 test_set_prereq EXECKEEPSPID
1315 test_set_prereq CYGWIN
1316 test_set_prereq SED_STRIPS_CR
1317 test_set_prereq GREP_STRIPS_CR
1318 test_set_prereq WINDOWS
1321 test_set_prereq POSIXPERM
1322 test_set_prereq BSLASHPSPEC
1323 test_set_prereq EXECKEEPSPID
1327 test_lazy_prereq QUILT
'
1328 # test whether quilt is installed
1329 quilt --version 2>/dev/null >/dev/null