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
54 # usage: cmdget <varname> <cmd> [<arg>...]
55 # return code is that of <cmd> [<arg...]
56 # <varname> is set to VERBATIM <cmd> output (except NULs may not be handled)
58 [ -n "$1" ] ||
return 1
59 eval "$1=" >/dev
/null
2>&1 ||
return 1
60 [ -n "$2" ] ||
return 1
64 _getcmd_result
="$(ec=0; ("$@
") || ec=$?; echo Z; exit $ec)" || _getcmd_ec
=$?
65 eval "$_getcmd_vn=\"\${_getcmd_result%Z}\""
69 # usage: whats_the_dir [-P | -L] [--] path-to-something varname
70 # determine path-to-something's directory and store it into varname
71 # without "-P" or "-L" a relative dirname may be returned
73 # determine "$1"'s directory and store it into the var name passed as "$2"
74 if [ "z$1" = "z-P" -o "z$1" = "z-L" ]; then
75 if [ "z$2" = "z--" ]; then
80 elif [ "z$1" = "z--" ]; then
83 case "$1" in *"/"*);;*) set -- "./$1" "$2" "$3"; esac
85 set -- "$(readlink "$1")" "$2" "$3" "$1"
86 case "$1" in "/"*);;*)
87 set -- "${4%/*}/$1" "$2" "$3"
90 set -- "${1%/*}" "$2" "$3"
91 if [ "z$3" != "z" ] && [ -d "$1" ] &&
92 ! case "$1" in [!/]*|
*"/./"*|
*"/."|
*"/../"*|
*"/..") ! :; esac; then
93 [ "z$3" = "z-P" ] ||
set -- "$1" "$2"
94 if [ "z$3" = "z" -a \
( "z$1" = "z." -o "z$1" = "z$PWD" \
) ]; then
97 set -- "$(cd "$1" && pwd $3)" "$2"
104 # Compare $1 to $3 each of which must match ^[^0-9]*\d*(\.\d*)*.*$
105 # where only the "\d*" parts in the regex participate in the comparison
106 # Since EVERY string matches that regex this function is easy to use
107 # An empty string ('') for $1 or $3 or any "\d*" part is treated as 0
108 # $2 is a compare op '<', '<=', '=', '==', '!=', '>=', '>'
109 # Return code is 0 for true, 1 for false (or unknown compare op)
110 # There is NO difference in behavior between '=' and '=='
111 # Note that "vcmp 1.8 == 1.8.0.0.0.0" correctly returns 0
112 set -- "$1" "$2" "$3" "${1%%[0-9]*}" "${3%%[0-9]*}"
113 set -- "${1#"$4"}" "$2" "${3#"$5"}"
114 set -- "${1%%[!0-9.]*}" "$2" "${3%%[!0-9.]*}"
118 [ "z$vcmp_a_" != "z" -o "z$vcmp_b_" != "z" ]
120 if [ "${vcmp_a_:-0}" -lt "${vcmp_b_:-0}" ]; then
121 unset vcmp_a_ vcmp_b_
122 case "$2" in "<"|
"<="|
"!=") return 0; esac
124 elif [ "${vcmp_a_:-0}" -gt "${vcmp_b_:-0}" ]; then
125 unset vcmp_a_ vcmp_b_
126 case "$2" in ">"|
">="|
"!=") return 0; esac
129 vcmp_a_
="${1#$vcmp_a_}"
130 vcmp_b_
="${3#$vcmp_b_}"
131 set -- "${vcmp_a_#.}" "$2" "${vcmp_b_#.}"
133 unset vcmp_a_ vcmp_b_
134 case "$2" in "="|
"=="|
"<="|
">=") return 0; esac
141 say_color error
"${LF}error: $*" >&7
142 printf '%s\n' "Bail out! ${0##*/}:${callerlno:+$callerlno:} error: $*" >&5
144 [ -z "$TESTLIB_TEST_PARENT_INT_ON_ERROR" ] ||
kill -INT $PPID ||
:
154 say_color_tap info
"$@"
159 if test -n "$TESTLIB_EXIT_OK"
163 echo >&5 "FATAL: Unexpected exit with code $code"
168 # You are not expected to call test_ok_ and test_failure_ directly, use
169 # the test_expect_* functions instead.
172 test_success
=$
(($test_success + 1))
173 say_color_tap
"" "ok $test_count - $@"
177 test_failure
=$
(($test_failure + 1))
180 say_color_tap error
"not ok $test_count - $1"
182 printf '%s\n' "$(printf '%s\n' "failed
: ${0##*/}${tlno:+:$tlno}$LF$
*")" |
203 test "$immediate" = "" ||
{ TESTLIB_EXIT_OK
=t
; exit 1; }
206 test_known_broken_ok_
() {
207 test_fixed
=$
(($test_fixed + 1))
208 say_color_tap warn
"ok $test_count - $@ # TODO known breakage vanished"
211 test_known_broken_failure_
() {
212 test_broken
=$
(($test_broken + 1))
213 say_color_tap warn
"not ok $test_count - $@ # TODO known breakage"
216 test_possibly_broken_ok_
() {
217 test_success
=$
(($test_success + 1))
218 say_color_tap
"" "ok $test_count - $@"
221 test_possibly_broken_failure_
() {
222 test_broken
=$
(($test_broken + 1))
223 say_color_tap warn
"not ok $test_count - $@ # TODO tolerated breakage"
227 test "$debug" = "" ||
test $# -eq 0 ||
test -z "$*" ||
{ "$@"; } >&7 2>&1
230 match_pattern_list
() {
233 test -z "$*" && return 1
244 match_test_selector_list
() {
249 test -z "$1" && return 0
251 # Both commas and whitespace are accepted as separators.
257 # If the first selector is negative we include by default.
265 orig_selector
=$selector
271 selector
=${selector##?}
275 test -z "$selector" && continue
279 if x_
="${selector%%-*}" && test "z$x_" != "z${x_#*[!0-9]}"
281 echo "error: $title: invalid non-numeric in range" \
282 "start: '$orig_selector'" >&2
285 if x_
="${selector#*-}" && test "z$x_" != "z${x_#*[!0-9]}"
287 echo "error: $title: invalid non-numeric in range" \
288 "end: '$orig_selector'" >&2
294 if test "z$selector" != "z${selector#*[!0-9]}"
296 echo "error: $title: invalid non-numeric in test" \
297 "selector: '$orig_selector'" >&2
302 # Short cut for "obvious" cases
303 test -z "$include" && test -z "$positive" && continue
304 test -n "$include" && test -n "$positive" && continue
308 if test $arg -le ${selector#-}
314 if test $arg -ge ${selector%-}
320 if test ${selector%%-*} -le $arg \
321 && test $arg -le ${selector#*-}
327 if test $arg -eq $selector
338 maybe_teardown_verbose
() {
339 test -z "$verbose_only" && return
340 exec 4>/dev
/null
3>/dev
/null
344 maybe_setup_verbose
() {
345 test -z "$verbose_only" && return
346 if match_pattern_list
$test_count $verbose_only
348 if test "$verbose_log" = "t"
350 exec 3>>"$TESTLIB_TEST_TEE_OUTPUT_FILE" 4>&3
354 # Emit a delimiting blank line when going from
355 # non-verbose to verbose. Within verbose mode the
356 # delimiter is printed by test_expect_*. The choice
357 # of the initial $last_verbose is such that before
358 # test 1, we do not print it.
359 test -z "$last_verbose" && echo >&3 ""
362 exec 4>/dev
/null
3>/dev
/null
365 last_verbose
=$verbose
369 test "$trace" = t
&& test "$verbose" = t
372 # This is a separate function because some tests use
373 # "return" to end a test_expect_success block early
374 # (and we want to make sure we run any cleanup like
377 # Do not add anything extra (including LF) after '$*'
380 test_subshell_active_=t
381 ! want_trace || ! set -x && ! :
385 # Same thing as test_eval_inner_ but without the subshell
386 test_eval_inner_no_subshell_
() {
387 # Do not add anything extra (including LF) after '$*'
389 ! want_trace || ! set -x && ! :
394 # We run this block with stderr redirected to avoid extra cruft
395 # during a "-x" trace. Once in "set -x" mode, we cannot prevent
396 # the shell from printing the "set +x" to turn it off (nor the saving
397 # of $? before that). But we can make sure that the output goes to
400 # The test itself is run with stderr put back to &4 (so either to
401 # /dev/null, or to the original stderr if --verbose was used).
405 if test "${test_eval_ss_:-0}" = "0"
407 test_eval_inner_no_subshell_
"$@" </dev
/null
>&3 2>&4
409 test_eval_inner_
"$@" </dev
/null
>&3 2>&4
415 if test "$test_eval_ret_" != 0
417 say_color error
>&4 "error: last command exited with \$?=$test_eval_ret_"
421 return $test_eval_ret_
424 # Calls the real test_eval_ss_ with !"$TESTLIB_TEST_NO_SUBSHELL" as first arg
426 if test -n "$TESTLIB_TEST_NO_SUBSHELL"
428 test_eval_ss_
"0" "$@"
430 test_eval_ss_
"1" "$@"
434 # If "$1" = "-" read the script from stdin but ONLY if stdin is NOT a tty
435 # Store the test script in test_script_
439 ! test -t 0 || error
"test script is '-' but STDIN is a tty"
440 test_script_
="$(cat)"
441 test -n "$test_script_" || error
"test script is '-' but STDIN is empty"
442 test_script_
="$LF$test_script_$LF"
454 test_subshell_active_
=
458 if test "${TESTLIB_TEST_CHAIN_LINT:-1}" != 0; then
459 # turn off tracing for this test-eval, as it simply creates
460 # confusing noise in the "-x" output
464 # 117 is magic because it is unlikely to match the exit
465 # code of other programs
466 test_eval_ss_
"1" "fail_ 117 && $1${LF}fail_ \$?"
467 if test "$?" != 117; then
468 error
"bug in the test script: broken &&-chain: $1"
477 if test -z "$immediate" ||
test $eval_ret = 0 ||
478 test -n "$expecting_failure" && test "${test_cleanup:-:}" != ":"
480 test_eval_
"$test_cleanup"
482 if test "$verbose" = "t" && test -n "$HARNESS_ACTIVE"
490 test_count
=$
(($test_count+1))
496 maybe_teardown_verbose
502 if match_pattern_list
$this_test.
$test_count $TESTLIB_SKIP_TESTS
505 skipped_reason
="TESTLIB_SKIP_TESTS"
507 if test -z "$to_skip" && test -n "$test_prereq" &&
508 ! test_have_prereq
"$test_prereq"
513 if test "$missing_prereq" != "$test_prereq"
515 of_prereq
=" of $test_prereq"
517 skipped_reason
="missing $missing_prereq${of_prereq}"
519 if test -z "$to_skip" && test -n "$run_list" &&
520 ! match_test_selector_list
'--run' $test_count "$run_list"
523 skipped_reason
="--run"
528 say_color skip
>&3 "skipping test: $@"
529 say_color_tap skip
"ok $test_count # skip $1 ($skipped_reason)"
538 # stub; runs at end of each successful test
539 test_at_end_hook_
() {
546 if test -z "$HARNESS_ACTIVE"
548 test_results_dir
="$TEST_OUTPUT_DIRECTORY/test-results"
549 mkdir
-p "$test_results_dir"
551 test_results_path
="$test_results_dir/${base%.sh}.counts"
553 cat >"$test_results_path" <<-EOF
555 success $test_success
563 if test "$test_fixed" != 0
565 say_color error
"# $test_fixed known breakage(s) vanished; please update test(s)"
567 if test "$test_broken" != 0
569 say_color warn
"# still have $test_broken known breakage(s)"
571 if test "$test_broken" != 0 ||
test "$test_fixed" != 0
573 test_remaining
=$
(( $test_count - $test_broken - $test_fixed ))
574 msg
="remaining $test_remaining test(s)"
576 test_remaining
=$test_count
577 msg
="$test_count test(s)"
579 case "$test_failure" in
581 # Maybe print SKIP message
582 if test -n "$skip_all" && test $test_count -gt 0
584 error
"Can't use skip_all after running some tests"
586 test -z "$skip_all" || skip_all
=" # SKIP $skip_all"
588 if test $test_external_has_tap -eq 0
590 if test $test_remaining -gt 0
592 say_color pass
"# passed all $msg"
594 test -n "$test_wrote_plan_count" || say_tap
"1..$test_count$skip_all"
596 if test -n "$test_wrote_plan_count" && test "$test_wrote_plan_count" -ne "$test_count"
598 say_color error
"# plan count of $test_wrote_plan_count does not match run count of $test_count"
602 test -n "$remove_trash" &&
603 test -d "$remove_trash" &&
604 cd "${remove_trash%/*}" &&
605 test_done_td_
="${remove_trash##*/}" &&
606 test -e "$test_done_td_" &&
607 rm -rf "$test_done_td_" &&
609 ! test -e "$test_done_td_" ||
{
610 chmod -R u
+w
"$test_done_td_" &&
611 rm -rf "$test_done_td_"
620 if test $test_external_has_tap -eq 0
622 say_color error
"# failed $test_failure among $msg"
623 test -n "$test_wrote_plan_count" || say_tap
"1..$test_count"
625 if test -n "$test_wrote_plan_count" && test "$test_wrote_plan_count" -ne "$test_count"
627 say_color error
"# plan count of $test_wrote_plan_count does not match run count of $test_count"
636 test -n "$1" && test "z$1" = "z${1#*[!0-9]}" || fatal
"invalid test_plan argument: $1"
637 test "$1" -eq 0 ||
test -z "$2" || fatal
"invalid test_plan arguments: $*"
638 if test "$1" -eq 0; then
639 skip_all
="${2:-skip all tests in $this_test}"
642 test $test_external_has_tap -ne 0 || say_tap
"1..$1"
643 test_wrote_plan_count
="$1"
646 # Provide an implementation of the 'yes' utility
663 run_with_limited_cmdline
() {
664 (ulimit -s 128 && "$@")
669 ## Note that the following functions have bodies that are NOT indented
670 ## to assist with readability
674 test_lib_main_init_tee
() {
675 # Begin test_lib_main_init_tee
678 # if --tee was passed, write the output not only to the terminal, but
679 # additionally to the file test-results/$BASENAME.out, too.
680 case "$TESTLIB_TEST_TEE_STARTED, $* " in
682 # do not redirect again
684 *' --tee '*|
*' --verbose-log '*)
685 mkdir
-p "$TEST_OUTPUT_DIRECTORY/test-results"
686 BASE
="$TEST_OUTPUT_DIRECTORY/test-results/${0##*/}"
689 # Make this filename available to the sub-process in case it is using
691 TESTLIB_TEST_TEE_OUTPUT_FILE
=$BASE.out
692 export TESTLIB_TEST_TEE_OUTPUT_FILE
694 # Truncate before calling "tee -a" to get rid of the results
695 # from any previous runs.
696 >"$TESTLIB_TEST_TEE_OUTPUT_FILE"
699 (ec
=0; TESTLIB_TEST_TEE_STARTED
=done ${SHELL_PATH} "$0" "$@" 2>&1 || ec
=$?
700 echo $ec >"$BASE.exit") |
tee -a "$TESTLIB_TEST_TEE_OUTPUT_FILE"
701 exitcode
="$(cat "$BASE.
exit" 2>/dev/null)" ||
:
707 # End test_lib_main_init_tee
711 test_lib_main_init_funcs
() {
712 # Begin test_lib_main_init_funcs
715 [ -z "$test_lib_main_init_funcs_done" ] ||
return 0
720 test -z "$1" && test -n "$quiet" && return
721 eval "say_color_color=\$say_color_$1"
725 if test -n "$HARNESS_ACTIVE"
727 case "$_sms" in '#'*)
732 printf '%s\n' "$_sfc$say_color_color$_sms$say_color_reset"
736 test -z "$1" && test -n "$quiet" && return
742 # Just like say_color except if HARNESS_ACTIVE it's ALWAYS output and WITHOUT color
744 if test -n "$HARNESS_ACTIVE"
754 # Fix some commands on Windows
755 case "${UNAME_S:=$(uname -s)}" in
757 # Windows has its own (incompatible) sort and find
767 # git sees Windows-style pwd
774 test_lib_main_init_funcs_done
=1
777 # End test_lib_main_init_funcs
781 # This function is called with all the test args and must perform all
782 # initialization that involves variables and is not specific to "$0"
783 # or "$test_description" in any way. This function may only be called
784 # once per run of the entire test suite.
785 test_lib_main_init_generic
() {
786 # Begin test_lib_main_init_generic
788 [ -n "$TESTLIB_DIRECTORY" ] || whats_the_dir
-L -- "${TEST_DIRECTORY:-.}/test-lib.sh" TESTLIB_DIRECTORY
789 [ -f "$TESTLIB_DIRECTORY/test-lib.sh" ] && [ -f "$TESTLIB_DIRECTORY/test-lib-main.sh" ] &&
790 [ -f "$TESTLIB_DIRECTORY/test-lib-functions.sh" ] ||
791 fatal
"error: invalid TESTLIB_DIRECOTRY: $TESTLIB_DIRECTORY"
792 export TESTLIB_DIRECTORY
794 ! [ -f "$TESTLIB_DIRECTORY/../TG-BUILD-SETTINGS" ] || .
"$TESTLIB_DIRECTORY/../TG-BUILD-SETTINGS"
795 ! [ -f "$TESTLIB_DIRECTORY/TG-TEST-SETTINGS" ] || .
"$TESTLIB_DIRECTORY/TG-TEST-SETTINGS"
797 : "${SHELL_PATH:=/bin/sh}"
799 : "${GIT_PATH:=$(cmd_path git)}"
800 : "${PERL_PATH:=$(cmd_path perl || :)}"
802 # Test the binaries we have just built. The tests are kept in
803 # t/ subdirectory and are run in 'trash directory' subdirectory.
804 if test -z "$TEST_DIRECTORY"
806 # We allow tests to override this, in case they want to run tests
807 # outside of t/, e.g. for running tests on the test library
809 TEST_DIRECTORY
="$TESTLIB_DIRECTORY"
811 # ensure that TEST_DIRECTORY is an absolute path so that it
812 # is valid even if the current working directory is changed
813 TEST_DIRECTORY
="$(cd "$TEST_DIRECTORY" && pwd)" ||
exit 1
815 if test -z "$TEST_OUTPUT_DIRECTORY"
817 # Similarly, override this to store the test-results subdir
819 TEST_OUTPUT_DIRECTORY
="$TEST_DIRECTORY"
821 [ -d "$TESTLIB_DIRECTORY"/empty
] ||
{
822 mkdir
"$TESTLIB_DIRECTORY/empty" ||
:
823 chmod a-w
"$TESTLIB_DIRECTORY/empty" ||
:
824 test -d "$TESTLIB_DIRECTORY"/empty ||
825 fatal
"error: could not make empty directory: '$TESTLIB_DIRECTORY/empty'"
827 EMPTY_DIRECTORY
="$TESTLIB_DIRECTORY/empty"
828 export TEST_DIRECTORY TEST_OUTPUT_DIRECTORY EMPTY_DIRECTORY
829 GIT_CEILING_DIRECTORIES
="$TESTLIB_DIRECTORY"
830 [ "$TESTLIB_DIRECTORY" = "$TEST_DIRECTORY" ] ||
831 GIT_CEILING_DIRECTORIES
="$TEST_DIRECTORY:$GIT_CEILING_DIRECTORIES"
832 [ "$TESTLIB_DIRECTORY" = "$TEST_OUTPUT_DIRECTORY" ] ||
833 GIT_CEILING_DIRECTORIES
="$TEST_OUTPUT_DIRECTORY:$GIT_CEILING_DIRECTORIES"
834 export GIT_CEILING_DIRECTORIES
836 ################################################################
837 # It appears that people try to run tests with missing perl or git...
838 git_version
="$("$GIT_PATH" --version 2>&1)" ||
839 fatal
'error: you do not seem to have git available?'
840 case "$git_version" in [Gg
][Ii
][Tt
]\
[Vv
][Ee
][Rr
][Ss
][Ii
][Oo
][Nn
]\
[0-9]*);;*)
841 fatal
"error: git --version returned bogus value: $git_version"
843 #"$PERL_PATH" --version >/dev/null 2>&1 ||
844 # fatal 'error: you do not seem to have perl available?'
846 test_lib_main_init_tee
"$@"
848 # For repeatability, reset the environment to known value.
849 # TERM is sanitized below, after saving color control sequences.
854 export LANG LC_ALL PAGER TZ
856 # A call to "unset" with no arguments causes at least Solaris 10
857 # /usr/xpg4/bin/sh and /bin/ksh to bail out. So keep the unsets
858 # deriving from the command substitution clustered with the other
860 unset VISUAL EMAIL LANGUAGE COLUMNS $
("$PERL_PATH" -e '
862 my $ok = join("|", qw(
877 my @vars = grep(/^GIT_/ && !/^GIT_($ok)/o, @env);
878 print join("\n", @vars);
880 unset XDG_CONFIG_HOME
882 GIT_AUTHOR_NAME
='Te s t'
883 GIT_AUTHOR_EMAIL
=test@example.net
884 GIT_COMMITTER_NAME
='Fra mewor k'
885 GIT_COMMITTER_EMAIL
=framework@example.org
886 GIT_MERGE_VERBOSITY
=5
887 GIT_MERGE_AUTOEDIT
=no
888 GIT_TEMPLATE_DIR
="$EMPTY_DIRECTORY"
889 GIT_CONFIG_NOSYSTEM
=1
891 export PATH GIT_TEMPLATE_DIR GIT_CONFIG_NOSYSTEM GIT_ATTR_NOSYSTEM
892 export GIT_MERGE_VERBOSITY GIT_MERGE_AUTOEDIT
893 export GIT_AUTHOR_EMAIL GIT_AUTHOR_NAME
894 export GIT_COMMITTER_EMAIL GIT_COMMITTER_NAME
897 # Tests using GIT_TRACE typically don't want <timestamp> <file>:<line> output
899 export GIT_TRACE_BARE
901 # Protect ourselves from common misconfiguration to export
902 # CDPATH into the environment
908 case "$GIT_TRACE" in 1|
2|
[Tt
][Rr
][Uu
][Ee
])
915 # A regexp to match 5 and 40 hexdigits
916 _x05
='[0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f]'
917 _x40
="$_x05$_x05$_x05$_x05$_x05$_x05$_x05$_x05"
920 _z40
=0000000000000000000000000000000000000000
922 EMPTY_TREE
=4b825dc642cb6eb9a060e54bf8d69288fbee4904
923 EMPTY_BLOB
=e69de29bb2d1d6434b8b29ae775ad8c2e48c5391
929 # UTF-8 ZERO WIDTH NON-JOINER, which HFS+ ignores
930 # when case-folding filenames
931 u200c
="$(printf '\342\200\214')"
933 export _x05 _x40 _z40 LF u200c EMPTY_TREE EMPTY_BLOB
935 while test "$#" -ne 0
938 -d|
--d|
--de|
--deb|
--debu|
--debug)
940 -i|
--i|
--im|
--imm|
--imme|
--immed|
--immedi|
--immedia|
--immediat|
--immediate)
941 immediate
=t
; shift ;;
942 -l|
--l|
--lo|
--lon|
--long|
--long-|
--long-t|
--long-te|
--long-tes|
--long-test|
--long-tests|\
943 --ex|
--exp|
--expe|
--expen|
--expens|
--expensi|
--expensiv|
--expensive)
944 TESTLIB_TEST_LONG
=t
; export TESTLIB_TEST_LONG
; shift ;;
946 shift; test "$#" -ne 0 ||
{
947 echo 'error: -r requires an argument' >&2;
950 run_list
=$1; shift ;;
952 run_list
=${1#--*=}; shift ;;
953 -h|
--h|
--he|
--hel|
--help)
955 -v|
--v|
--ve|
--ver|
--verb|
--verbo|
--verbos|
--verbose)
958 verbose_only
=${1#--*=}
960 -q|
--q|
--qu|
--qui|
--quie|
--quiet)
967 shift ;; # was handled already
972 TESTLIB_TEST_CHAIN_LINT
=1
975 TESTLIB_TEST_CHAIN_LINT
=0
977 -x|
--x|
--xt|
--xtr|
--xtra|
--xtrac|
--xtrace)
985 echo "error: unknown test option '$1'" >&2; exit 1 ;;
989 test "x${color+set}" != "xset" &&
990 test "x$TERM" != "xdumb" && (
991 { test -n "$TESTLIB_FORCETTY" ||
test -t 1; } &&
992 tput bold
>/dev
/null
2>&1 &&
993 tput setaf
1 >/dev
/null
2>&1 &&
994 tput sgr0
>/dev
/null
2>&1
999 # Save the color control sequences now rather than run tput
1000 # each time say_color() is called. This is done for two
1002 # * TERM will be changed to dumb
1003 # * HOME will be changed to a temporary directory and tput
1004 # might need to read ~/.terminfo from the original HOME
1005 # directory to get the control sequences
1006 getcmd say_color_error
eval 'tput setaf 1' # red
1007 getcmd say_color_skip
eval 'tput bold; tput setaf 5' # bold blue
1008 getcmd say_color_warn
eval 'tput setaf 3' # brown/yellow
1009 getcmd say_color_pass
eval 'tput setaf 2' # green
1010 getcmd say_color_info
eval 'tput setaf 6' # cyan
1011 getcmd say_color_reset
eval 'tput sgr0'
1012 say_color_
="" # no formatting for normal text
1018 # Send any "-x" output directly to stderr to avoid polluting tests
1019 # which capture stderr. We can do this unconditionally since it
1020 # has no effect if tracing isn't turned on.
1022 # Note that this sets up the trace fd as soon as we assign the variable, so it
1023 # must come after the creation of descriptor 4 above. Likewise, we must never
1024 # unset this, as it has the side effect of closing descriptor 4, which we
1025 # use to show verbose tests to the user.
1027 # Note also that we don't need or want to export it. The tracing is local to
1028 # this shell, and we would not want to influence any shells we exec.
1037 test_external_has_tap
=0
1039 # The user-facing functions are loaded from a separate file
1040 .
"$TESTLIB_DIRECTORY/test-lib-functions.sh"
1041 test_lib_functions_init
1045 if [ -n "$TG_TEST_INSTALLED" ]; then
1046 [ -n "$(cmd_path tg || :)" ] ||
1047 fatal
'error: TG_TEST_INSTALLED set but no tg found in $PATH!'
1049 tg_bin_dir
="$(cd "$TESTLIB_DIRECTORY/..
/bin-wrappers
" 2>/dev/null && pwd -P || :)"
1050 [ -x "$tg_bin_dir/tg" ] ||
1051 fatal
'error: no ../bin-wrappers/tg executable found!'
1052 PATH
="$tg_bin_dir:$PATH"
1054 tg_version
="$(tg --version)" ||
1055 fatal
'error: tg --version failed!'
1056 case "$tg_version" in [Tt
][Oo
][Pp
][Gg
][Ii
][Tt
]\
[Vv
][Ee
][Rr
][Ss
][Ii
][Oo
][Nn
]\
[0-9]*);;*)
1057 fatal
"error: tg --version returned bogus value: $tg_version"
1060 vcmp
"$git_version" '>=' "$GIT_MINIMUM_VERSION" ||
1061 fatal
"git version >= $GIT_MINIMUM_VERSION required but found \"$git_version\" instead"
1063 if test -z "$TESTLIB_TEST_CMP"
1065 if test -n "$TESTLIB_TEST_CMP_USE_COPIED_CONTEXT"
1067 TESTLIB_TEST_CMP
="$DIFF -c"
1069 TESTLIB_TEST_CMP
="$DIFF -u"
1073 # Fix some commands on Windows
1074 case "${UNAME_S:=$(uname -s)}" in
1076 # no POSIX permissions
1077 # backslashes in pathspec are converted to '/'
1078 # exec does not inherit the PID
1079 test_set_prereq MINGW
1080 test_set_prereq NATIVE_CRLF
1081 test_set_prereq SED_STRIPS_CR
1082 test_set_prereq GREP_STRIPS_CR
1083 TESTLIB_TEST_CMP
=mingw_test_cmp
1086 test_set_prereq POSIXPERM
1087 test_set_prereq EXECKEEPSPID
1088 test_set_prereq CYGWIN
1089 test_set_prereq SED_STRIPS_CR
1090 test_set_prereq GREP_STRIPS_CR
1093 test_set_prereq POSIXPERM
1094 test_set_prereq BSLASHPSPEC
1095 test_set_prereq EXECKEEPSPID
1099 ( COLUMNS
=1 && test $COLUMNS = 1 ) && test_set_prereq COLUMNS_CAN_BE_1
1101 test_lib_main_init_funcs
1103 test_lazy_prereq PIPE
'
1104 # test whether the filesystem supports FIFOs
1105 case "${UNAME_S:=$(uname -s)}" in
1110 rm -f testfifo && mkfifo testfifo
1115 test_lazy_prereq SYMLINKS
'
1116 # test whether the filesystem supports symbolic links
1117 ln -s x y && test -h y
1120 test_lazy_prereq FILEMODE
'
1121 test "$(git config --bool core.filemode)" = true
1124 test_lazy_prereq CASE_INSENSITIVE_FS
'
1125 echo good >CamelCase &&
1126 echo bad >camelcase &&
1127 test "$(cat CamelCase)" != good
1130 test_lazy_prereq UTF8_NFD_TO_NFC
'
1131 # check whether FS converts nfd unicode to nfc
1132 auml="$(printf "\303\244")"
1133 aumlcdiar="$(printf "\141\314\210")"
1143 test_lazy_prereq AUTOIDENT
'
1144 sane_unset GIT_AUTHOR_NAME &&
1145 sane_unset GIT_AUTHOR_EMAIL &&
1146 git var GIT_AUTHOR_IDENT
1149 test_lazy_prereq EXPENSIVE
'
1150 test -n "$TESTLIB_TEST_LONG"
1153 test_lazy_prereq USR_BIN_TIME
'
1154 test -x /usr/bin/time
1157 test_lazy_prereq NOT_ROOT
'
1162 # SANITY is about "can you correctly predict what the filesystem would
1163 # do by only looking at the permission bits of the files and
1164 # directories?" A typical example of !SANITY is running the test
1165 # suite as root, where a test may expect "chmod -r file && cat file"
1166 # to fail because file is supposed to be unreadable after a successful
1167 # chmod. In an environment (i.e. combination of what filesystem is
1168 # being used and who is running the tests) that lacks SANITY, you may
1169 # be able to delete or create a file when the containing directory
1170 # doesn't have write permissions, or access a file even if the
1171 # containing directory doesn't have read or execute permissions.
1173 test_lazy_prereq SANITY
'
1174 mkdir SANETESTD.1 SANETESTD.2 &&
1176 chmod +w SANETESTD.1 SANETESTD.2 &&
1177 >SANETESTD.1/x 2>SANETESTD.2/x &&
1178 chmod -w SANETESTD.1 &&
1179 chmod -r SANETESTD.1/x &&
1180 chmod -rx SANETESTD.2 ||
1181 error "bug in test sript: cannot prepare SANETESTD"
1183 ! test -r SANETESTD.1/x &&
1184 ! rm SANETESTD.1/x && ! test -f SANETESTD.2/x
1187 chmod +rwx SANETESTD.1 SANETESTD.2 &&
1188 rm -rf SANETESTD.1 SANETESTD.2 ||
1189 error "bug in test sript: cannot clean SANETESTD"
1193 test_lazy_prereq CMDLINE_LIMIT
'run_with_limited_cmdline true'
1196 # End test_lib_main_init_generic
1200 # This function is guaranteed to always be called for every single test.
1201 # Only put things in this function that MUST be done per-test, function
1202 # definitions and sourcing other files generally DO NOT QUALIFY (there can
1204 test_lib_main_init_specific
() {
1205 # Begin test_lib_main_init_specific
1208 # original stdin is on 6, stdout on 5 and stderr on 7
1211 test_lib_main_init_funcs
1213 if test -n "$HARNESS_ACTIVE"
1215 if test "$verbose" = t ||
test -n "$verbose_only" && test -z "$verbose_log$TESTLIB_OVERRIDE"
1217 printf 'Bail out! %s\n' \
1218 'verbose mode forbidden under TAP harness; use --verbose-log'
1223 test "${test_description}" != "" ||
1224 error
"Test script did not set test_description."
1226 if test "$help" = "t"
1228 printf '%s\n' "$(printf '%s\n' "$test_description")" |
1243 if test "$verbose_log" = "t"
1245 exec 3>>"$TESTLIB_TEST_TEE_OUTPUT_FILE" 4>&3
1246 elif test "$verbose" = "t"
1250 exec 4>/dev
/null
3>/dev
/null
1255 trap 'exit $?' HUP INT QUIT ABRT PIPE TERM
1256 trap 'TESTLIB_EXIT_OK=t; exit 1' USR1
1259 TRASH_DIRECTORY
="trash directory.${0##*/}"
1260 TRASH_DIRECTORY
="${TRASH_DIRECTORY%.sh}"
1261 test -n "$root" && TRASH_DIRECTORY
="$root/$TRASH_DIRECTORY"
1262 test -n "$root" && GIT_CEILING_DIRECTORIES
="$root:$GIT_CEILING_DIRECTORIES"
1263 case "$TRASH_DIRECTORY" in
1264 /*) ;; # absolute path is good
1265 *) TRASH_DIRECTORY
="$TEST_OUTPUT_DIRECTORY/$TRASH_DIRECTORY" ;;
1267 test ! -z "$debug" || remove_trash
=$TRASH_DIRECTORY
1268 ! test -e "$TRASH_DIRECTORY" ||
{
1269 rm -rf "$TRASH_DIRECTORY" &&
1270 ! test -e "$TRASH_DIRECTORY" ||
{
1271 chmod -R u
+w
"$TRASH_DIRECTORY" &&
1272 rm -rf "$TRASH_DIRECTORY" &&
1273 ! test -e "$TRASH_DIRECTORY"
1277 echo >&5 "FATAL: Cannot prepare test area"
1281 HOME
="$TRASH_DIRECTORY"
1282 GNUPGHOME
="$HOME/gnupg-home-not-used"
1283 export HOME GNUPGHOME
1285 if test -z "$TEST_NO_CREATE_REPO"
1287 test_create_repo
"$TRASH_DIRECTORY"
1289 mkdir
-p "$TRASH_DIRECTORY"
1291 # Use -P to resolve symlinks in our working directory so that the cwd
1292 # in subprocesses like tg equals our $PWD (for pathname comparisons).
1293 cd -P "$TRASH_DIRECTORY" ||
exit 1
1296 this_test
=${this_test%%-*}
1297 test_wrote_plan_count
=
1298 test_last_subtest_ok
=1
1299 if match_pattern_list
"$this_test" $TESTLIB_SKIP_TESTS
1301 say_color info
>&3 "skipping test $this_test altogether"
1302 skip_all
="skip all tests in $this_test"
1307 # End test_lib_main_init_specific
1312 # THIS SHOULD ALWAYS BE THE LAST FUNCTION DEFINED IN THIS FILE
1314 # Any client that sources this file should immediately execute this function
1315 # afterwards with the command line arguments
1317 # THERE SHOULD NOT BE ANY DIRECTLY EXECUTED LINES OF CODE IN THIS FILE
1319 test_lib_main_init
() {
1321 test_lib_main_init_generic
"$@"
1322 test_lib_main_init_specific
"$@"