test-lib-main.sh: promote test_done messages to TAP status
[topgit/pro.git] / t / test-lib-main.sh
blob210442d4b291878a95820d56f45caecfb3e4109a
1 # Test framework from Git with modifications.
3 # Modifications Copyright (C) 2016,2017 Kyle J. McKay. All rights reserved.
4 # Modifications made:
6 # * Many "GIT_..." variables removed -- some were kept as TESTLIB_..." instead
7 # (Except "GIT_PATH" is new and is the full path to a "git" executable)
9 # * IMPORTANT: test-lib-main.sh SHOULD NOT EXECUTE ANY CODE! A new
10 # function "test_lib_main_init" has been added that will be called
11 # and MUST contain any lines of code to be executed. This will ALWAYS
12 # be the LAST function defined in this file for easy locatability.
14 # * Added cmd_path, _?fatal, whats_the_dir, vcmp, getcmd, say_tap, say_color_tap,
15 # fail_, test_possibly_broken_ok_ and test_possibly_broken_failure_ functions
17 # * Anything related to valgrind or perf has been stripped out
19 # * Many other minor changes
21 # Copyright (C) 2005 Junio C Hamano
23 # This program is free software: you can redistribute it and/or modify
24 # it under the terms of the GNU General Public License as published by
25 # the Free Software Foundation, either version 2 of the License, or
26 # (at your option) any later version.
28 # This program is distributed in the hope that it will be useful,
29 # but WITHOUT ANY WARRANTY; without even the implied warranty of
30 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
31 # GNU General Public License for more details.
33 # You should have received a copy of the GNU General Public License
34 # along with this program. If not, see http://www.gnu.org/licenses/ .
37 ## IMPORTANT: THIS FILE MUST NOT CONTAIN ANYTHING OTHER THAN FUNCTION
38 ## DEFINITION!!! INITIALIZATION GOES IN THE LAST FUNCTION
39 ## DEFINED IN THIS FILE "test_lib_main_init" AS REQUIRED!
42 cmd_path() (
43 { "unset" -f command unset unalias "$1"; } >/dev/null 2>&1 || :
44 { "unalias" -a || unalias -m "*"; } >/dev/null 2>&1 || :
45 command -v "$1"
48 _fatal() {
49 printf '%s\n' "$*" >&2
50 TESTLIB_EXIT_OK=1
51 exit 1
53 fatal() { _fatal "$@"; }
55 # usage: cmdget <varname> <cmd> [<arg>...]
56 # return code is that of <cmd> [<arg...]
57 # <varname> is set to VERBATIM <cmd> output (except NULs may not be handled)
58 getcmd() {
59 [ -n "$1" ] || return 1
60 eval "$1=" >/dev/null 2>&1 || return 1
61 [ -n "$2" ] || return 1
62 _getcmd_vn="$1"
63 shift
64 _getcmd_ec=0
65 _getcmd_result="$(ec=0; ("$@") || ec=$?; echo Z; exit $ec)" || _getcmd_ec=$?
66 eval "$_getcmd_vn=\"\${_getcmd_result%Z}\""
67 return $_getcmd_ec
70 # usage: whats_the_dir [-P | -L] [--] path-to-something varname
71 # determine path-to-something's directory and store it into varname
72 # without "-P" or "-L" a relative dirname may be returned
73 whats_the_dir() {
74 # determine "$1"'s directory and store it into the var name passed as "$2"
75 if [ "z$1" = "z-P" -o "z$1" = "z-L" ]; then
76 if [ "z$2" = "z--" ]; then
77 set -- "$3" "$4" "$1"
78 else
79 set -- "$2" "$3" "$1"
81 elif [ "z$1" = "z--" ]; then
82 shift
84 case "$1" in *"/"*);;*) set -- "./$1" "$2" "$3"; esac
85 while [ -L "$1" ]; do
86 set -- "$(readlink "$1")" "$2" "$3" "$1"
87 case "$1" in "/"*);;*)
88 set -- "${4%/*}/$1" "$2" "$3"
89 esac
90 done
91 set -- "${1%/*}" "$2" "$3"
92 if [ "z$3" != "z" ] && [ -d "$1" ] &&
93 ! case "$1" in [!/]*|*"/./"*|*"/."|*"/../"*|*"/..") ! :; esac; then
94 [ "z$3" = "z-P" ] || set -- "$1" "$2"
95 if [ "z$3" = "z" -a \( "z$1" = "z." -o "z$1" = "z$PWD" \) ]; then
96 set -- "$PWD" "$2"
97 else
98 set -- "$(cd "$1" && pwd $3)" "$2"
101 eval "$2=\"$1\""
104 vcmp() {
105 # Compare $1 to $3 each of which must match ^[^0-9]*\d*(\.\d*)*.*$
106 # where only the "\d*" parts in the regex participate in the comparison
107 # Since EVERY string matches that regex this function is easy to use
108 # An empty string ('') for $1 or $3 or any "\d*" part is treated as 0
109 # $2 is a compare op '<', '<=', '=', '==', '!=', '>=', '>'
110 # Return code is 0 for true, 1 for false (or unknown compare op)
111 # There is NO difference in behavior between '=' and '=='
112 # Note that "vcmp 1.8 == 1.8.0.0.0.0" correctly returns 0
113 set -- "$1" "$2" "$3" "${1%%[0-9]*}" "${3%%[0-9]*}"
114 set -- "${1#"$4"}" "$2" "${3#"$5"}"
115 set -- "${1%%[!0-9.]*}" "$2" "${3%%[!0-9.]*}"
116 while
117 vcmp_a_="${1%%.*}"
118 vcmp_b_="${3%%.*}"
119 [ "z$vcmp_a_" != "z" -o "z$vcmp_b_" != "z" ]
121 if [ "${vcmp_a_:-0}" -lt "${vcmp_b_:-0}" ]; then
122 unset_ vcmp_a_ vcmp_b_
123 case "$2" in "<"|"<="|"!=") return 0; esac
124 return 1
125 elif [ "${vcmp_a_:-0}" -gt "${vcmp_b_:-0}" ]; then
126 unset_ vcmp_a_ vcmp_b_
127 case "$2" in ">"|">="|"!=") return 0; esac
128 return 1;
130 vcmp_a_="${1#$vcmp_a_}"
131 vcmp_b_="${3#$vcmp_b_}"
132 set -- "${vcmp_a_#.}" "$2" "${vcmp_b_#.}"
133 done
134 unset_ vcmp_a_ vcmp_b_
135 case "$2" in "="|"=="|"<="|">=") return 0; esac
136 return 1
139 vcmp "$@"
141 error_lno() {
142 : "${callerlno:=$1}"
143 shift
144 say_color error "${LF}error: $*" >&7
145 printf '%s\n' "Bail out! ${0##*/}:${callerlno:+$callerlno:} error: $*" >&5
146 test_results_dir="${TEST_OUTPUT_DIRECTORY:-.}/test-results"
147 mkdir -p "$test_results_dir"
148 printf '%s\n' "Bail out! ${0##*/}:${callerlno:+$callerlno:} error: $*" >>"$test_results_dir/bailout"
149 TESTLIB_EXIT_OK=t
150 [ -z "$TESTLIB_TEST_PARENT_INT_ON_ERROR" ] || {
151 trap '' INT
152 perl -e "kill(-2, getpgrp($TESTLIB_TEST_PARENT_INT_ON_ERROR), getpgrp($PPID), getpgrp($$), getpgrp(0))" || :
153 kill -INT $TESTLIB_TEST_PARENT_INT_ON_ERROR $PPID || :
154 } >/dev/null 2>&1
155 kill -USR1 $$ || :
156 exit 1
158 error() {
159 error_lno "" "$@"
161 alias error='error_lno "$LINENO"' >/dev/null 2>&1 || :
163 say() {
164 say_color info "$@"
167 say_tap() {
168 say_color_tap info "$@"
171 _die() {
172 code=${EXITCODE_:-$?}
173 if test -n "$TESTLIB_EXIT_OK"
174 then
175 exit $code
176 else
177 msg="$*"
178 msg="${msg:+($code) }$msg"
179 [ -n "$msg" ] || msg=" Unexpected exit with code $code"
180 echo >&5 "FATAL:$msg"
181 exit 1
184 die() { _die "$@"; }
186 # You are not expected to call test_ok_ and test_failure_ directly, use
187 # the test_expect_* functions instead.
189 test_ok_() {
190 test_success=$(($test_success + 1))
191 say_color_tap "" "ok $test_count - $@"
194 test_failure_() {
195 test_failure=$(($test_failure + 1))
196 tlno="$1"
197 shift
198 say_color_tap error "not ok $test_count - $1"
199 if test z"${TESTLIB_TEST_TAP_ONLY:-0}" != z"0"; then
200 test z"$tlno" = z ||
201 say_color_tap "" "# failed: ${0##*/}${tlno:+:$tlno}: $test_count - $1"
202 else
203 ttit="$test_count - $1"
204 shift
205 printf '%s\n' "$(printf '%s\n' "failed: ${0##*/}${tlno:+:$tlno}: $ttit$LF$*")" |
206 sed -n -e '
208 :loop
209 s/\([^ ]\)/\1/
210 t first
211 b continue
212 :first
215 b rest
216 :continue
218 b loop
220 :rest
221 s/^/# /
223 $ i\
227 test "$immediate" = "" || { TESTLIB_EXIT_OK=t; exit 1; }
230 test_known_broken_ok_() {
231 test_fixed=$(($test_fixed + 1))
232 say_color_tap warn "ok $test_count - $@ # TODO known breakage vanished"
235 test_known_broken_failure_() {
236 test_broken=$(($test_broken + 1))
237 say_color_tap warn "not ok $test_count - $@ # TODO known breakage"
240 test_possibly_broken_ok_() {
241 test_success=$(($test_success + 1))
242 say_color_tap "" "ok $test_count - $@"
245 test_possibly_broken_failure_() {
246 test_broken=$(($test_broken + 1))
247 say_color_tap warn "not ok $test_count - $@ # TODO tolerated breakage"
250 test_debug() {
251 test "$debug" = "" || test $# -eq 0 || test -z "$*" || { "$@"; } >&7 2>&1
254 match_pattern_list() {
255 arg="$1"
256 shift
257 test -z "$*" && return 1
258 for pattern_
260 case "$arg" in
261 $pattern_)
262 return 0
263 esac
264 done
265 return 1
268 match_test_selector_list() {
269 title="$1"
270 shift
271 arg="$1"
272 shift
273 test -z "$1" && return 0
275 # Both commas and whitespace are accepted as separators.
276 OLDIFS=$IFS
277 IFS=' ,'
278 set -- $1
279 IFS=$OLDIFS
281 # If the first selector is negative we include by default.
282 include=
283 case "$1" in
284 !*) include=t ;;
285 esac
287 for selector
289 orig_selector=$selector
291 positive=t
292 case "$selector" in
294 positive=
295 selector=${selector##?}
297 esac
299 test -z "$selector" && continue
301 case "$selector" in
302 *-*)
303 if x_="${selector%%-*}" && test "z$x_" != "z${x_#*[!0-9]}"
304 then
305 echo "error: $title: invalid non-numeric in range" \
306 "start: '$orig_selector'" >&2
307 exit 1
309 if x_="${selector#*-}" && test "z$x_" != "z${x_#*[!0-9]}"
310 then
311 echo "error: $title: invalid non-numeric in range" \
312 "end: '$orig_selector'" >&2
313 exit 1
315 unset_ x_
318 if test "z$selector" != "z${selector#*[!0-9]}"
319 then
320 echo "error: $title: invalid non-numeric in test" \
321 "selector: '$orig_selector'" >&2
322 exit 1
324 esac
326 # Short cut for "obvious" cases
327 test -z "$include" && test -z "$positive" && continue
328 test -n "$include" && test -n "$positive" && continue
330 case "$selector" in
332 if test $arg -le ${selector#-}
333 then
334 include=$positive
338 if test $arg -ge ${selector%-}
339 then
340 include=$positive
343 *-*)
344 if test ${selector%%-*} -le $arg \
345 && test $arg -le ${selector#*-}
346 then
347 include=$positive
351 if test $arg -eq $selector
352 then
353 include=$positive
356 esac
357 done
359 test -n "$include"
362 maybe_teardown_verbose() {
363 test -z "$verbose_list" && return
364 exec 4>/dev/null 3>/dev/null
365 verbose=
368 maybe_setup_verbose() {
369 test -z "$verbose_list" && return
370 if match_test_selector_list '--verbose-only' $test_count "$verbose_list"
371 then
372 if test "$verbose_log" = "t"
373 then
374 exec 3>>"$TESTLIB_TEST_TEE_OUTPUT_FILE" 4>&3
375 else
376 exec 4>&2 3>&1
378 # Emit a delimiting blank line when going from
379 # non-verbose to verbose. Within verbose mode the
380 # delimiter is printed by test_expect_*. The choice
381 # of the initial $last_verbose is such that before
382 # test 1, we do not print it.
383 test -z "$last_verbose" && echo >&3 ""
384 verbose=t
385 else
386 exec 4>/dev/null 3>/dev/null
387 verbose=
389 last_verbose=$verbose
392 want_verbose() {
393 test "$verbose" = t
396 want_no_verbose() {
397 ! want_verbose
400 want_trace() {
401 test "$trace" = t && test "$verbose" = t
404 # This is a separate function because some tests use
405 # "return" to end a test_expect_success block early
406 # (and we want to make sure we run any cleanup like
407 # "set +x").
408 test_eval_inner_() (
409 # Do not add anything extra (including LF) after '$*'
410 eval "
411 set -e
412 test_subshell_active_=t
413 ! want_trace || ! set -x && ! :
417 # Same thing as test_eval_inner_ but without the subshell
418 test_eval_inner_no_subshell_() {
419 # Do not add anything extra (including LF) after '$*'
420 eval "
421 ! want_trace || ! set -x && ! :
425 test_eval_ss_() {
426 # We run this block with stderr redirected to avoid extra cruft
427 # during a "-x" trace. Once in "set -x" mode, we cannot prevent
428 # the shell from printing the "set +x" to turn it off (nor the saving
429 # of $? before that). But we can make sure that the output goes to
430 # /dev/null.
432 # The test itself is run with stderr put back to &4 (so either to
433 # /dev/null, or to the original stderr if --verbose was used).
435 test_eval_ss_="$1"
436 shift
437 if test "${test_eval_ss_:-0}" = "0"
438 then
439 test_eval_inner_no_subshell_ "$@" </dev/null >&3 2>&4
440 else
441 test_eval_inner_ "$@" </dev/null >&3 2>&4
443 test_eval_ret_=$?
444 if want_trace
445 then
446 set +x
447 if test "$test_eval_ret_" != 0
448 then
449 say_color error >&4 "error: last command exited with \$?=$test_eval_ret_"
452 } 2>/dev/null
453 return $test_eval_ret_
456 # Calls the real test_eval_ss_ with !"$TESTLIB_TEST_NO_SUBSHELL" as first arg
457 test_eval_() {
458 if test -n "$TESTLIB_TEST_NO_SUBSHELL"
459 then
460 test_eval_ss_ "0" "$@"
461 else
462 test_eval_ss_ "1" "$@"
466 # If "$1" = "-" read the script from stdin but ONLY if stdin is NOT a tty
467 # Store the test script in test_script_
468 test_get_() {
469 if test "x$1" = "x-"
470 then
471 ! test -t 0 || error "test script is '-' but STDIN is a tty"
472 test_script_="$(cat)"
473 test -n "$test_script_" || error "test script is '-' but STDIN is empty"
474 test_script_="$LF$test_script_$LF"
475 else
476 test_script_="$1"
480 # protects against use of "return" in test_when_finished scripts
481 test_do_script_() {
482 . "$1"
485 fail_() {
486 test z"$2" = "z" || set +e
487 return ${1:-1}
490 test_run_() {
491 test_cleanup="$TRASHTMP_DIRECTORY/test_when_finished_${test_count:-0}.sh"
492 ! test -e "$test_cleanup" || {
493 rm -f "$test_cleanup" &&
494 ! test -e "$test_cleanup" ||
495 error "FATAL: Cannot prepare test area"
497 test_subshell_active_=
498 expecting_failure=$2
499 linting=
501 if test "${TESTLIB_TEST_CHAIN_LINT:-1}" != 0; then
502 # turn off tracing for this test-eval, as it simply creates
503 # confusing noise in the "-x" output
504 trace_tmp=$trace
505 trace=
506 linting=t
507 # 117 is magic because it is unlikely to match the exit
508 # code of other programs
509 test_eval_ss_ "1" "fail_ 117 && $1${LF}fail_ \$? 1"
510 if test "$?" != 117; then
511 error "bug in the test script: broken &&-chain: $1"
513 trace=$trace_tmp
514 linting=
517 test_eval_ "$1"
518 eval_ret=$?
520 if test -z "$immediate" || test $eval_ret = 0 ||
521 test -n "$expecting_failure" && test -s "$test_cleanup"
522 then
523 test_eval_ss_ "0" 'test_do_script_ "$test_cleanup" && (exit $eval_ret); eval_ret=$?'
525 if test "$verbose" = "t" && test -n "$HARNESS_ACTIVE"
526 then
527 echo ""
529 return "$eval_ret"
532 test_start_() {
533 test_count=$(($test_count+1))
534 maybe_setup_verbose
537 test_finish_() {
538 test z"$to_skip" = z"q" || echo >&3 ""
539 maybe_teardown_verbose
542 test_skip() {
543 to_skip=
544 skipped_reason=
545 if match_pattern_list $this_test.$test_count $TESTLIB_SKIP_TESTS
546 then
547 to_skip=t
548 skipped_reason="TESTLIB_SKIP_TESTS"
550 if test -z "$to_skip" && test -n "$test_prereq" &&
551 ! test_have_prereq "$test_prereq"
552 then
553 to_skip=t
555 of_prereq=
556 if test "$missing_prereq" != "$test_prereq"
557 then
558 of_prereq=" of $test_prereq"
560 skipped_reason="missing $missing_prereq${of_prereq}"
562 if test -z "$to_skip" && test -n "$run_list" &&
563 ! match_test_selector_list '--run' $test_count "$run_list"
564 then
565 to_skip=t
566 skipped_reason="--run"
569 case "$to_skip" in
571 if test z"$runquiet" = z || test z"$skipped_reason" != z"--run"; then
572 say_color skip >&3 "skipping test: $@"
573 say_color_tap skip "ok $test_count # skip $1 ($skipped_reason)"
574 else
575 to_skip=q
577 : true
580 false
582 esac
585 # stub; runs at end of each successful test
586 test_at_end_hook_() {
590 # returns 1 if counts do not match
591 # $1 is extra message, if any
592 test_done_write_plan_() {
593 if test $test_external_has_tap -eq 0
594 then
596 test -z "$test_called_test_plan" &&
598 test -z "$1" ||
599 test z"$test_count" != z"0"
601 then
602 say_color_tap warn "# please add test_plan call"
604 test -n "$test_wrote_plan_count" || say_tap "1..$test_count$1"
606 if test -n "$test_wrote_plan_count" && test "$test_wrote_plan_count" -ne "$test_count"
607 then
608 say_color_tap error "# $this_test plan count of $test_wrote_plan_count does not match run count of $test_count"
609 return 1
611 return 0
614 test_done() {
615 TESTLIB_EXIT_OK=t
617 if test -z "$HARNESS_ACTIVE"
618 then
619 test_results_dir="${TEST_OUTPUT_DIRECTORY:-.}/test-results"
620 mkdir -p "$test_results_dir"
621 base=${0##*/}
622 test_results_path="$test_results_dir/${base%.sh}.counts"
624 cat >"$test_results_path" <<-EOF
625 total $test_count
626 success $test_success
627 fixed $test_fixed
628 broken $test_broken
629 failed $test_failure
634 if test "$test_fixed" != 0
635 then
636 say_color_tap error "# $this_test $test_fixed known breakage(s) vanished; please update test(s)"
638 if test "$test_broken" != 0
639 then
640 say_color_tap warn "# $this_test still have $test_broken known breakage(s)"
642 if test "$test_broken" != 0 || test "$test_fixed" != 0
643 then
644 test_remaining=$(( $test_count - $test_broken - $test_fixed ))
645 msg="remaining $test_remaining test(s)"
646 else
647 test_remaining=$test_count
648 msg="$test_count test(s)"
650 case "$test_failure" in
652 # Maybe print SKIP message
653 if test -n "$skip_all" && test $test_count -gt 0
654 then
655 error "Can't use skip_all after running some tests"
657 test -z "$skip_all" || skip_all=" # SKIP $skip_all"
659 if test $test_external_has_tap -eq 0
660 then
661 if test $test_remaining -gt 0
662 then
663 say_color_tap pass "# $this_test passed all $msg"
666 test_done_write_plan_ "$skip_all" || exit 1
668 test -n "$remove_trash" &&
669 test -d "$remove_trash" &&
670 cd "${remove_trash%/*}" &&
671 test_done_td_="${remove_trash##*/}" &&
672 test -e "$test_done_td_" &&
673 { rm -rf "$test_done_td_" || :; } >/dev/null 2>&1 &&
675 ! test -e "$test_done_td_" || {
676 chmod -R u+rw "$test_done_td_" &&
677 rm -rf "$test_done_td_"
678 } || :
680 test -n "$remove_trashtmp" &&
681 test -d "$remove_trashtmp" &&
682 cd "${remove_trashtmp%/*}" &&
683 test_done_td_="${remove_trashtmp##*/}" &&
684 test -e "$test_done_td_" &&
685 { rm -rf "$test_done_td_" || :; } >/dev/null 2>&1 &&
687 ! test -e "$test_done_td_" || {
688 chmod -R u+rw "$test_done_td_" &&
689 rm -rf "$test_done_td_"
690 } || :
693 test_at_end_hook_
695 exit 0 ;;
698 if test $test_external_has_tap -eq 0
699 then
700 say_color_tap error "# $this_test failed $test_failure among $msg"
702 test_done_write_plan_ || :
704 test -z "$HARNESS_ACTIVE" || exit 0
705 exit 1 ;;
707 esac
710 test_plan() {
711 test z"$test_called_test_plan" = z || fatal "test_plan may not be called more than once"
712 test_called_test_plan=1
713 test z"$*" != z"?" || return 0
714 test -n "$1" && test "z$1" = "z${1#*[!0-9]}" || fatal "invalid test_plan argument: $1"
715 test "$1" -eq 0 || test z"$1" = z"$*" || fatal "invalid test_plan arguments: $*"
716 if test "$1" -eq 0; then
717 shift
718 msg="$*"
719 skip_all="${msg:-skip all tests in $this_test}"
720 test_done
722 if test z"$runquiet" = z; then
723 test $test_external_has_tap -ne 0 || say_tap "1..$1"
724 test_wrote_plan_count="$1"
728 # Provide an implementation of the 'yes' utility
729 yes() {
730 if test $# = 0
731 then
733 else
734 y="$*"
738 while test $i -lt 99
740 echo "$y"
741 i=$(($i+1))
742 done
745 run_with_limited_cmdline() {
746 (ulimit -s 128 && "$@")
749 # internal use function
750 test_ensure_temp_dir_() {
751 test z"$TRASHTMP_DIRECTORY" != z ||
752 fatal "${1:+$1 called but }TRASHTMP_DIRECTORY is not set yet"
753 test -d "$TRASHTMP_DIRECTORY" || {
754 mkdir "$TRASHTMP_DIRECTORY" &&
755 test -d "$TRASHTMP_DIRECTORY"
756 } || fatal "could not create temp directory \"$TRASHTMP_DIRECTORY\""
757 test z"$2" = z ||
758 test -d "$TRASHTMP_DIRECTORY/$2" || {
759 mkdir "$TRASHTMP_DIRECTORY/$2" &&
760 test -d "$TRASHTMP_DIRECTORY/$2"
761 } || fatal "could not create temp subdirectory \"$TRASHTMP_DIRECTORY/$2\""
764 # test_get_temp [-d] [<name>]
765 # creates a new temporary file (or directory with -d) in the
766 # temporary directory $TRASHTMP_DIRECTORY with pattern prefix NAME
767 test_get_temp() {
768 test_ensure_temp_dir_ "test_get_temp"
769 test z"$1" != z"-d" || set -- "$2" "$1"
770 mktemp $2 "$TRASHTMP_DIRECTORY/${1:+$1.}XXXXXX"
775 ## Note that the following functions have bodies that are NOT indented
776 ## to assist with readability
780 test_lib_main_init_tee() {
781 # Begin test_lib_main_init_tee
784 # if --tee was passed, write the output not only to the terminal, but
785 # additionally to the file test-results/$BASENAME.out, too.
786 case "$TESTLIB_TEST_TEE_STARTED, $* " in
787 done,*)
788 # do not redirect again
790 *' --tee '*|*' --verbose-log '*)
791 mkdir -p "$TEST_OUTPUT_DIRECTORY/test-results"
792 BASE="$TEST_OUTPUT_DIRECTORY/test-results/${0##*/}"
793 BASE="${BASE%.sh}"
795 # Make this filename available to the sub-process in case it is using
796 # --verbose-log.
797 TESTLIB_TEST_TEE_OUTPUT_FILE=$BASE.out
798 export TESTLIB_TEST_TEE_OUTPUT_FILE
800 # Truncate before calling "tee -a" to get rid of the results
801 # from any previous runs.
802 >"$TESTLIB_TEST_TEE_OUTPUT_FILE"
803 >"$BASE.exit"
805 (ec=0; TESTLIB_TEST_TEE_STARTED=done ${SHELL_PATH} "$0" "$@" 2>&1 || ec=$?
806 echo $ec >"$BASE.exit") | tee -a "$TESTLIB_TEST_TEE_OUTPUT_FILE"
807 exitcode="$(cat "$BASE.exit" 2>/dev/null)" || :
808 exit ${exitcode:-1}
810 esac
813 # End test_lib_main_init_tee
817 test_lib_main_init_funcs() {
818 # Begin test_lib_main_init_funcs
821 [ -z "$test_lib_main_init_funcs_done" ] || return 0
823 if test z"$color" != z
824 then
825 say_color_() {
826 test z"$1" != z || test z"${TESTLIB_TEST_TAP_ONLY:-0}" = z"0" || return 0
827 shift
828 test -z "$1" && test -n "$quiet" && test -z "$verbose" && return
829 eval "say_color_color=\$say_color_$1"
830 shift
831 _sfc=
832 _sms="$*"
833 if test -n "$HARNESS_ACTIVE"
834 then
835 case "$_sms" in '#'*)
836 _sfc='#'
837 _sms="${_sms#?}"
838 esac
840 printf '%s\n' "$_sfc$say_color_color$_sms$say_color_reset"
842 else
843 say_color_() {
844 test z"$1" != z || test z"${TESTLIB_TEST_TAP_ONLY:-0}" = z"0" || return 0
845 shift
846 test -z "$1" && test -n "$quiet" && test -z "$verbose" && return
847 shift
848 printf '%s\n' "$*"
852 # Public front-end
853 say_color() { say_color_ "" "$@"; }
855 # Just like say_color except if HARNESS_ACTIVE it's ALWAYS output and WITHOUT color
856 say_color_tap() {
857 if test -n "$HARNESS_ACTIVE"
858 then
859 shift
860 printf '%s\n' "$*"
861 else
862 say_color_ 1 "$@"
867 # Fix some commands on Windows
868 case "${UNAME_S:=$(uname -s)}" in
869 *MINGW*)
870 # Windows has its own (incompatible) sort and find
871 sort() {
872 /usr/bin/sort "$@"
874 find() {
875 /usr/bin/find "$@"
877 sum() {
878 md5sum "$@"
880 # git sees Windows-style pwd
881 pwd() {
882 builtin pwd -W
885 esac
887 test_lib_main_init_funcs_done=1
890 # End test_lib_main_init_funcs
894 # This function is called with all the test args and must perform all
895 # initialization that involves variables and is not specific to "$0"
896 # or "$test_description" in any way. This function may only be called
897 # once per run of the entire test suite.
898 test_lib_main_init_generic() {
899 # Begin test_lib_main_init_generic
901 [ -n "$TESTLIB_DIRECTORY" ] || whats_the_dir -L -- "${TEST_DIRECTORY:-.}/test-lib.sh" TESTLIB_DIRECTORY
902 [ -f "$TESTLIB_DIRECTORY/test-lib.sh" ] && [ -f "$TESTLIB_DIRECTORY/test-lib-main.sh" ] &&
903 [ -f "$TESTLIB_DIRECTORY/test-lib-functions.sh" ] &&
904 [ -f "$TESTLIB_DIRECTORY/test-lib-functions-tg.sh" ] ||
905 fatal "error: invalid TESTLIB_DIRECTORY: $TESTLIB_DIRECTORY"
906 export TESTLIB_DIRECTORY
908 ! [ -f "$TESTLIB_DIRECTORY/../TG-BUILD-SETTINGS" ] || . "$TESTLIB_DIRECTORY/../TG-BUILD-SETTINGS"
909 ! [ -f "$TESTLIB_DIRECTORY/TG-TEST-SETTINGS" ] || . "$TESTLIB_DIRECTORY/TG-TEST-SETTINGS"
911 : "${SHELL_PATH:=/bin/sh}"
912 : "${DIFF:=diff}"
913 : "${GIT_PATH:=$(cmd_path git)}"
914 : "${PERL_PATH:=$(cmd_path perl || :)}"
916 # Test the binaries we have just built. The tests are kept in
917 # t/ subdirectory and are run in 'trash directory' subdirectory.
918 if test -z "$TEST_DIRECTORY"
919 then
920 # We allow tests to override this, in case they want to run tests
921 # outside of t/, e.g. for running tests on the test library
922 # itself.
923 TEST_DIRECTORY="$TESTLIB_DIRECTORY"
924 else
925 # ensure that TEST_DIRECTORY is an absolute path so that it
926 # is valid even if the current working directory is changed
927 TEST_DIRECTORY="$(cd "$TEST_DIRECTORY" && pwd)" || exit 1
929 if test -z "$TEST_HELPER_DIRECTORY" && test -d "$TEST_DIRECTORY/helper"
930 then
931 TEST_HELPER_DIRECTORY="$TEST_DIRECTORY/helper"
933 if test -z "$TEST_OUTPUT_DIRECTORY"
934 then
935 # Similarly, override this to store the test-results subdir
936 # elsewhere
937 TEST_OUTPUT_DIRECTORY="$TEST_DIRECTORY"
939 [ -d "$TESTLIB_DIRECTORY"/empty ] || {
940 mkdir "$TESTLIB_DIRECTORY/empty" || :
941 chmod a-w "$TESTLIB_DIRECTORY/empty" || :
942 test -d "$TESTLIB_DIRECTORY"/empty ||
943 fatal "error: could not make empty directory: '$TESTLIB_DIRECTORY/empty'"
945 EMPTY_DIRECTORY="$TESTLIB_DIRECTORY/empty"
946 export TEST_DIRECTORY TEST_HELPER_DIRECTORY TEST_OUTPUT_DIRECTORY EMPTY_DIRECTORY
947 GIT_CEILING_DIRECTORIES="$TESTLIB_DIRECTORY"
948 [ "$TESTLIB_DIRECTORY" = "$TEST_DIRECTORY" ] ||
949 GIT_CEILING_DIRECTORIES="$TEST_DIRECTORY:$GIT_CEILING_DIRECTORIES"
950 [ "$TESTLIB_DIRECTORY" = "$TEST_OUTPUT_DIRECTORY" ] ||
951 GIT_CEILING_DIRECTORIES="$TEST_OUTPUT_DIRECTORY:$GIT_CEILING_DIRECTORIES"
952 export GIT_CEILING_DIRECTORIES
954 ################################################################
955 # It appears that people try to run tests with missing perl or git...
956 git_version="$("$GIT_PATH" --version 2>&1)" ||
957 fatal 'error: you do not seem to have git available?'
958 case "$git_version" in [Gg][Ii][Tt]\ [Vv][Ee][Rr][Ss][Ii][Oo][Nn]\ [0-9]*);;*)
959 fatal "error: git --version returned bogus value: $git_version"
960 esac
961 ! vcmp "$git_version" '>=' "2.9" || test_auh="--allow-unrelated-histories"
962 #"$PERL_PATH" --version >/dev/null 2>&1 ||
963 # fatal 'error: you do not seem to have perl available?'
965 test_lib_main_init_tee "$@"
967 # For repeatability, reset the environment to known value.
968 # TERM is sanitized below, after saving color control sequences.
969 LANG=C
970 LC_ALL=C
971 PAGER=cat
972 TZ=UTC
973 export LANG LC_ALL PAGER TZ
974 EDITOR=:
975 # A call to "unset" with no arguments causes at least Solaris 10
976 # /usr/xpg4/bin/sh and /bin/ksh to bail out. So keep the unsets
977 # deriving from the command substitution clustered with the other
978 # ones.
979 unset_ VISUAL EMAIL LANGUAGE COLUMNS $("$PERL_PATH" -e '
980 my @env = keys %ENV;
981 my $ok = join("|", qw(
982 TRACE
983 DEBUG
984 USE_LOOKUP
985 TEST
986 .*_TEST
987 MINIMUM_VERSION
988 PATH
989 PROVE
990 UNZIP
991 PERF_
992 CURL_VERBOSE
993 TRACE_CURL
994 CEILING_DIRECTORIES
996 my @vars = grep(/^GIT_/ && !/^GIT_($ok)/o, @env);
997 print join("\n", @vars);
999 unset_ XDG_CONFIG_HOME
1000 unset_ GITPERLLIB
1001 GIT_AUTHOR_NAME='Te s t (Author)'
1002 GIT_AUTHOR_EMAIL=test@example.net
1003 GIT_COMMITTER_NAME='Fra mewor k (Committer)'
1004 GIT_COMMITTER_EMAIL=framework@example.org
1005 GIT_MERGE_VERBOSITY=5
1006 GIT_MERGE_AUTOEDIT=no
1007 GIT_TEMPLATE_DIR="$EMPTY_DIRECTORY"
1008 GIT_CONFIG_NOSYSTEM=1
1009 GIT_ATTR_NOSYSTEM=1
1010 export PATH GIT_TEMPLATE_DIR GIT_CONFIG_NOSYSTEM GIT_ATTR_NOSYSTEM
1011 export GIT_MERGE_VERBOSITY GIT_MERGE_AUTOEDIT
1012 export GIT_AUTHOR_EMAIL GIT_AUTHOR_NAME
1013 export GIT_COMMITTER_EMAIL GIT_COMMITTER_NAME
1014 export EDITOR
1016 # Tests using GIT_TRACE typically don't want <timestamp> <file>:<line> output
1017 GIT_TRACE_BARE=1
1018 export GIT_TRACE_BARE
1020 # Protect ourselves from common misconfiguration to export
1021 # CDPATH into the environment
1022 unset_ CDPATH
1024 unset_ GREP_OPTIONS
1025 unset_ UNZIP
1027 case "$GIT_TRACE" in 1|2|[Tt][Rr][Uu][Ee])
1028 GIT_TRACE=4
1030 esac
1032 # Convenience
1034 # A regexp to match 5 and 40 hexdigits
1035 _x05='[0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f]'
1036 _x40="$_x05$_x05$_x05$_x05$_x05$_x05$_x05$_x05"
1038 # Zero SHA-1
1039 _z40=0000000000000000000000000000000000000000
1041 EMPTY_TREE=4b825dc642cb6eb9a060e54bf8d69288fbee4904
1042 EMPTY_BLOB=e69de29bb2d1d6434b8b29ae775ad8c2e48c5391
1044 # Line feed
1045 LF='
1048 # UTF-8 ZERO WIDTH NON-JOINER, which HFS+ ignores
1049 # when case-folding filenames
1050 u200c="$(printf '\342\200\214')"
1052 export _x05 _x40 _z40 LF u200c EMPTY_TREE EMPTY_BLOB
1054 while test "$#" -ne 0
1056 case "$1" in
1057 -d|--d|--de|--deb|--debu|--debug)
1058 debug=t; shift ;;
1059 -i|--i|--im|--imm|--imme|--immed|--immedi|--immedia|--immediat|--immediate)
1060 immediate=t; shift ;;
1061 -l|--l|--lo|--lon|--long|--long-|--long-t|--long-te|--long-tes|--long-test|--long-tests|\
1062 --ex|--exp|--expe|--expen|--expens|--expensi|--expensiv|--expensive)
1063 TESTLIB_TEST_LONG=t; export TESTLIB_TEST_LONG; shift ;;
1065 shift; test "$#" -ne 0 || {
1066 echo 'error: -r requires an argument' >&2;
1067 exit 1;
1069 run_list=$1; shift ;;
1070 --run=*)
1071 run_list=${1#--*=}; shift ;;
1072 -h|--h|--he|--hel|--help)
1073 help=t; shift ;;
1074 -v|--v|--ve|--ver|--verb|--verbo|--verbos|--verbose)
1075 verbose=t; shift ;;
1076 --verbose-only=*)
1077 verbose_list=${1#--*=}
1078 shift ;;
1079 -q|--q|--qu|--qui|--quie|--quiet)
1080 quiet=t; shift ;;
1081 --no-quiet)
1082 quiet=0; shift ;;
1083 --tap-only)
1084 TESTLIB_TEST_TAP_ONLY=1; shift;;
1085 --no-tap-only)
1086 TESTLIB_TEST_TAP_ONLY=0; shift;;
1087 --color)
1088 color="--color"; shift ;;
1089 --no-color)
1090 color=; shift ;;
1091 --tee)
1092 shift ;; # was handled already
1093 --root=*)
1094 root=${1#--*=}
1095 shift ;;
1096 --chain-lint)
1097 TESTLIB_TEST_CHAIN_LINT=1
1098 shift ;;
1099 --no-chain-lint)
1100 TESTLIB_TEST_CHAIN_LINT=0
1101 shift ;;
1102 -x|--x|--xt|--xtr|--xtra|--xtrac|--xtrace)
1103 trace=t
1104 verbose=t
1105 shift ;;
1106 --verbose-log)
1107 verbose_log=t
1108 shift ;;
1110 echo "error: unknown test option '$1'" >&2; exit 1 ;;
1111 esac
1112 done
1114 test z"$run_list" = z || test z"$quiet" != z || quiet=T
1115 test z"$quiet" != z"0" || quiet=
1116 test z"$quiet" = z || test z"$run_list" = z || test z"$HARNESS_ACTIVE" != z || runquiet=t
1117 test z"$quiet" != z"T" || quiet=
1119 test "x${color+set}" != "xset" &&
1120 test "x$TERM" != "xdumb" && (
1121 { test -n "$TESTLIB_FORCETTY" || test -t 1; } &&
1122 tput bold >/dev/null 2>&1 &&
1123 tput setaf 1 >/dev/null 2>&1 &&
1124 tput sgr0 >/dev/null 2>&1
1125 ) &&
1126 color="--color"
1127 if test z"$color" != z
1128 then
1129 # Save the color control sequences now rather than run tput
1130 # each time say_color() is called. This is done for two
1131 # reasons:
1132 # * TERM will be changed to dumb
1133 # * HOME will be changed to a temporary directory and tput
1134 # might need to read ~/.terminfo from the original HOME
1135 # directory to get the control sequences
1136 getcmd say_color_error eval 'tput setaf 1' # red
1137 getcmd say_color_skip eval 'tput bold; tput setaf 5' # bold blue
1138 getcmd say_color_warn eval 'tput setaf 3' # brown/yellow
1139 getcmd say_color_pass eval 'tput setaf 2' # green
1140 getcmd say_color_info eval 'tput setaf 6' # cyan
1141 getcmd say_color_reset eval 'tput sgr0'
1142 say_color_="" # no formatting for normal text
1145 TERM=dumb
1146 export TERM
1148 test_failure=0
1149 test_count=0
1150 test_fixed=0
1151 test_broken=0
1152 test_success=0
1154 test_external_has_tap=0
1156 # The user-facing functions are loaded from a separate file
1157 . "$TESTLIB_DIRECTORY/test-lib-functions-tg.sh"
1158 . "$TESTLIB_DIRECTORY/test-lib-functions.sh"
1159 test_lib_functions_init
1160 test_lib_functions_tg_init
1162 # Check for shopt
1163 : "${TESTLIB_SHELL_HAS_SHOPT=$(command -v shopt)}"
1165 last_verbose=t
1167 [ -n "$TEST_HELPER_DIRECTORY" ] && [ -d "$TEST_HELPER_DIRECTORY" ] && PATH="$TEST_HELPER_DIRECTORY:$PATH" || :
1168 if [ -n "$TG_TEST_INSTALLED" ]; then
1169 TG_TEST_FULL_PATH="$(cmd_path tg)" && [ -n "$TG_TEST_FULL_PATH" ] ||
1170 fatal 'error: TG_TEST_INSTALLED set but no tg found in $PATH!'
1171 else
1172 tg_bin_dir="$(cd "$TESTLIB_DIRECTORY/../bin-wrappers" 2>/dev/null && pwd -P || :)"
1173 [ -x "$tg_bin_dir/tg" ] ||
1174 fatal 'error: no ../bin-wrappers/tg executable found!'
1175 PATH="$tg_bin_dir:$PATH"
1176 TG_TEST_FULL_PATH="$tg_bin_dir/tg"
1177 test -f "$TESTLIB_DIRECTORY/TG-TEST-SETTINGS" ||
1178 echo 'warning: no TG-TEST-SETTINGS file found (run `make settings`)' >&2
1180 export TG_TEST_FULL_PATH
1181 tg_version="$(tg --version)" ||
1182 fatal 'error: tg --version failed!'
1183 case "$tg_version" in [Tt][Oo][Pp][Gg][Ii][Tt]\ [Vv][Ee][Rr][Ss][Ii][Oo][Nn]\ [0-9]*);;*)
1184 fatal "error: tg --version returned bogus value: $tg_version"
1185 esac
1187 vcmp "$git_version" '>=' "$GIT_MINIMUM_VERSION" ||
1188 fatal "git version >= $GIT_MINIMUM_VERSION required but found \"$git_version\" instead"
1190 if test -z "$TESTLIB_TEST_CMP"
1191 then
1192 if test -n "$TESTLIB_TEST_CMP_USE_COPIED_CONTEXT"
1193 then
1194 TESTLIB_TEST_CMP="$DIFF -c"
1195 else
1196 TESTLIB_TEST_CMP="$DIFF -u"
1200 # Fix some commands on Windows
1201 case "${UNAME_S:=$(uname -s)}" in
1202 *MINGW*)
1203 # no POSIX permissions
1204 # backslashes in pathspec are converted to '/'
1205 # exec does not inherit the PID
1206 test_set_prereq MINGW
1207 test_set_prereq NATIVE_CRLF
1208 test_set_prereq SED_STRIPS_CR
1209 test_set_prereq GREP_STRIPS_CR
1210 TESTLIB_TEST_CMP=mingw_test_cmp
1212 *CYGWIN*)
1213 test_set_prereq POSIXPERM
1214 test_set_prereq EXECKEEPSPID
1215 test_set_prereq CYGWIN
1216 test_set_prereq SED_STRIPS_CR
1217 test_set_prereq GREP_STRIPS_CR
1220 test_set_prereq POSIXPERM
1221 test_set_prereq BSLASHPSPEC
1222 test_set_prereq EXECKEEPSPID
1224 esac
1226 ( COLUMNS=1 && test $COLUMNS = 1 ) && test_set_prereq COLUMNS_CAN_BE_1
1228 test_lib_main_init_funcs
1230 test_lazy_prereq PIPE '
1231 # test whether the filesystem supports FIFOs
1232 case "${UNAME_S:=$(uname -s)}" in
1233 CYGWIN*|MINGW*)
1234 false
1237 rm -f testfifo && mkfifo testfifo
1239 esac
1242 test_lazy_prereq SYMLINKS '
1243 # test whether the filesystem supports symbolic links
1244 ln -s x y && test -h y
1247 test_lazy_prereq FILEMODE '
1248 test_ensure_git_dir_ &&
1249 test "$(git config --bool core.filemode)" = true
1252 test_lazy_prereq CASE_INSENSITIVE_FS '
1253 echo good >CamelCase &&
1254 echo bad >camelcase &&
1255 test "$(cat CamelCase)" != good
1258 test_lazy_prereq UTF8_NFD_TO_NFC '
1259 # check whether FS converts nfd unicode to nfc
1260 auml="$(printf "\303\244")"
1261 aumlcdiar="$(printf "\141\314\210")"
1262 >"$auml" &&
1263 case "$(echo *)" in
1264 "$aumlcdiar")
1265 true ;;
1267 false ;;
1268 esac
1271 test_lazy_prereq AUTOIDENT '
1272 test_ensure_git_dir_ &&
1273 sane_unset GIT_AUTHOR_NAME &&
1274 sane_unset GIT_AUTHOR_EMAIL &&
1275 git var GIT_AUTHOR_IDENT
1278 test_lazy_prereq EXPENSIVE '
1279 test -n "$TESTLIB_TEST_LONG"
1282 test_lazy_prereq USR_BIN_TIME '
1283 test -x /usr/bin/time
1286 test_lazy_prereq NOT_ROOT '
1287 uid="$(id -u)" &&
1288 test "$uid" != 0
1291 # SANITY is about "can you correctly predict what the filesystem would
1292 # do by only looking at the permission bits of the files and
1293 # directories?" A typical example of !SANITY is running the test
1294 # suite as root, where a test may expect "chmod -r file && cat file"
1295 # to fail because file is supposed to be unreadable after a successful
1296 # chmod. In an environment (i.e. combination of what filesystem is
1297 # being used and who is running the tests) that lacks SANITY, you may
1298 # be able to delete or create a file when the containing directory
1299 # doesn't have write permissions, or access a file even if the
1300 # containing directory doesn't have read or execute permissions.
1302 test_lazy_prereq SANITY '
1303 mkdir SANETESTD.1 SANETESTD.2 &&
1305 chmod +w SANETESTD.1 SANETESTD.2 &&
1306 >SANETESTD.1/x 2>SANETESTD.2/x &&
1307 chmod -w SANETESTD.1 &&
1308 chmod -r SANETESTD.1/x &&
1309 chmod -rx SANETESTD.2 ||
1310 error "bug in test sript: cannot prepare SANETESTD"
1312 ! test -r SANETESTD.1/x &&
1313 ! rm SANETESTD.1/x && ! test -f SANETESTD.2/x
1314 status=$?
1316 chmod +rwx SANETESTD.1 SANETESTD.2 &&
1317 rm -rf SANETESTD.1 SANETESTD.2 ||
1318 error "bug in test sript: cannot clean SANETESTD"
1319 return $status
1322 test_lazy_prereq CMDLINE_LIMIT 'run_with_limited_cmdline true'
1325 # End test_lib_main_init_generic
1329 # This function is guaranteed to always be called for every single test.
1330 # Only put things in this function that MUST be done per-test, function
1331 # definitions and sourcing other files generally DO NOT QUALIFY (there can
1332 # be exceptions).
1333 test_lib_main_init_specific() {
1334 # Begin test_lib_main_init_specific
1337 # original stdin is on 6, stdout on 5 and stderr on 7
1338 exec 5>&1 6<&0 7>&2
1340 test_lib_main_init_funcs
1342 if test -n "$HARNESS_ACTIVE"
1343 then
1344 if test "$verbose" = t || test -n "$verbose_list" && test -z "$verbose_log$TESTLIB_OVERRIDE"
1345 then
1346 printf 'Bail out! %s\n' \
1347 'verbose mode forbidden under TAP harness; use --verbose-log'
1348 exit 1
1352 test z"${TESTLIB_TEST_TAP_ONLY:-0}" = z"0" || test -z "$verbose$verbose_list" ||
1353 test -n "$verbose_log$TESTLIB_OVERRIDE" || {
1354 if test z"$TESTLIB_TEST_TAP_ONLY" = z"-1"; then
1355 unset_ TESTLIB_TEST_TAP_ONLY
1356 say_color "" "# auto-deactivating TESTLIB_TEST_TAP_ONLY=-1 in verbose mode"
1357 else
1358 printf 'Bail out! %s\n' \
1359 'verbose mode forbidden with TESTLIB_TEST_TAP_ONLY; use --verbose-log'
1360 exit 1
1364 test "${test_description}" != "" ||
1365 error "Test script did not set test_description."
1367 if test "$help" = "t"
1368 then
1369 printf '%s\n' "$(printf '%s\n' "$test_description")" |
1370 sed -n -e '
1372 :loop
1373 s/\([^ ]\)/\1/
1374 t rest
1376 b loop
1378 :rest
1381 exit 0
1384 if test "$verbose_log" = "t"
1385 then
1386 exec 3>>"$TESTLIB_TEST_TEE_OUTPUT_FILE" 4>&3
1387 elif test "$verbose" = "t"
1388 then
1389 exec 4>&2 3>&1
1390 else
1391 exec 4>/dev/null 3>/dev/null
1394 # Send any "-x" output directly to stderr to avoid polluting tests
1395 # which capture stderr. We can do this unconditionally since it
1396 # has no effect if tracing isn't turned on.
1398 # Note that this sets up the trace fd as soon as we assign the variable, so it
1399 # must come after the creation of descriptor 4 above. Likewise, we must never
1400 # unset this, as it has the side effect of closing descriptor 4, which we
1401 # use to show verbose tests to the user.
1403 # Note also that we don't need or want to export it. The tracing is local to
1404 # this shell, and we would not want to influence any shells we exec.
1405 BASH_XTRACEFD=4
1407 TESTLIB_EXIT_OK=
1408 TRAPEXIT_='_die'
1409 trap 'trapexit_ 129' HUP
1410 trap 'trapexit_ 130' INT
1411 trap 'trapexit_ 131' QUIT
1412 trap 'trapexit_ 134' ABRT
1413 trap 'trapexit_ 141' PIPE
1414 trap 'trapexit_ 143' TERM
1415 trap 'TESTLIB_EXIT_OK=t; trapexit_ 1' USR1
1417 # Test repository
1418 TRASH_DIRECTORY="${0%.sh}"
1419 test z"${TRASH_DIRECTORY##*/}" != z"sh" || TRASH_DIRECTORY="xsh"
1420 TRASH_DIRECTORY="trash directory.${TRASH_DIRECTORY##*/}"
1421 TRASHTMP_DIRECTORY="${0%.sh}"
1422 test z"${TRASHTMP_DIRECTORY##*/}" != z"sh" || TRASHTMP_DIRECTORY="xsh"
1423 TRASHTMP_DIRECTORY="trash tmp directory.${TRASHTMP_DIRECTORY##*/}"
1424 test -n "$root" && TRASH_DIRECTORY="$root/$TRASH_DIRECTORY"
1425 test -n "$root" && TRASHTMP_DIRECTORY="$root/$TRASHTMP_DIRECTORY"
1426 test -n "$root" && GIT_CEILING_DIRECTORIES="$root:$GIT_CEILING_DIRECTORIES"
1427 case "$TRASH_DIRECTORY" in
1428 /*) ;; # absolute path is good
1429 *) TRASH_DIRECTORY="$TEST_OUTPUT_DIRECTORY/$TRASH_DIRECTORY"
1430 TRASHTMP_DIRECTORY="$TEST_OUTPUT_DIRECTORY/$TRASHTMP_DIRECTORY" ;;
1431 esac
1432 test ! -z "$debug" || remove_trash="$TRASH_DIRECTORY"
1433 test ! -z "$debug" || remove_trashtmp="$TRASHTMP_DIRECTORY"
1434 ! test -e "$TRASH_DIRECTORY" || {
1435 { rm -rf "$TRASH_DIRECTORY" || :; } >/dev/null 2>&1 &&
1436 ! test -e "$TRASH_DIRECTORY" || {
1437 chmod -R u+rw "$TRASH_DIRECTORY" &&
1438 rm -rf "$TRASH_DIRECTORY" &&
1439 ! test -e "$TRASH_DIRECTORY"
1441 } &&
1442 ! test -e "$TRASHTMP_DIRECTORY" || {
1443 { rm -rf "$TRASHTMP_DIRECTORY" || :; } >/dev/null 2>&1 &&
1444 ! test -e "$TRASHTMP_DIRECTORY" || {
1445 chmod -R u+rw "$TRASHTMP_DIRECTORY" &&
1446 rm -rf "$TRASHTMP_DIRECTORY" &&
1447 ! test -e "$TRASHTMP_DIRECTORY"
1449 } || {
1450 TESTLIB_EXIT_OK=t
1451 echo >&5 "FATAL: Cannot prepare test area"
1452 exit 1
1455 HOME="$TRASH_DIRECTORY"
1456 GNUPGHOME="$HOME/gnupg-home-not-used"
1457 export HOME GNUPGHOME
1459 if test -z "$TEST_NO_CREATE_REPO"
1460 then
1461 test_create_repo "$TRASH_DIRECTORY"
1462 else
1463 mkdir -p "$TRASH_DIRECTORY"
1465 # $TRASHTMP_DIRECTORY is created on-demand only
1467 # Use -P to resolve symlinks in our working directory so that the cwd
1468 # in subprocesses like tg equals our $PWD (for pathname comparisons).
1469 cd -P "$TRASH_DIRECTORY" || exit 1
1471 this_test=${0##*/}
1472 this_test=${this_test%%-*}
1473 test_called_test_plan=
1474 test_wrote_plan_count=
1475 test_last_subtest_ok=1
1476 if match_pattern_list "$this_test" $TESTLIB_SKIP_TESTS
1477 then
1478 say_color info >&3 "skipping test $this_test altogether"
1479 skip_all="skip all tests in $this_test"
1480 test_done
1483 if test z"${TESTLIB_SHELL_HAS_SHOPT=$(command -v shopt)}" = z"shopt"
1484 then
1485 shopt -s expand_aliases >/dev/null 2>&1 || :
1488 # End test_lib_main_init_specific
1493 # THIS SHOULD ALWAYS BE THE LAST FUNCTION DEFINED IN THIS FILE
1495 # Any client that sources this file should immediately execute this function
1496 # afterwards with the command line arguments
1498 # THERE SHOULD NOT BE ANY DIRECTLY EXECUTED LINES OF CODE IN THIS FILE
1500 test_lib_main_init() {
1502 test_lib_main_init_generic "$@"
1503 test_lib_main_init_specific "$@"