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 # Parse options while taking care to leave $@ intact, so we will still
49 # have all the original command line options when executing the test
50 # script again for '--tee' and '--verbose-log' below.
55 if test -n "$store_arg_to"
57 eval $store_arg_to=\
$opt
64 -d|
--d|
--de|
--deb|
--debu|
--debug)
66 -i|
--i|
--im|
--imm|
--imme|
--immed|
--immedi|
--immedia|
--immediat|
--immediate)
68 -l|
--l|
--lo|
--lon|
--long|
--long-|
--long-t|
--long-te|
--long-tes|
--long-test|
--long-tests)
69 GIT_TEST_LONG
=t
; export GIT_TEST_LONG
;;
74 run_list
=${opt#--*=} ;;
75 -h|
--h|
--he|
--hel|
--help)
77 -v|
--v|
--ve|
--ver|
--verb|
--verbo|
--verbos|
--verbose)
81 verbose_only
=${opt#--*=}
83 -q|
--q|
--qu|
--qui|
--quie|
--quiet)
84 # Ignore --quiet under a TAP::Harness. Saying how many tests
85 # passed without the ok/not ok details is always an error.
86 test -z "$HARNESS_ACTIVE" && quiet
=t
;;
105 echo "error: --stress does not accept an argument: '$opt'" >&2
106 echo "did you mean --stress-jobs=${opt#*=} or --stress-limit=${opt#*=}?" >&2
114 echo "error: --stress-jobs=<N> requires the number of jobs to run" >&2
123 stress_limit
=${opt#--*=}
124 case "$stress_limit" in
126 echo "error: --stress-limit=<N> requires the number of repetitions" >&2
134 echo "error: unknown test option '$opt'" >&2; exit 1 ;;
139 if test -n "$store_arg_to"
141 echo "error: $prev_opt requires an argument" >&2
153 TEST_STRESS_JOB_SFX
="${GIT_TEST_STRESS_JOB_NR:+.stress-$GIT_TEST_STRESS_JOB_NR}"
154 TEST_NAME
="$(basename "$0" .sh)"
155 TEST_NUMBER
="${TEST_NAME%%-*}"
156 TEST_NUMBER
="${TEST_NUMBER#t}"
157 TEST_RESULTS_DIR
="$TEST_OUTPUT_DIRECTORY/test-results"
158 TEST_RESULTS_BASE
="$TEST_RESULTS_DIR/$TEST_NAME$TEST_STRESS_JOB_SFX"
159 TRASH_DIRECTORY
="trash directory.$TEST_NAME$TEST_STRESS_JOB_SFX"
160 test -n "$root" && TRASH_DIRECTORY
="$root/$TRASH_DIRECTORY"
161 case "$TRASH_DIRECTORY" in
162 /*) ;; # absolute path is good
163 *) TRASH_DIRECTORY
="$TEST_OUTPUT_DIRECTORY/$TRASH_DIRECTORY" ;;
166 # If --stress was passed, run this test repeatedly in several parallel loops.
167 if test "$GIT_TEST_STRESS_STARTED" = "done"
169 : # Don't stress test again.
170 elif test -n "$stress"
172 if test "$stress" != t
175 elif test -n "$GIT_TEST_STRESS_LOAD"
177 job_count
="$GIT_TEST_STRESS_LOAD"
178 elif job_count
=$
(getconf _NPROCESSORS_ONLN
2>/dev
/null
) &&
181 job_count
=$
((2 * $job_count))
186 mkdir
-p "$TEST_RESULTS_DIR"
187 stressfail
="$TEST_RESULTS_BASE.stress-failed"
192 kill $job_pids 2>/dev/null
199 while test $job_nr -lt "$job_count"
202 GIT_TEST_STRESS_STARTED
=done
203 GIT_TEST_STRESS_JOB_NR
=$job_nr
204 export GIT_TEST_STRESS_STARTED GIT_TEST_STRESS_JOB_NR
207 kill $test_pid 2>/dev/null
213 while ! test -e "$stressfail" &&
214 { test -z "$stress_limit" ||
215 test $cnt -le $stress_limit ; }
217 $TEST_SHELL_PATH "$0" "$@" >"$TEST_RESULTS_BASE.stress-$job_nr.out" 2>&1 &
222 printf "OK %2d.%d\n" $GIT_TEST_STRESS_JOB_NR $cnt
224 echo $GIT_TEST_STRESS_JOB_NR >>"$stressfail"
225 printf "FAIL %2d.%d\n" $GIT_TEST_STRESS_JOB_NR $cnt
230 job_pids
="$job_pids $!"
231 job_nr
=$
(($job_nr + 1))
236 if test -f "$stressfail"
239 echo "Log(s) of failed test run(s):"
240 for failed_job_nr
in $
(sort -n "$stressfail")
242 echo "Contents of '$TEST_RESULTS_BASE.stress-$failed_job_nr.out':"
243 cat "$TEST_RESULTS_BASE.stress-$failed_job_nr.out"
245 rm -rf "$TRASH_DIRECTORY.stress-failed"
247 mv "$TRASH_DIRECTORY.stress-$failed_job_nr" "$TRASH_DIRECTORY.stress-failed"
253 # if --tee was passed, write the output not only to the terminal, but
254 # additionally to the file test-results/$BASENAME.out, too.
255 if test "$GIT_TEST_TEE_STARTED" = "done"
257 : # do not redirect again
260 mkdir
-p "$TEST_RESULTS_DIR"
262 # Make this filename available to the sub-process in case it is using
264 GIT_TEST_TEE_OUTPUT_FILE
=$TEST_RESULTS_BASE.out
265 export GIT_TEST_TEE_OUTPUT_FILE
267 # Truncate before calling "tee -a" to get rid of the results
268 # from any previous runs.
269 >"$GIT_TEST_TEE_OUTPUT_FILE"
271 (GIT_TEST_TEE_STARTED
=done ${TEST_SHELL_PATH} "$0" "$@" 2>&1;
272 echo $?
>"$TEST_RESULTS_BASE.exit") |
tee -a "$GIT_TEST_TEE_OUTPUT_FILE"
273 test "$(cat "$TEST_RESULTS_BASE.
exit")" = 0
277 if test -n "$trace" && test -n "$test_untraceable"
279 # '-x' tracing requested, but this test script can't be reliably
280 # traced, unless it is run with a Bash version supporting
281 # BASH_XTRACEFD (introduced in Bash v4.1).
283 # Perform this version check _after_ the test script was
284 # potentially re-executed with $TEST_SHELL_PATH for '--tee' or
285 # '--verbose-log', so the right shell is checked and the
286 # warning is issued only once.
287 if test -n "$BASH_VERSION" && eval '
288 test ${BASH_VERSINFO[0]} -gt 4 || {
289 test ${BASH_VERSINFO[0]} -eq 4 &&
290 test ${BASH_VERSINFO[1]} -ge 1
294 : Executed by a Bash version supporting BASH_XTRACEFD. Good.
296 echo >&2 "warning: ignoring -x; '$0' is untraceable without BASH_XTRACEFD"
300 if test -n "$trace" && test -z "$verbose_log"
306 export STGIT_DEBUG_LEVEL
308 # For repeatability, reset the environment to known value.
309 # TERM is sanitized below, after saving color control sequences.
310 LANG
=${STG_TEST_LANG:-C}
314 export LANG LC_ALL PAGER TZ
317 # A call to "unset" with no arguments causes at least Solaris 10
318 # /usr/xpg4/bin/sh and /bin/ksh to bail out. So keep the unsets
319 # deriving from the command substitution clustered with the other
321 unset VISUAL EMAIL LANGUAGE COLUMNS $
("$PERL_PATH" -e '
323 my $ok = join("|", qw(
335 my @vars = grep(/^GIT_/ && !/^GIT_($ok)/o, @env);
336 print join("\n", @vars);
339 unset XDG_CONFIG_HOME
341 TEST_AUTHOR_LOCALNAME
=author
342 TEST_AUTHOR_DOMAIN
=example.com
343 GIT_AUTHOR_EMAIL
=${TEST_AUTHOR_LOCALNAME}@
${TEST_AUTHOR_DOMAIN}
344 GIT_AUTHOR_NAME
='A Ú Thor'
345 TEST_COMMITTER_LOCALNAME
=committer
346 TEST_COMMITTER_DOMAIN
=example.com
347 GIT_COMMITTER_EMAIL
=${TEST_COMMITTER_LOCALNAME}@
${TEST_COMMITTER_DOMAIN}
348 GIT_COMMITTER_NAME
='C Ó Mitter'
349 GIT_MERGE_VERBOSITY
=5
350 GIT_MERGE_AUTOEDIT
=no
351 export GIT_MERGE_VERBOSITY GIT_MERGE_AUTOEDIT
352 export GIT_AUTHOR_EMAIL GIT_AUTHOR_NAME
353 export GIT_COMMITTER_EMAIL GIT_COMMITTER_NAME
356 # Tests using GIT_TRACE typically don't want <timestamp> <file>:<line> output
358 export GIT_TRACE_BARE
360 # Use specific version of the index file format
361 if test -n "${GIT_TEST_INDEX_VERSION:+isset}"
363 GIT_INDEX_VERSION
="$GIT_TEST_INDEX_VERSION"
364 export GIT_INDEX_VERSION
367 # Protect ourselves from common misconfiguration to export
368 # CDPATH into the environment
374 case $
(echo $GIT_TRACE |
tr "[A-Z]" "[a-z]") in
382 # A regexp to match 5, 35 and 40 hexdigits
383 _x05
='[0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f]'
384 _x35
="$_x05$_x05$_x05$_x05$_x05$_x05$_x05"
388 _z40
=0000000000000000000000000000000000000000
392 EMPTY_TREE
=4b825dc642cb6eb9a060e54bf8d69288fbee4904
393 EMPTY_BLOB
=e69de29bb2d1d6434b8b29ae775ad8c2e48c5391
402 # UTF-8 ZERO WIDTH NON-JOINER, which HFS+ ignores
403 # when case-folding filenames
404 u200c
=$
(printf '\342\200\214')
406 export _x05 _x35 _x40 _z40 LF u200c EMPTY_TREE EMPTY_BLOB ZERO_OID OID_REGEX
408 # Each test should start with something like this, after copyright notices:
410 # test_description='Description of this test...
411 # This test checks if command xyzzy does the right thing...
414 test "x$TERM" != "xdumb" && (
416 tput bold
>/dev
/null
2>&1 &&
417 tput setaf
1 >/dev
/null
2>&1 &&
418 tput sgr0
>/dev
/null
2>&1
424 # Save the color control sequences now rather than run tput
425 # each time say_color() is called. This is done for two
427 # * TERM will be changed to dumb
428 # * HOME will be changed to a temporary directory and tput
429 # might need to read ~/.terminfo from the original HOME
430 # directory to get the control sequences
431 # Note: This approach assumes the control sequences don't end
432 # in a newline for any terminal of interest (command
433 # substitutions strip trailing newlines). Given that most
434 # (all?) terminals in common use are related to ECMA-48, this
435 # shouldn't be a problem.
436 say_color_error
=$
(tput bold
; tput setaf
1) # bold red
437 say_color_skip
=$
(tput setaf
4) # blue
438 say_color_warn
=$
(tput setaf
3) # brown/yellow
439 say_color_pass
=$
(tput setaf
2) # green
440 say_color_info
=$
(tput setaf
6) # cyan
441 say_color_reset
=$
(tput sgr0
)
442 say_color_
="" # no formatting for normal text
444 test -z "$1" && test -n "$quiet" && return
445 eval "say_color_color=\$say_color_$1"
447 printf "%s\\n" "$say_color_color$*$say_color_reset"
451 test -z "$1" && test -n "$quiet" && return
461 say_color error
"error: $*"
468 error
>&7 "bug in the test script: $*"
475 if test -n "$HARNESS_ACTIVE"
477 if test "$verbose" = t ||
test -n "$verbose_only"
479 printf 'Bail out! %s\n' \
480 'verbose mode forbidden under TAP harness; try --verbose-log'
485 test "${test_description}" != "" ||
486 error
"Test script did not set test_description."
488 if test "$help" = "t"
490 printf '%s\n' "$test_description"
497 if test "$verbose_log" = "t"
499 exec 3>>"$GIT_TEST_TEE_OUTPUT_FILE" 4>&3
500 elif test "$verbose" = "t"
504 exec 4>/dev
/null
3>/dev
/null
507 # Send any "-x" output directly to stderr to avoid polluting tests
508 # which capture stderr. We can do this unconditionally since it
509 # has no effect if tracing isn't turned on.
511 # Note that this sets up the trace fd as soon as we assign the variable, so it
512 # must come after the creation of descriptor 4 above. Likewise, we must never
513 # unset this, as it has the side effect of closing descriptor 4, which we
514 # use to show verbose tests to the user.
516 # Note also that we don't need or want to export it. The tracing is local to
517 # this shell, and we would not want to influence any shells we exec.
526 test_external_has_tap
=0
530 # This is responsible for running the atexit commands even when a
531 # test script run with '--immediate' fails, or when the user hits
532 # ctrl-C, i.e. when 'test_done' is not invoked at all.
533 test_atexit_handler || code
=$?
534 if test -n "$GIT_EXIT_OK"
538 echo >&5 "FATAL: Unexpected exit with code $code"
545 # Disable '-x' tracing, because with some shells, notably dash, it
546 # prevents running the cleanup commands when a test script run with
547 # '--verbose-log -x' is interrupted.
548 trap '{ code=$?; set +x; } 2>/dev/null; exit $code' INT TERM HUP
550 # The user-facing functions are loaded from a separate file so that
551 # test_perf subshells can have them too
552 .
"$TEST_DIRECTORY/test-lib-functions.sh"
554 # You are not expected to call test_ok_ and test_failure_ directly, use
555 # the test_expect_* functions instead.
558 if test -n "$write_junit_xml"
560 write_junit_xml_testcase
"$*"
562 test_success
=$
(($test_success + 1))
563 say_color
"" "ok $test_count - $@"
567 if test -n "$write_junit_xml"
569 junit_insert
="<failure message=\"not ok $test_count -"
570 junit_insert
="$junit_insert $(xml_attr_encode "$1")\">"
571 junit_insert
="$junit_insert $(xml_attr_encode \
572 "$
(if test -n "$GIT_TEST_TEE_OUTPUT_FILE"
574 test-tool path-utils skip-n-bytes \
575 "$GIT_TEST_TEE_OUTPUT_FILE" $GIT_TEST_TEE_OFFSET
577 printf '%s\n' "$@" |
sed 1d
579 junit_insert
="$junit_insert</failure>"
580 if test -n "$GIT_TEST_TEE_OUTPUT_FILE"
582 junit_insert
="$junit_insert<system-err>$(xml_attr_encode \
583 "$
(cat "$GIT_TEST_TEE_OUTPUT_FILE")")</system-err>"
585 write_junit_xml_testcase
"$1" " $junit_insert"
587 test_failure
=$
(($test_failure + 1))
588 say_color error
"not ok $test_count - $1"
590 printf '%s\n' "$*" |
sed -e 's/^/# /'
591 test "$immediate" = "" ||
{ finalize_junit_xml
; GIT_EXIT_OK
=t
; exit 1; }
594 test_known_broken_ok_
() {
595 if test -n "$write_junit_xml"
597 write_junit_xml_testcase
"$* (breakage fixed)"
599 test_fixed
=$
(($test_fixed+1))
600 say_color error
"ok $test_count - $@ # TODO known breakage vanished"
603 test_known_broken_failure_
() {
604 if test -n "$write_junit_xml"
606 write_junit_xml_testcase
"$* (known breakage)"
608 test_broken
=$
(($test_broken+1))
609 say_color warn
"not ok $test_count - $@ # TODO known breakage"
613 test "$debug" = "" ||
eval "$1"
616 match_pattern_list
() {
619 test -z "$*" && return 1
630 match_test_selector_list
() {
635 test -z "$1" && return 0
637 # Both commas and whitespace are accepted as separators.
643 # If the first selector is negative we include by default.
651 orig_selector
=$selector
657 selector
=${selector##?}
661 test -z "$selector" && continue
665 if expr "z${selector%%-*}" : "z[0-9]*[^0-9]" >/dev
/null
667 echo "error: $title: invalid non-numeric in range" \
668 "start: '$orig_selector'" >&2
671 if expr "z${selector#*-}" : "z[0-9]*[^0-9]" >/dev
/null
673 echo "error: $title: invalid non-numeric in range" \
674 "end: '$orig_selector'" >&2
679 if expr "z$selector" : "z[0-9]*[^0-9]" >/dev
/null
681 echo "error: $title: invalid non-numeric in test" \
682 "selector: '$orig_selector'" >&2
687 # Short cut for "obvious" cases
688 test -z "$include" && test -z "$positive" && continue
689 test -n "$include" && test -n "$positive" && continue
693 if test $arg -le ${selector#-}
699 if test $arg -ge ${selector%-}
705 if test ${selector%%-*} -le $arg \
706 && test $arg -le ${selector#*-}
712 if test $arg -eq $selector
723 maybe_teardown_verbose
() {
724 test -z "$verbose_only" && return
725 exec 4>/dev
/null
3>/dev
/null
730 maybe_setup_verbose
() {
731 test -z "$verbose_only" && return
732 if match_pattern_list
$test_count $verbose_only
735 # Emit a delimiting blank line when going from
736 # non-verbose to verbose. Within verbose mode the
737 # delimiter is printed by test_expect_*. The choice
738 # of the initial $last_verbose is such that before
739 # test 1, we do not print it.
740 test -z "$last_verbose" && echo >&3 ""
743 exec 4>/dev
/null
3>/dev
/null
746 last_verbose
=$verbose
750 test "$trace" = t
&& {
751 test "$verbose" = t ||
test "$verbose_log" = t
755 # This is a separate function because some tests use
756 # "return" to end a test_expect_success block early
757 # (and we want to make sure we run any cleanup like
759 test_eval_inner_
() {
760 # Do not add anything extra (including LF) after '$*'
767 # If "-x" tracing is in effect, then we want to avoid polluting stderr
768 # with non-test commands. But once in "set -x" mode, we cannot prevent
769 # the shell from printing the "set +x" to turn it off (nor the saving
770 # of $? before that). But we can make sure that the output goes to
773 # There are a few subtleties here:
775 # - we have to redirect descriptor 4 in addition to 2, to cover
778 # - the actual eval has to come before the redirection block (since
779 # it needs to see descriptor 4 to set up its stderr)
781 # - likewise, any error message we print must be outside the block to
782 # access descriptor 4
784 # - checking $? has to come immediately after the eval, but it must
785 # be _inside_ the block to avoid polluting the "set -x" output
788 test_eval_inner_
"$@" </dev
/null
>&3 2>&4
797 if test "$test_eval_ret_" != 0 && want_trace
799 say_color error
>&4 "error: last command exited with \$?=$test_eval_ret_"
801 return $test_eval_ret_
811 if test -z "$immediate" ||
test $eval_ret = 0 ||
812 test -n "$expecting_failure" && test "$test_cleanup" != ":"
814 test_eval_
"$test_cleanup"
816 if test "$verbose" = "t" && test -n "$HARNESS_ACTIVE"
824 test_count
=$
(($test_count+1))
826 if test -n "$write_junit_xml"
828 junit_start
=$
(test-tool
date getnanos
)
834 maybe_teardown_verbose
835 if test -n "$GIT_TEST_TEE_OFFSET"
837 GIT_TEST_TEE_OFFSET
=$
(test-tool path-utils file-size \
838 "$GIT_TEST_TEE_OUTPUT_FILE")
845 if match_pattern_list
$this_test.
$test_count $STG_SKIP_TESTS
848 skipped_reason
="STG_SKIP_TESTS"
850 if test -z "$to_skip" && test -n "$run_list" &&
851 ! match_test_selector_list
'--run' $test_count "$run_list"
854 skipped_reason
="--run"
856 if test -z "$to_skip" && test -n "$test_prereq" &&
857 ! test_have_prereq
"$test_prereq"
862 if test "$missing_prereq" != "$test_prereq"
864 of_prereq
=" of $test_prereq"
866 skipped_reason
="missing $missing_prereq${of_prereq}"
871 if test -n "$write_junit_xml"
873 message
="$(xml_attr_encode "$skipped_reason")"
874 write_junit_xml_testcase
"$1" \
875 " <skipped message=\"$message\" />"
878 say_color skip
>&3 "skipping test: $@"
879 say_color skip
"ok $test_count # skip $1 ($skipped_reason)"
888 # stub; perf-lib overrides it
889 test_at_end_hook_
() {
901 printf '%s\n' "$@" >>"$junit_xml_path"
905 printf '%s\n' "$@" | test-tool xml-encode
908 write_junit_xml_testcase
() {
909 junit_attrs
="name=\"$(xml_attr_encode "$this_test.
$test_count $1")\""
911 junit_attrs
="$junit_attrs classname=\"$this_test\""
912 junit_attrs
="$junit_attrs time=\"$(test-tool \
913 date getnanos $junit_start)\""
914 write_junit_xml
"$(printf '%s\n' \
915 " <testcase
$junit_attrs>" "$@
" " </testcase
>")"
916 junit_have_testcase
=t
919 finalize_junit_xml
() {
920 if test -n "$write_junit_xml" && test -n "$junit_xml_path"
922 test -n "$junit_have_testcase" ||
{
923 junit_start
=$
(test-tool
date getnanos
)
924 write_junit_xml_testcase
"all tests skipped"
927 # adjust the overall time
928 junit_time
=$
(test-tool
date getnanos
$junit_suite_start)
929 sed -e "s/\(<testsuite.*\) time=\"[^\"]*\"/\1/" \
930 -e "s/<testsuite [^>]*/& time=\"$junit_time\"/" \
931 <"$junit_xml_path" >"$junit_xml_path.new"
932 mv "$junit_xml_path.new" "$junit_xml_path"
934 write_junit_xml
" </testsuite>" "</testsuites>"
939 test_atexit_cleanup
=:
940 test_atexit_handler
() {
941 # In a succeeding test script 'test_atexit_handler' is invoked
942 # twice: first from 'test_done', then from 'die' in the trap on
944 # This condition and resetting 'test_atexit_cleanup' below makes
945 # sure that the registered cleanup commands are run only once.
946 test : != "$test_atexit_cleanup" ||
return 0
948 test_eval_
"$test_atexit_cleanup"
949 test_atexit_cleanup
=:
955 # Run the atexit commands _before_ the trash directory is
956 # removed, so the commands can access pidfiles and socket files.
961 if test -z "$HARNESS_ACTIVE"
963 mkdir
-p "$TEST_RESULTS_DIR"
965 cat >"$TEST_RESULTS_BASE.counts" <<-EOF
967 success $test_success
975 if test "$test_fixed" != 0
977 say_color error
"# $test_fixed known breakage(s) vanished; please update test(s)"
979 if test "$test_broken" != 0
981 say_color warn
"# still have $test_broken known breakage(s)"
983 if test "$test_broken" != 0 ||
test "$test_fixed" != 0
985 test_remaining
=$
(( $test_count - $test_broken - $test_fixed ))
986 msg
="remaining $test_remaining test(s)"
988 test_remaining
=$test_count
989 msg
="$test_count test(s)"
991 case "$test_failure" in
993 if test $test_external_has_tap -eq 0
995 if test $test_remaining -gt 0
997 say_color pass
"# passed all $msg"
1000 # Maybe print SKIP message
1001 test -z "$skip_all" || skip_all
="# SKIP $skip_all"
1002 case "$test_count" in
1004 say
"1..$test_count${skip_all:+ $skip_all}"
1007 test -z "$skip_all" ||
1008 say_color warn
"$skip_all"
1009 say
"1..$test_count"
1016 test -d "$TRASH_DIRECTORY" ||
1017 error
"Tests passed but trash directory already removed before test cleanup; aborting"
1019 cd "$TRASH_DIRECTORY/.." &&
1020 rm -fr "$TRASH_DIRECTORY" ||
{
1021 # try again in a bit
1023 rm -fr "$TRASH_DIRECTORY"
1025 error
"Tests passed but test cleanup failed; aborting"
1032 if test $test_external_has_tap -eq 0
1034 say_color error
"# failed $test_failure among $msg"
1035 say
"1..$test_count"
1043 if test -n "$STG_TEST_INSTALLED"
1045 PATH
=$STG_TEST_INSTALLED:$PATH
1047 PATH
="$TEST_DIRECTORY/test-bin:$PATH"
1048 PYTHONPATH
="$STG_ROOT":"$PYTHONPATH"
1050 GIT_EXEC_PATH
=$
(git
--exec-path) || error
"Cannot run git"
1051 unset GIT_TEMPLATE_DIR
1052 GIT_CONFIG_NOSYSTEM
=1
1054 export PATH GIT_EXEC_PATH PYTHONPATH GIT_CONFIG_NOSYSTEM GIT_ATTR_NOSYSTEM
1056 if test -z "$GIT_TEST_CMP"
1058 DIFF
="${DIFF:-diff}"
1059 if test -n "$GIT_TEST_CMP_USE_COPIED_CONTEXT"
1061 GIT_TEST_CMP
="$DIFF -c"
1063 GIT_TEST_CMP
="$DIFF -u"
1068 rm -fr "$TRASH_DIRECTORY" ||
{
1070 echo >&5 "FATAL: Cannot prepare test area"
1074 HOME
="$TRASH_DIRECTORY"
1075 GNUPGHOME
="$HOME/gnupg-home-not-used"
1076 export HOME GNUPGHOME
1078 if test -z "$TEST_NO_CREATE_REPO"
1080 test_create_repo
"$TRASH_DIRECTORY"
1082 mkdir
-p "$TRASH_DIRECTORY"
1085 # Use -P to resolve symlinks in our working directory so that the cwd
1086 # in subprocesses like git equals our $PWD (for pathname comparisons).
1087 cd -P "$TRASH_DIRECTORY" ||
exit 1
1090 this_test
=${this_test%%-*}
1091 if match_pattern_list
"$this_test" $STG_SKIP_TESTS
1093 say_color info
>&3 "skipping test $this_test altogether"
1094 skip_all
="skip all tests in $this_test"
1098 if test -n "$write_junit_xml"
1100 junit_xml_dir
="$TEST_OUTPUT_DIRECTORY/out"
1101 mkdir
-p "$junit_xml_dir"
1102 junit_xml_base
=${0##*/}
1103 junit_xml_path
="$junit_xml_dir/TEST-${junit_xml_base%.sh}.xml"
1104 junit_attrs
="name=\"${junit_xml_base%.sh}\""
1105 junit_attrs
="$junit_attrs timestamp=\"$(TZ=UTC \
1106 date +%Y-%m-%dT%H:%M:%S)\""
1107 write_junit_xml
--truncate "<testsuites>" " <testsuite $junit_attrs>"
1108 junit_suite_start
=$
(test-tool
date getnanos
)
1109 if test -n "$GIT_TEST_TEE_OUTPUT_FILE"
1111 GIT_TEST_TEE_OFFSET
=0
1115 # Provide an implementation of the 'yes' utility; the upper bound
1116 # limit is there to help Windows that cannot stop this loop from
1117 # wasting cycles when the downstream stops reading, so do not be
1118 # tempted to turn it into an infinite loop. cf. 6129c930 ("test-lib:
1119 # limit the output of the yes utility", 2016-02-02)
1129 while test $i -lt 99
1136 # Fix some commands on Windows, and other OS-specific things
1140 # Windows has its own (incompatible) sort and find
1147 # git sees Windows-style pwd
1151 # no POSIX permissions
1152 # backslashes in pathspec are converted to '/'
1153 # exec does not inherit the PID
1154 test_set_prereq MINGW
1155 test_set_prereq NATIVE_CRLF
1156 test_set_prereq SED_STRIPS_CR
1157 test_set_prereq GREP_STRIPS_CR
1158 GIT_TEST_CMP
=mingw_test_cmp
1161 test_set_prereq POSIXPERM
1162 test_set_prereq EXECKEEPSPID
1163 test_set_prereq CYGWIN
1164 test_set_prereq SED_STRIPS_CR
1165 test_set_prereq GREP_STRIPS_CR
1168 test_set_prereq REGEX_ILLSEQ
1169 test_set_prereq POSIXPERM
1170 test_set_prereq BSLASHPSPEC
1171 test_set_prereq EXECKEEPSPID
1174 test_set_prereq POSIXPERM
1175 test_set_prereq BSLASHPSPEC
1176 test_set_prereq EXECKEEPSPID
1180 test_lazy_prereq QUILT
'
1181 # test whether quilt is installed
1182 quilt --version 2>/dev/null >/dev/null