1 # Test framework from Git with modifications.
3 # Modifications Copyright (C) 2016,2017 Kyle J. McKay. All rights reserved.
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!
43 { "unset" -f command unset unalias "$1"; } >/dev
/null
2>&1 ||
:
44 { "unalias" -a; } >/dev
/null
2>&1 ||
:
49 printf '%s\n' "$*" >&2
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)
59 [ -n "$1" ] ||
return 1
60 eval "$1=" >/dev
/null
2>&1 ||
return 1
61 [ -n "$2" ] ||
return 1
65 _getcmd_result
="$(ec=0; ("$@
") || ec=$?; echo Z; exit $ec)" || _getcmd_ec
=$?
66 eval "$_getcmd_vn=\"\${_getcmd_result%Z}\""
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
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
81 elif [ "z$1" = "z--" ]; then
84 case "$1" in *"/"*);;*) set -- "./$1" "$2" "$3"; esac
86 set -- "$(readlink "$1")" "$2" "$3" "$1"
87 case "$1" in "/"*);;*)
88 set -- "${4%/*}/$1" "$2" "$3"
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
98 set -- "$(cd "$1" && pwd $3)" "$2"
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.]*}"
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
125 elif [ "${vcmp_a_:-0}" -gt "${vcmp_b_:-0}" ]; then
126 unset vcmp_a_ vcmp_b_
127 case "$2" in ">"|
">="|
"!=") return 0; esac
130 vcmp_a_
="${1#$vcmp_a_}"
131 vcmp_b_
="${3#$vcmp_b_}"
132 set -- "${vcmp_a_#.}" "$2" "${vcmp_b_#.}"
134 unset vcmp_a_ vcmp_b_
135 case "$2" in "="|
"=="|
"<="|
">=") return 0; esac
144 say_color error
"${LF}error: $*" >&7
145 printf '%s\n' "Bail out! ${0##*/}:${callerlno:+$callerlno:} error: $*" >&5
147 [ -z "$TESTLIB_TEST_PARENT_INT_ON_ERROR" ] ||
{
148 perl
-e "kill(-2, getpgrp($TESTLIB_TEST_PARENT_INT_ON_ERROR), getpgrp($PPID))" ||
:
149 kill -INT $TESTLIB_TEST_PARENT_INT_ON_ERROR $PPID ||
:
157 alias error
='error_lno "$LINENO"' >/dev
/null
2>&1 ||
:
164 say_color_tap info
"$@"
169 if test -n "$TESTLIB_EXIT_OK"
173 echo >&5 "FATAL: Unexpected exit with code $code"
179 # You are not expected to call test_ok_ and test_failure_ directly, use
180 # the test_expect_* functions instead.
183 test_success
=$
(($test_success + 1))
184 say_color_tap
"" "ok $test_count - $@"
188 test_failure
=$
(($test_failure + 1))
191 say_color_tap error
"not ok $test_count - $1"
193 printf '%s\n' "$(printf '%s\n' "failed
: ${0##*/}${tlno:+:$tlno}$LF$
*")" |
214 test "$immediate" = "" ||
{ TESTLIB_EXIT_OK
=t
; exit 1; }
217 test_known_broken_ok_
() {
218 test_fixed
=$
(($test_fixed + 1))
219 say_color_tap warn
"ok $test_count - $@ # TODO known breakage vanished"
222 test_known_broken_failure_
() {
223 test_broken
=$
(($test_broken + 1))
224 say_color_tap warn
"not ok $test_count - $@ # TODO known breakage"
227 test_possibly_broken_ok_
() {
228 test_success
=$
(($test_success + 1))
229 say_color_tap
"" "ok $test_count - $@"
232 test_possibly_broken_failure_
() {
233 test_broken
=$
(($test_broken + 1))
234 say_color_tap warn
"not ok $test_count - $@ # TODO tolerated breakage"
238 test "$debug" = "" ||
test $# -eq 0 ||
test -z "$*" ||
{ "$@"; } >&7 2>&1
241 match_pattern_list
() {
244 test -z "$*" && return 1
255 match_test_selector_list
() {
260 test -z "$1" && return 0
262 # Both commas and whitespace are accepted as separators.
268 # If the first selector is negative we include by default.
276 orig_selector
=$selector
282 selector
=${selector##?}
286 test -z "$selector" && continue
290 if x_
="${selector%%-*}" && test "z$x_" != "z${x_#*[!0-9]}"
292 echo "error: $title: invalid non-numeric in range" \
293 "start: '$orig_selector'" >&2
296 if x_
="${selector#*-}" && test "z$x_" != "z${x_#*[!0-9]}"
298 echo "error: $title: invalid non-numeric in range" \
299 "end: '$orig_selector'" >&2
305 if test "z$selector" != "z${selector#*[!0-9]}"
307 echo "error: $title: invalid non-numeric in test" \
308 "selector: '$orig_selector'" >&2
313 # Short cut for "obvious" cases
314 test -z "$include" && test -z "$positive" && continue
315 test -n "$include" && test -n "$positive" && continue
319 if test $arg -le ${selector#-}
325 if test $arg -ge ${selector%-}
331 if test ${selector%%-*} -le $arg \
332 && test $arg -le ${selector#*-}
338 if test $arg -eq $selector
349 maybe_teardown_verbose
() {
350 test -z "$verbose_only" && return
351 exec 4>/dev
/null
3>/dev
/null
355 maybe_setup_verbose
() {
356 test -z "$verbose_only" && return
357 if match_pattern_list
$test_count $verbose_only
359 if test "$verbose_log" = "t"
361 exec 3>>"$TESTLIB_TEST_TEE_OUTPUT_FILE" 4>&3
365 # Emit a delimiting blank line when going from
366 # non-verbose to verbose. Within verbose mode the
367 # delimiter is printed by test_expect_*. The choice
368 # of the initial $last_verbose is such that before
369 # test 1, we do not print it.
370 test -z "$last_verbose" && echo >&3 ""
373 exec 4>/dev
/null
3>/dev
/null
376 last_verbose
=$verbose
380 test "$trace" = t
&& test "$verbose" = t
383 # This is a separate function because some tests use
384 # "return" to end a test_expect_success block early
385 # (and we want to make sure we run any cleanup like
388 # Do not add anything extra (including LF) after '$*'
391 test_subshell_active_=t
392 ! want_trace || ! set -x && ! :
396 # Same thing as test_eval_inner_ but without the subshell
397 test_eval_inner_no_subshell_
() {
398 # Do not add anything extra (including LF) after '$*'
400 ! want_trace || ! set -x && ! :
405 # We run this block with stderr redirected to avoid extra cruft
406 # during a "-x" trace. Once in "set -x" mode, we cannot prevent
407 # the shell from printing the "set +x" to turn it off (nor the saving
408 # of $? before that). But we can make sure that the output goes to
411 # The test itself is run with stderr put back to &4 (so either to
412 # /dev/null, or to the original stderr if --verbose was used).
416 if test "${test_eval_ss_:-0}" = "0"
418 test_eval_inner_no_subshell_
"$@" </dev
/null
>&3 2>&4
420 test_eval_inner_
"$@" </dev
/null
>&3 2>&4
426 if test "$test_eval_ret_" != 0
428 say_color error
>&4 "error: last command exited with \$?=$test_eval_ret_"
432 return $test_eval_ret_
435 # Calls the real test_eval_ss_ with !"$TESTLIB_TEST_NO_SUBSHELL" as first arg
437 if test -n "$TESTLIB_TEST_NO_SUBSHELL"
439 test_eval_ss_
"0" "$@"
441 test_eval_ss_
"1" "$@"
445 # If "$1" = "-" read the script from stdin but ONLY if stdin is NOT a tty
446 # Store the test script in test_script_
450 ! test -t 0 || error
"test script is '-' but STDIN is a tty"
451 test_script_
="$(cat)"
452 test -n "$test_script_" || error
"test script is '-' but STDIN is empty"
453 test_script_
="$LF$test_script_$LF"
460 test z
"$2" = "z" ||
set +e
466 test_subshell_active_
=
470 if test "${TESTLIB_TEST_CHAIN_LINT:-1}" != 0; then
471 # turn off tracing for this test-eval, as it simply creates
472 # confusing noise in the "-x" output
476 # 117 is magic because it is unlikely to match the exit
477 # code of other programs
478 test_eval_ss_
"1" "fail_ 117 && $1${LF}fail_ \$? 1"
479 if test "$?" != 117; then
480 error
"bug in the test script: broken &&-chain: $1"
489 if test -z "$immediate" ||
test $eval_ret = 0 ||
490 test -n "$expecting_failure" && test "${test_cleanup:-:}" != ":"
492 test_eval_
"$test_cleanup"
494 if test "$verbose" = "t" && test -n "$HARNESS_ACTIVE"
502 test_count
=$
(($test_count+1))
508 maybe_teardown_verbose
514 if match_pattern_list
$this_test.
$test_count $TESTLIB_SKIP_TESTS
517 skipped_reason
="TESTLIB_SKIP_TESTS"
519 if test -z "$to_skip" && test -n "$test_prereq" &&
520 ! test_have_prereq
"$test_prereq"
525 if test "$missing_prereq" != "$test_prereq"
527 of_prereq
=" of $test_prereq"
529 skipped_reason
="missing $missing_prereq${of_prereq}"
531 if test -z "$to_skip" && test -n "$run_list" &&
532 ! match_test_selector_list
'--run' $test_count "$run_list"
535 skipped_reason
="--run"
540 say_color skip
>&3 "skipping test: $@"
541 say_color_tap skip
"ok $test_count # skip $1 ($skipped_reason)"
550 # stub; runs at end of each successful test
551 test_at_end_hook_
() {
558 if test -z "$HARNESS_ACTIVE"
560 test_results_dir
="$TEST_OUTPUT_DIRECTORY/test-results"
561 mkdir
-p "$test_results_dir"
563 test_results_path
="$test_results_dir/${base%.sh}.counts"
565 cat >"$test_results_path" <<-EOF
567 success $test_success
575 if test "$test_fixed" != 0
577 say_color error
"# $this_test $test_fixed known breakage(s) vanished; please update test(s)"
579 if test "$test_broken" != 0
581 say_color warn
"# $this_test still have $test_broken known breakage(s)"
583 if test "$test_broken" != 0 ||
test "$test_fixed" != 0
585 test_remaining
=$
(( $test_count - $test_broken - $test_fixed ))
586 msg
="remaining $test_remaining test(s)"
588 test_remaining
=$test_count
589 msg
="$test_count test(s)"
591 case "$test_failure" in
593 # Maybe print SKIP message
594 if test -n "$skip_all" && test $test_count -gt 0
596 error
"Can't use skip_all after running some tests"
598 test -z "$skip_all" || skip_all
=" # SKIP $skip_all"
600 if test $test_external_has_tap -eq 0
602 if test $test_remaining -gt 0
604 say_color pass
"# $this_test passed all $msg"
606 test -n "$test_wrote_plan_count" || say_tap
"1..$test_count$skip_all"
608 if test -n "$test_wrote_plan_count" && test "$test_wrote_plan_count" -ne "$test_count"
610 say_color error
"# $this_test plan count of $test_wrote_plan_count does not match run count of $test_count"
614 test -n "$remove_trash" &&
615 test -d "$remove_trash" &&
616 cd "${remove_trash%/*}" &&
617 test_done_td_
="${remove_trash##*/}" &&
618 test -e "$test_done_td_" &&
619 rm -rf "$test_done_td_" &&
621 ! test -e "$test_done_td_" ||
{
622 chmod -R u
+w
"$test_done_td_" &&
623 rm -rf "$test_done_td_"
632 if test $test_external_has_tap -eq 0
634 say_color error
"# $this_test failed $test_failure among $msg"
635 test -n "$test_wrote_plan_count" || say_tap
"1..$test_count"
637 if test -n "$test_wrote_plan_count" && test "$test_wrote_plan_count" -ne "$test_count"
639 say_color error
"# $this_test plan count of $test_wrote_plan_count does not match run count of $test_count"
642 test -z "$HARNESS_ACTIVE" ||
exit 0
649 test -n "$1" && test "z$1" = "z${1#*[!0-9]}" || fatal
"invalid test_plan argument: $1"
650 test "$1" -eq 0 ||
test -z "$2" || fatal
"invalid test_plan arguments: $*"
651 if test "$1" -eq 0; then
652 skip_all
="${2:-skip all tests in $this_test}"
655 test $test_external_has_tap -ne 0 || say_tap
"1..$1"
656 test_wrote_plan_count
="$1"
659 # Provide an implementation of the 'yes' utility
676 run_with_limited_cmdline
() {
677 (ulimit -s 128 && "$@")
682 ## Note that the following functions have bodies that are NOT indented
683 ## to assist with readability
687 test_lib_main_init_tee
() {
688 # Begin test_lib_main_init_tee
691 # if --tee was passed, write the output not only to the terminal, but
692 # additionally to the file test-results/$BASENAME.out, too.
693 case "$TESTLIB_TEST_TEE_STARTED, $* " in
695 # do not redirect again
697 *' --tee '*|
*' --verbose-log '*)
698 mkdir
-p "$TEST_OUTPUT_DIRECTORY/test-results"
699 BASE
="$TEST_OUTPUT_DIRECTORY/test-results/${0##*/}"
702 # Make this filename available to the sub-process in case it is using
704 TESTLIB_TEST_TEE_OUTPUT_FILE
=$BASE.out
705 export TESTLIB_TEST_TEE_OUTPUT_FILE
707 # Truncate before calling "tee -a" to get rid of the results
708 # from any previous runs.
709 >"$TESTLIB_TEST_TEE_OUTPUT_FILE"
712 (ec
=0; TESTLIB_TEST_TEE_STARTED
=done ${SHELL_PATH} "$0" "$@" 2>&1 || ec
=$?
713 echo $ec >"$BASE.exit") |
tee -a "$TESTLIB_TEST_TEE_OUTPUT_FILE"
714 exitcode
="$(cat "$BASE.
exit" 2>/dev/null)" ||
:
720 # End test_lib_main_init_tee
724 test_lib_main_init_funcs
() {
725 # Begin test_lib_main_init_funcs
728 [ -z "$test_lib_main_init_funcs_done" ] ||
return 0
733 test -z "$1" && test -n "$quiet" && return
734 eval "say_color_color=\$say_color_$1"
738 if test -n "$HARNESS_ACTIVE"
740 case "$_sms" in '#'*)
745 printf '%s\n' "$_sfc$say_color_color$_sms$say_color_reset"
749 test -z "$1" && test -n "$quiet" && return
755 # Just like say_color except if HARNESS_ACTIVE it's ALWAYS output and WITHOUT color
757 if test -n "$HARNESS_ACTIVE"
767 # Fix some commands on Windows
768 case "${UNAME_S:=$(uname -s)}" in
770 # Windows has its own (incompatible) sort and find
780 # git sees Windows-style pwd
787 test_lib_main_init_funcs_done
=1
790 # End test_lib_main_init_funcs
794 # This function is called with all the test args and must perform all
795 # initialization that involves variables and is not specific to "$0"
796 # or "$test_description" in any way. This function may only be called
797 # once per run of the entire test suite.
798 test_lib_main_init_generic
() {
799 # Begin test_lib_main_init_generic
801 [ -n "$TESTLIB_DIRECTORY" ] || whats_the_dir
-L -- "${TEST_DIRECTORY:-.}/test-lib.sh" TESTLIB_DIRECTORY
802 [ -f "$TESTLIB_DIRECTORY/test-lib.sh" ] && [ -f "$TESTLIB_DIRECTORY/test-lib-main.sh" ] &&
803 [ -f "$TESTLIB_DIRECTORY/test-lib-functions.sh" ] &&
804 [ -f "$TESTLIB_DIRECTORY/test-lib-functions-tg.sh" ] ||
805 fatal
"error: invalid TESTLIB_DIRECTORY: $TESTLIB_DIRECTORY"
806 export TESTLIB_DIRECTORY
808 ! [ -f "$TESTLIB_DIRECTORY/../TG-BUILD-SETTINGS" ] || .
"$TESTLIB_DIRECTORY/../TG-BUILD-SETTINGS"
809 ! [ -f "$TESTLIB_DIRECTORY/TG-TEST-SETTINGS" ] || .
"$TESTLIB_DIRECTORY/TG-TEST-SETTINGS"
811 : "${SHELL_PATH:=/bin/sh}"
813 : "${GIT_PATH:=$(cmd_path git)}"
814 : "${PERL_PATH:=$(cmd_path perl || :)}"
816 # Test the binaries we have just built. The tests are kept in
817 # t/ subdirectory and are run in 'trash directory' subdirectory.
818 if test -z "$TEST_DIRECTORY"
820 # We allow tests to override this, in case they want to run tests
821 # outside of t/, e.g. for running tests on the test library
823 TEST_DIRECTORY
="$TESTLIB_DIRECTORY"
825 # ensure that TEST_DIRECTORY is an absolute path so that it
826 # is valid even if the current working directory is changed
827 TEST_DIRECTORY
="$(cd "$TEST_DIRECTORY" && pwd)" ||
exit 1
829 if test -z "$TEST_HELPER_DIRECTORY" && test -d "$TEST_DIRECTORY/helper"
831 TEST_HELPER_DIRECTORY
="$TEST_DIRECTORY/helper"
833 if test -z "$TEST_OUTPUT_DIRECTORY"
835 # Similarly, override this to store the test-results subdir
837 TEST_OUTPUT_DIRECTORY
="$TEST_DIRECTORY"
839 [ -d "$TESTLIB_DIRECTORY"/empty
] ||
{
840 mkdir
"$TESTLIB_DIRECTORY/empty" ||
:
841 chmod a-w
"$TESTLIB_DIRECTORY/empty" ||
:
842 test -d "$TESTLIB_DIRECTORY"/empty ||
843 fatal
"error: could not make empty directory: '$TESTLIB_DIRECTORY/empty'"
845 EMPTY_DIRECTORY
="$TESTLIB_DIRECTORY/empty"
846 export TEST_DIRECTORY TEST_HELPER_DIRECTORY TEST_OUTPUT_DIRECTORY EMPTY_DIRECTORY
847 GIT_CEILING_DIRECTORIES
="$TESTLIB_DIRECTORY"
848 [ "$TESTLIB_DIRECTORY" = "$TEST_DIRECTORY" ] ||
849 GIT_CEILING_DIRECTORIES
="$TEST_DIRECTORY:$GIT_CEILING_DIRECTORIES"
850 [ "$TESTLIB_DIRECTORY" = "$TEST_OUTPUT_DIRECTORY" ] ||
851 GIT_CEILING_DIRECTORIES
="$TEST_OUTPUT_DIRECTORY:$GIT_CEILING_DIRECTORIES"
852 export GIT_CEILING_DIRECTORIES
854 ################################################################
855 # It appears that people try to run tests with missing perl or git...
856 git_version
="$("$GIT_PATH" --version 2>&1)" ||
857 fatal
'error: you do not seem to have git available?'
858 case "$git_version" in [Gg
][Ii
][Tt
]\
[Vv
][Ee
][Rr
][Ss
][Ii
][Oo
][Nn
]\
[0-9]*);;*)
859 fatal
"error: git --version returned bogus value: $git_version"
861 #"$PERL_PATH" --version >/dev/null 2>&1 ||
862 # fatal 'error: you do not seem to have perl available?'
864 test_lib_main_init_tee
"$@"
866 # For repeatability, reset the environment to known value.
867 # TERM is sanitized below, after saving color control sequences.
872 export LANG LC_ALL PAGER TZ
874 # A call to "unset" with no arguments causes at least Solaris 10
875 # /usr/xpg4/bin/sh and /bin/ksh to bail out. So keep the unsets
876 # deriving from the command substitution clustered with the other
878 unset VISUAL EMAIL LANGUAGE COLUMNS $
("$PERL_PATH" -e '
880 my $ok = join("|", qw(
895 my @vars = grep(/^GIT_/ && !/^GIT_($ok)/o, @env);
896 print join("\n", @vars);
898 unset XDG_CONFIG_HOME
900 GIT_AUTHOR_NAME
='Te s t'
901 GIT_AUTHOR_EMAIL
=test@example.net
902 GIT_COMMITTER_NAME
='Fra mewor k'
903 GIT_COMMITTER_EMAIL
=framework@example.org
904 GIT_MERGE_VERBOSITY
=5
905 GIT_MERGE_AUTOEDIT
=no
906 GIT_TEMPLATE_DIR
="$EMPTY_DIRECTORY"
907 GIT_CONFIG_NOSYSTEM
=1
909 export PATH GIT_TEMPLATE_DIR GIT_CONFIG_NOSYSTEM GIT_ATTR_NOSYSTEM
910 export GIT_MERGE_VERBOSITY GIT_MERGE_AUTOEDIT
911 export GIT_AUTHOR_EMAIL GIT_AUTHOR_NAME
912 export GIT_COMMITTER_EMAIL GIT_COMMITTER_NAME
915 # Tests using GIT_TRACE typically don't want <timestamp> <file>:<line> output
917 export GIT_TRACE_BARE
919 # Protect ourselves from common misconfiguration to export
920 # CDPATH into the environment
926 case "$GIT_TRACE" in 1|
2|
[Tt
][Rr
][Uu
][Ee
])
933 # A regexp to match 5 and 40 hexdigits
934 _x05
='[0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f]'
935 _x40
="$_x05$_x05$_x05$_x05$_x05$_x05$_x05$_x05"
938 _z40
=0000000000000000000000000000000000000000
940 EMPTY_TREE
=4b825dc642cb6eb9a060e54bf8d69288fbee4904
941 EMPTY_BLOB
=e69de29bb2d1d6434b8b29ae775ad8c2e48c5391
947 # UTF-8 ZERO WIDTH NON-JOINER, which HFS+ ignores
948 # when case-folding filenames
949 u200c
="$(printf '\342\200\214')"
951 export _x05 _x40 _z40 LF u200c EMPTY_TREE EMPTY_BLOB
953 while test "$#" -ne 0
956 -d|
--d|
--de|
--deb|
--debu|
--debug)
958 -i|
--i|
--im|
--imm|
--imme|
--immed|
--immedi|
--immedia|
--immediat|
--immediate)
959 immediate
=t
; shift ;;
960 -l|
--l|
--lo|
--lon|
--long|
--long-|
--long-t|
--long-te|
--long-tes|
--long-test|
--long-tests|\
961 --ex|
--exp|
--expe|
--expen|
--expens|
--expensi|
--expensiv|
--expensive)
962 TESTLIB_TEST_LONG
=t
; export TESTLIB_TEST_LONG
; shift ;;
964 shift; test "$#" -ne 0 ||
{
965 echo 'error: -r requires an argument' >&2;
968 run_list
=$1; shift ;;
970 run_list
=${1#--*=}; shift ;;
971 -h|
--h|
--he|
--hel|
--help)
973 -v|
--v|
--ve|
--ver|
--verb|
--verbo|
--verbos|
--verbose)
976 verbose_only
=${1#--*=}
978 -q|
--q|
--qu|
--qui|
--quie|
--quiet)
985 shift ;; # was handled already
990 TESTLIB_TEST_CHAIN_LINT
=1
993 TESTLIB_TEST_CHAIN_LINT
=0
995 -x|
--x|
--xt|
--xtr|
--xtra|
--xtrac|
--xtrace)
1003 echo "error: unknown test option '$1'" >&2; exit 1 ;;
1007 test "x${color+set}" != "xset" &&
1008 test "x$TERM" != "xdumb" && (
1009 { test -n "$TESTLIB_FORCETTY" ||
test -t 1; } &&
1010 tput bold
>/dev
/null
2>&1 &&
1011 tput setaf
1 >/dev
/null
2>&1 &&
1012 tput sgr0
>/dev
/null
2>&1
1017 # Save the color control sequences now rather than run tput
1018 # each time say_color() is called. This is done for two
1020 # * TERM will be changed to dumb
1021 # * HOME will be changed to a temporary directory and tput
1022 # might need to read ~/.terminfo from the original HOME
1023 # directory to get the control sequences
1024 getcmd say_color_error
eval 'tput setaf 1' # red
1025 getcmd say_color_skip
eval 'tput bold; tput setaf 5' # bold blue
1026 getcmd say_color_warn
eval 'tput setaf 3' # brown/yellow
1027 getcmd say_color_pass
eval 'tput setaf 2' # green
1028 getcmd say_color_info
eval 'tput setaf 6' # cyan
1029 getcmd say_color_reset
eval 'tput sgr0'
1030 say_color_
="" # no formatting for normal text
1042 test_external_has_tap
=0
1044 # The user-facing functions are loaded from a separate file
1045 .
"$TESTLIB_DIRECTORY/test-lib-functions-tg.sh"
1046 .
"$TESTLIB_DIRECTORY/test-lib-functions.sh"
1047 test_lib_functions_init
1048 test_lib_functions_tg_init
1051 : "${TESTLIB_SHELL_HAS_SHOPT=$(command -v shopt)}"
1055 [ -n "$TEST_HELPER_DIRECTORY" ] && [ -d "$TEST_HELPER_DIRECTORY" ] && PATH
="$TEST_HELPER_DIRECTORY:$PATH" ||
:
1056 if [ -n "$TG_TEST_INSTALLED" ]; then
1057 TG_TEST_FULL_PATH
="$(cmd_path tg)" && [ -n "$TG_TEST_FULL_PATH" ] ||
1058 fatal
'error: TG_TEST_INSTALLED set but no tg found in $PATH!'
1060 tg_bin_dir
="$(cd "$TESTLIB_DIRECTORY/..
/bin-wrappers
" 2>/dev/null && pwd -P || :)"
1061 [ -x "$tg_bin_dir/tg" ] ||
1062 fatal
'error: no ../bin-wrappers/tg executable found!'
1063 PATH
="$tg_bin_dir:$PATH"
1064 TG_TEST_FULL_PATH
="$tg_bin_dir/tg"
1066 export TG_TEST_FULL_PATH
1067 tg_version
="$(tg --version)" ||
1068 fatal
'error: tg --version failed!'
1069 case "$tg_version" in [Tt
][Oo
][Pp
][Gg
][Ii
][Tt
]\
[Vv
][Ee
][Rr
][Ss
][Ii
][Oo
][Nn
]\
[0-9]*);;*)
1070 fatal
"error: tg --version returned bogus value: $tg_version"
1073 vcmp
"$git_version" '>=' "$GIT_MINIMUM_VERSION" ||
1074 fatal
"git version >= $GIT_MINIMUM_VERSION required but found \"$git_version\" instead"
1076 if test -z "$TESTLIB_TEST_CMP"
1078 if test -n "$TESTLIB_TEST_CMP_USE_COPIED_CONTEXT"
1080 TESTLIB_TEST_CMP
="$DIFF -c"
1082 TESTLIB_TEST_CMP
="$DIFF -u"
1086 # Fix some commands on Windows
1087 case "${UNAME_S:=$(uname -s)}" in
1089 # no POSIX permissions
1090 # backslashes in pathspec are converted to '/'
1091 # exec does not inherit the PID
1092 test_set_prereq MINGW
1093 test_set_prereq NATIVE_CRLF
1094 test_set_prereq SED_STRIPS_CR
1095 test_set_prereq GREP_STRIPS_CR
1096 TESTLIB_TEST_CMP
=mingw_test_cmp
1099 test_set_prereq POSIXPERM
1100 test_set_prereq EXECKEEPSPID
1101 test_set_prereq CYGWIN
1102 test_set_prereq SED_STRIPS_CR
1103 test_set_prereq GREP_STRIPS_CR
1106 test_set_prereq POSIXPERM
1107 test_set_prereq BSLASHPSPEC
1108 test_set_prereq EXECKEEPSPID
1112 ( COLUMNS
=1 && test $COLUMNS = 1 ) && test_set_prereq COLUMNS_CAN_BE_1
1114 test_lib_main_init_funcs
1116 test_lazy_prereq PIPE
'
1117 # test whether the filesystem supports FIFOs
1118 case "${UNAME_S:=$(uname -s)}" in
1123 rm -f testfifo && mkfifo testfifo
1128 test_lazy_prereq SYMLINKS
'
1129 # test whether the filesystem supports symbolic links
1130 ln -s x y && test -h y
1133 test_lazy_prereq FILEMODE
'
1134 test "$(git config --bool core.filemode)" = true
1137 test_lazy_prereq CASE_INSENSITIVE_FS
'
1138 echo good >CamelCase &&
1139 echo bad >camelcase &&
1140 test "$(cat CamelCase)" != good
1143 test_lazy_prereq UTF8_NFD_TO_NFC
'
1144 # check whether FS converts nfd unicode to nfc
1145 auml="$(printf "\303\244")"
1146 aumlcdiar="$(printf "\141\314\210")"
1156 test_lazy_prereq AUTOIDENT
'
1157 sane_unset GIT_AUTHOR_NAME &&
1158 sane_unset GIT_AUTHOR_EMAIL &&
1159 git var GIT_AUTHOR_IDENT
1162 test_lazy_prereq EXPENSIVE
'
1163 test -n "$TESTLIB_TEST_LONG"
1166 test_lazy_prereq USR_BIN_TIME
'
1167 test -x /usr/bin/time
1170 test_lazy_prereq NOT_ROOT
'
1175 # SANITY is about "can you correctly predict what the filesystem would
1176 # do by only looking at the permission bits of the files and
1177 # directories?" A typical example of !SANITY is running the test
1178 # suite as root, where a test may expect "chmod -r file && cat file"
1179 # to fail because file is supposed to be unreadable after a successful
1180 # chmod. In an environment (i.e. combination of what filesystem is
1181 # being used and who is running the tests) that lacks SANITY, you may
1182 # be able to delete or create a file when the containing directory
1183 # doesn't have write permissions, or access a file even if the
1184 # containing directory doesn't have read or execute permissions.
1186 test_lazy_prereq SANITY
'
1187 mkdir SANETESTD.1 SANETESTD.2 &&
1189 chmod +w SANETESTD.1 SANETESTD.2 &&
1190 >SANETESTD.1/x 2>SANETESTD.2/x &&
1191 chmod -w SANETESTD.1 &&
1192 chmod -r SANETESTD.1/x &&
1193 chmod -rx SANETESTD.2 ||
1194 error "bug in test sript: cannot prepare SANETESTD"
1196 ! test -r SANETESTD.1/x &&
1197 ! rm SANETESTD.1/x && ! test -f SANETESTD.2/x
1200 chmod +rwx SANETESTD.1 SANETESTD.2 &&
1201 rm -rf SANETESTD.1 SANETESTD.2 ||
1202 error "bug in test sript: cannot clean SANETESTD"
1206 test_lazy_prereq CMDLINE_LIMIT
'run_with_limited_cmdline true'
1209 # End test_lib_main_init_generic
1213 # This function is guaranteed to always be called for every single test.
1214 # Only put things in this function that MUST be done per-test, function
1215 # definitions and sourcing other files generally DO NOT QUALIFY (there can
1217 test_lib_main_init_specific
() {
1218 # Begin test_lib_main_init_specific
1221 # original stdin is on 6, stdout on 5 and stderr on 7
1224 test_lib_main_init_funcs
1226 if test -n "$HARNESS_ACTIVE"
1228 if test "$verbose" = t ||
test -n "$verbose_only" && test -z "$verbose_log$TESTLIB_OVERRIDE"
1230 printf 'Bail out! %s\n' \
1231 'verbose mode forbidden under TAP harness; use --verbose-log'
1236 test "${test_description}" != "" ||
1237 error
"Test script did not set test_description."
1239 if test "$help" = "t"
1241 printf '%s\n' "$(printf '%s\n' "$test_description")" |
1256 if test "$verbose_log" = "t"
1258 exec 3>>"$TESTLIB_TEST_TEE_OUTPUT_FILE" 4>&3
1259 elif test "$verbose" = "t"
1263 exec 4>/dev
/null
3>/dev
/null
1266 # Send any "-x" output directly to stderr to avoid polluting tests
1267 # which capture stderr. We can do this unconditionally since it
1268 # has no effect if tracing isn't turned on.
1270 # Note that this sets up the trace fd as soon as we assign the variable, so it
1271 # must come after the creation of descriptor 4 above. Likewise, we must never
1272 # unset this, as it has the side effect of closing descriptor 4, which we
1273 # use to show verbose tests to the user.
1275 # Note also that we don't need or want to export it. The tracing is local to
1276 # this shell, and we would not want to influence any shells we exec.
1281 trap 'exit $?' HUP INT QUIT ABRT PIPE TERM
1282 trap 'TESTLIB_EXIT_OK=t; exit 1' USR1
1285 TRASH_DIRECTORY
="trash directory.${0##*/}"
1286 TRASH_DIRECTORY
="${TRASH_DIRECTORY%.sh}"
1287 test -n "$root" && TRASH_DIRECTORY
="$root/$TRASH_DIRECTORY"
1288 test -n "$root" && GIT_CEILING_DIRECTORIES
="$root:$GIT_CEILING_DIRECTORIES"
1289 case "$TRASH_DIRECTORY" in
1290 /*) ;; # absolute path is good
1291 *) TRASH_DIRECTORY
="$TEST_OUTPUT_DIRECTORY/$TRASH_DIRECTORY" ;;
1293 test ! -z "$debug" || remove_trash
=$TRASH_DIRECTORY
1294 ! test -e "$TRASH_DIRECTORY" ||
{
1295 rm -rf "$TRASH_DIRECTORY" &&
1296 ! test -e "$TRASH_DIRECTORY" ||
{
1297 chmod -R u
+w
"$TRASH_DIRECTORY" &&
1298 rm -rf "$TRASH_DIRECTORY" &&
1299 ! test -e "$TRASH_DIRECTORY"
1303 echo >&5 "FATAL: Cannot prepare test area"
1307 HOME
="$TRASH_DIRECTORY"
1308 GNUPGHOME
="$HOME/gnupg-home-not-used"
1309 export HOME GNUPGHOME
1311 if test -z "$TEST_NO_CREATE_REPO"
1313 test_create_repo
"$TRASH_DIRECTORY"
1315 mkdir
-p "$TRASH_DIRECTORY"
1317 # Use -P to resolve symlinks in our working directory so that the cwd
1318 # in subprocesses like tg equals our $PWD (for pathname comparisons).
1319 cd -P "$TRASH_DIRECTORY" ||
exit 1
1322 this_test
=${this_test%%-*}
1323 test_wrote_plan_count
=
1324 test_last_subtest_ok
=1
1325 if match_pattern_list
"$this_test" $TESTLIB_SKIP_TESTS
1327 say_color info
>&3 "skipping test $this_test altogether"
1328 skip_all
="skip all tests in $this_test"
1332 if test z
"${TESTLIB_SHELL_HAS_SHOPT=$(command -v shopt)}" = z
"shopt"
1334 shopt -s expand_aliases
>/dev
/null
2>&1 ||
:
1337 # End test_lib_main_init_specific
1342 # THIS SHOULD ALWAYS BE THE LAST FUNCTION DEFINED IN THIS FILE
1344 # Any client that sources this file should immediately execute this function
1345 # afterwards with the command line arguments
1347 # THERE SHOULD NOT BE ANY DIRECTLY EXECUTED LINES OF CODE IN THIS FILE
1349 test_lib_main_init
() {
1351 test_lib_main_init_generic
"$@"
1352 test_lib_main_init_specific
"$@"