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
142 say_color error
"${LF}error: $*" >&7
143 printf '%s\n' "Bail out! ${0##*/}:${callerlno:+$callerlno:} error: $*" >&5
145 [ -z "$TESTLIB_TEST_PARENT_INT_ON_ERROR" ] ||
kill -INT $PPID ||
:
155 say_color_tap info
"$@"
160 if test -n "$TESTLIB_EXIT_OK"
164 echo >&5 "FATAL: Unexpected exit with code $code"
170 # You are not expected to call test_ok_ and test_failure_ directly, use
171 # the test_expect_* functions instead.
174 test_success
=$
(($test_success + 1))
175 say_color_tap
"" "ok $test_count - $@"
179 test_failure
=$
(($test_failure + 1))
182 say_color_tap error
"not ok $test_count - $1"
184 printf '%s\n' "$(printf '%s\n' "failed
: ${0##*/}${tlno:+:$tlno}$LF$
*")" |
205 test "$immediate" = "" ||
{ TESTLIB_EXIT_OK
=t
; exit 1; }
208 test_known_broken_ok_
() {
209 test_fixed
=$
(($test_fixed + 1))
210 say_color_tap warn
"ok $test_count - $@ # TODO known breakage vanished"
213 test_known_broken_failure_
() {
214 test_broken
=$
(($test_broken + 1))
215 say_color_tap warn
"not ok $test_count - $@ # TODO known breakage"
218 test_possibly_broken_ok_
() {
219 test_success
=$
(($test_success + 1))
220 say_color_tap
"" "ok $test_count - $@"
223 test_possibly_broken_failure_
() {
224 test_broken
=$
(($test_broken + 1))
225 say_color_tap warn
"not ok $test_count - $@ # TODO tolerated breakage"
229 test "$debug" = "" ||
test $# -eq 0 ||
test -z "$*" ||
{ "$@"; } >&7 2>&1
232 match_pattern_list
() {
235 test -z "$*" && return 1
246 match_test_selector_list
() {
251 test -z "$1" && return 0
253 # Both commas and whitespace are accepted as separators.
259 # If the first selector is negative we include by default.
267 orig_selector
=$selector
273 selector
=${selector##?}
277 test -z "$selector" && continue
281 if x_
="${selector%%-*}" && test "z$x_" != "z${x_#*[!0-9]}"
283 echo "error: $title: invalid non-numeric in range" \
284 "start: '$orig_selector'" >&2
287 if x_
="${selector#*-}" && test "z$x_" != "z${x_#*[!0-9]}"
289 echo "error: $title: invalid non-numeric in range" \
290 "end: '$orig_selector'" >&2
296 if test "z$selector" != "z${selector#*[!0-9]}"
298 echo "error: $title: invalid non-numeric in test" \
299 "selector: '$orig_selector'" >&2
304 # Short cut for "obvious" cases
305 test -z "$include" && test -z "$positive" && continue
306 test -n "$include" && test -n "$positive" && continue
310 if test $arg -le ${selector#-}
316 if test $arg -ge ${selector%-}
322 if test ${selector%%-*} -le $arg \
323 && test $arg -le ${selector#*-}
329 if test $arg -eq $selector
340 maybe_teardown_verbose
() {
341 test -z "$verbose_only" && return
342 exec 4>/dev
/null
3>/dev
/null
346 maybe_setup_verbose
() {
347 test -z "$verbose_only" && return
348 if match_pattern_list
$test_count $verbose_only
350 if test "$verbose_log" = "t"
352 exec 3>>"$TESTLIB_TEST_TEE_OUTPUT_FILE" 4>&3
356 # Emit a delimiting blank line when going from
357 # non-verbose to verbose. Within verbose mode the
358 # delimiter is printed by test_expect_*. The choice
359 # of the initial $last_verbose is such that before
360 # test 1, we do not print it.
361 test -z "$last_verbose" && echo >&3 ""
364 exec 4>/dev
/null
3>/dev
/null
367 last_verbose
=$verbose
371 test "$trace" = t
&& test "$verbose" = t
374 # This is a separate function because some tests use
375 # "return" to end a test_expect_success block early
376 # (and we want to make sure we run any cleanup like
379 # Do not add anything extra (including LF) after '$*'
382 test_subshell_active_=t
383 ! want_trace || ! set -x && ! :
387 # Same thing as test_eval_inner_ but without the subshell
388 test_eval_inner_no_subshell_
() {
389 # Do not add anything extra (including LF) after '$*'
391 ! want_trace || ! set -x && ! :
396 # We run this block with stderr redirected to avoid extra cruft
397 # during a "-x" trace. Once in "set -x" mode, we cannot prevent
398 # the shell from printing the "set +x" to turn it off (nor the saving
399 # of $? before that). But we can make sure that the output goes to
402 # The test itself is run with stderr put back to &4 (so either to
403 # /dev/null, or to the original stderr if --verbose was used).
407 if test "${test_eval_ss_:-0}" = "0"
409 test_eval_inner_no_subshell_
"$@" </dev
/null
>&3 2>&4
411 test_eval_inner_
"$@" </dev
/null
>&3 2>&4
417 if test "$test_eval_ret_" != 0
419 say_color error
>&4 "error: last command exited with \$?=$test_eval_ret_"
423 return $test_eval_ret_
426 # Calls the real test_eval_ss_ with !"$TESTLIB_TEST_NO_SUBSHELL" as first arg
428 if test -n "$TESTLIB_TEST_NO_SUBSHELL"
430 test_eval_ss_
"0" "$@"
432 test_eval_ss_
"1" "$@"
436 # If "$1" = "-" read the script from stdin but ONLY if stdin is NOT a tty
437 # Store the test script in test_script_
441 ! test -t 0 || error
"test script is '-' but STDIN is a tty"
442 test_script_
="$(cat)"
443 test -n "$test_script_" || error
"test script is '-' but STDIN is empty"
444 test_script_
="$LF$test_script_$LF"
456 test_subshell_active_
=
460 if test "${TESTLIB_TEST_CHAIN_LINT:-1}" != 0; then
461 # turn off tracing for this test-eval, as it simply creates
462 # confusing noise in the "-x" output
466 # 117 is magic because it is unlikely to match the exit
467 # code of other programs
468 test_eval_ss_
"1" "fail_ 117 && $1${LF}fail_ \$?"
469 if test "$?" != 117; then
470 error
"bug in the test script: broken &&-chain: $1"
479 if test -z "$immediate" ||
test $eval_ret = 0 ||
480 test -n "$expecting_failure" && test "${test_cleanup:-:}" != ":"
482 test_eval_
"$test_cleanup"
484 if test "$verbose" = "t" && test -n "$HARNESS_ACTIVE"
492 test_count
=$
(($test_count+1))
498 maybe_teardown_verbose
504 if match_pattern_list
$this_test.
$test_count $TESTLIB_SKIP_TESTS
507 skipped_reason
="TESTLIB_SKIP_TESTS"
509 if test -z "$to_skip" && test -n "$test_prereq" &&
510 ! test_have_prereq
"$test_prereq"
515 if test "$missing_prereq" != "$test_prereq"
517 of_prereq
=" of $test_prereq"
519 skipped_reason
="missing $missing_prereq${of_prereq}"
521 if test -z "$to_skip" && test -n "$run_list" &&
522 ! match_test_selector_list
'--run' $test_count "$run_list"
525 skipped_reason
="--run"
530 say_color skip
>&3 "skipping test: $@"
531 say_color_tap skip
"ok $test_count # skip $1 ($skipped_reason)"
540 # stub; runs at end of each successful test
541 test_at_end_hook_
() {
548 if test -z "$HARNESS_ACTIVE"
550 test_results_dir
="$TEST_OUTPUT_DIRECTORY/test-results"
551 mkdir
-p "$test_results_dir"
553 test_results_path
="$test_results_dir/${base%.sh}.counts"
555 cat >"$test_results_path" <<-EOF
557 success $test_success
565 if test "$test_fixed" != 0
567 say_color error
"# $test_fixed known breakage(s) vanished; please update test(s)"
569 if test "$test_broken" != 0
571 say_color warn
"# still have $test_broken known breakage(s)"
573 if test "$test_broken" != 0 ||
test "$test_fixed" != 0
575 test_remaining
=$
(( $test_count - $test_broken - $test_fixed ))
576 msg
="remaining $test_remaining test(s)"
578 test_remaining
=$test_count
579 msg
="$test_count test(s)"
581 case "$test_failure" in
583 # Maybe print SKIP message
584 if test -n "$skip_all" && test $test_count -gt 0
586 error
"Can't use skip_all after running some tests"
588 test -z "$skip_all" || skip_all
=" # SKIP $skip_all"
590 if test $test_external_has_tap -eq 0
592 if test $test_remaining -gt 0
594 say_color pass
"# passed all $msg"
596 test -n "$test_wrote_plan_count" || say_tap
"1..$test_count$skip_all"
598 if test -n "$test_wrote_plan_count" && test "$test_wrote_plan_count" -ne "$test_count"
600 say_color error
"# plan count of $test_wrote_plan_count does not match run count of $test_count"
604 test -n "$remove_trash" &&
605 test -d "$remove_trash" &&
606 cd "${remove_trash%/*}" &&
607 test_done_td_
="${remove_trash##*/}" &&
608 test -e "$test_done_td_" &&
609 rm -rf "$test_done_td_" &&
611 ! test -e "$test_done_td_" ||
{
612 chmod -R u
+w
"$test_done_td_" &&
613 rm -rf "$test_done_td_"
622 if test $test_external_has_tap -eq 0
624 say_color error
"# failed $test_failure among $msg"
625 test -n "$test_wrote_plan_count" || say_tap
"1..$test_count"
627 if test -n "$test_wrote_plan_count" && test "$test_wrote_plan_count" -ne "$test_count"
629 say_color error
"# plan count of $test_wrote_plan_count does not match run count of $test_count"
632 test -z "$HARNESS_ACTIVE" ||
exit 0
639 test -n "$1" && test "z$1" = "z${1#*[!0-9]}" || fatal
"invalid test_plan argument: $1"
640 test "$1" -eq 0 ||
test -z "$2" || fatal
"invalid test_plan arguments: $*"
641 if test "$1" -eq 0; then
642 skip_all
="${2:-skip all tests in $this_test}"
645 test $test_external_has_tap -ne 0 || say_tap
"1..$1"
646 test_wrote_plan_count
="$1"
649 # Provide an implementation of the 'yes' utility
666 run_with_limited_cmdline
() {
667 (ulimit -s 128 && "$@")
672 ## Note that the following functions have bodies that are NOT indented
673 ## to assist with readability
677 test_lib_main_init_tee
() {
678 # Begin test_lib_main_init_tee
681 # if --tee was passed, write the output not only to the terminal, but
682 # additionally to the file test-results/$BASENAME.out, too.
683 case "$TESTLIB_TEST_TEE_STARTED, $* " in
685 # do not redirect again
687 *' --tee '*|
*' --verbose-log '*)
688 mkdir
-p "$TEST_OUTPUT_DIRECTORY/test-results"
689 BASE
="$TEST_OUTPUT_DIRECTORY/test-results/${0##*/}"
692 # Make this filename available to the sub-process in case it is using
694 TESTLIB_TEST_TEE_OUTPUT_FILE
=$BASE.out
695 export TESTLIB_TEST_TEE_OUTPUT_FILE
697 # Truncate before calling "tee -a" to get rid of the results
698 # from any previous runs.
699 >"$TESTLIB_TEST_TEE_OUTPUT_FILE"
702 (ec
=0; TESTLIB_TEST_TEE_STARTED
=done ${SHELL_PATH} "$0" "$@" 2>&1 || ec
=$?
703 echo $ec >"$BASE.exit") |
tee -a "$TESTLIB_TEST_TEE_OUTPUT_FILE"
704 exitcode
="$(cat "$BASE.
exit" 2>/dev/null)" ||
:
710 # End test_lib_main_init_tee
714 test_lib_main_init_funcs
() {
715 # Begin test_lib_main_init_funcs
718 [ -z "$test_lib_main_init_funcs_done" ] ||
return 0
723 test -z "$1" && test -n "$quiet" && return
724 eval "say_color_color=\$say_color_$1"
728 if test -n "$HARNESS_ACTIVE"
730 case "$_sms" in '#'*)
735 printf '%s\n' "$_sfc$say_color_color$_sms$say_color_reset"
739 test -z "$1" && test -n "$quiet" && return
745 # Just like say_color except if HARNESS_ACTIVE it's ALWAYS output and WITHOUT color
747 if test -n "$HARNESS_ACTIVE"
757 # Fix some commands on Windows
758 case "${UNAME_S:=$(uname -s)}" in
760 # Windows has its own (incompatible) sort and find
770 # git sees Windows-style pwd
777 test_lib_main_init_funcs_done
=1
780 # End test_lib_main_init_funcs
784 # This function is called with all the test args and must perform all
785 # initialization that involves variables and is not specific to "$0"
786 # or "$test_description" in any way. This function may only be called
787 # once per run of the entire test suite.
788 test_lib_main_init_generic
() {
789 # Begin test_lib_main_init_generic
791 [ -n "$TESTLIB_DIRECTORY" ] || whats_the_dir
-L -- "${TEST_DIRECTORY:-.}/test-lib.sh" TESTLIB_DIRECTORY
792 [ -f "$TESTLIB_DIRECTORY/test-lib.sh" ] && [ -f "$TESTLIB_DIRECTORY/test-lib-main.sh" ] &&
793 [ -f "$TESTLIB_DIRECTORY/test-lib-functions.sh" ] &&
794 [ -f "$TESTLIB_DIRECTORY/test-lib-functions-tg.sh" ] ||
795 fatal
"error: invalid TESTLIB_DIRECTORY: $TESTLIB_DIRECTORY"
796 export TESTLIB_DIRECTORY
798 ! [ -f "$TESTLIB_DIRECTORY/../TG-BUILD-SETTINGS" ] || .
"$TESTLIB_DIRECTORY/../TG-BUILD-SETTINGS"
799 ! [ -f "$TESTLIB_DIRECTORY/TG-TEST-SETTINGS" ] || .
"$TESTLIB_DIRECTORY/TG-TEST-SETTINGS"
801 : "${SHELL_PATH:=/bin/sh}"
803 : "${GIT_PATH:=$(cmd_path git)}"
804 : "${PERL_PATH:=$(cmd_path perl || :)}"
806 # Test the binaries we have just built. The tests are kept in
807 # t/ subdirectory and are run in 'trash directory' subdirectory.
808 if test -z "$TEST_DIRECTORY"
810 # We allow tests to override this, in case they want to run tests
811 # outside of t/, e.g. for running tests on the test library
813 TEST_DIRECTORY
="$TESTLIB_DIRECTORY"
815 # ensure that TEST_DIRECTORY is an absolute path so that it
816 # is valid even if the current working directory is changed
817 TEST_DIRECTORY
="$(cd "$TEST_DIRECTORY" && pwd)" ||
exit 1
819 if test -z "$TEST_OUTPUT_DIRECTORY"
821 # Similarly, override this to store the test-results subdir
823 TEST_OUTPUT_DIRECTORY
="$TEST_DIRECTORY"
825 [ -d "$TESTLIB_DIRECTORY"/empty
] ||
{
826 mkdir
"$TESTLIB_DIRECTORY/empty" ||
:
827 chmod a-w
"$TESTLIB_DIRECTORY/empty" ||
:
828 test -d "$TESTLIB_DIRECTORY"/empty ||
829 fatal
"error: could not make empty directory: '$TESTLIB_DIRECTORY/empty'"
831 EMPTY_DIRECTORY
="$TESTLIB_DIRECTORY/empty"
832 export TEST_DIRECTORY TEST_OUTPUT_DIRECTORY EMPTY_DIRECTORY
833 GIT_CEILING_DIRECTORIES
="$TESTLIB_DIRECTORY"
834 [ "$TESTLIB_DIRECTORY" = "$TEST_DIRECTORY" ] ||
835 GIT_CEILING_DIRECTORIES
="$TEST_DIRECTORY:$GIT_CEILING_DIRECTORIES"
836 [ "$TESTLIB_DIRECTORY" = "$TEST_OUTPUT_DIRECTORY" ] ||
837 GIT_CEILING_DIRECTORIES
="$TEST_OUTPUT_DIRECTORY:$GIT_CEILING_DIRECTORIES"
838 export GIT_CEILING_DIRECTORIES
840 ################################################################
841 # It appears that people try to run tests with missing perl or git...
842 git_version
="$("$GIT_PATH" --version 2>&1)" ||
843 fatal
'error: you do not seem to have git available?'
844 case "$git_version" in [Gg
][Ii
][Tt
]\
[Vv
][Ee
][Rr
][Ss
][Ii
][Oo
][Nn
]\
[0-9]*);;*)
845 fatal
"error: git --version returned bogus value: $git_version"
847 #"$PERL_PATH" --version >/dev/null 2>&1 ||
848 # fatal 'error: you do not seem to have perl available?'
850 test_lib_main_init_tee
"$@"
852 # For repeatability, reset the environment to known value.
853 # TERM is sanitized below, after saving color control sequences.
858 export LANG LC_ALL PAGER TZ
860 # A call to "unset" with no arguments causes at least Solaris 10
861 # /usr/xpg4/bin/sh and /bin/ksh to bail out. So keep the unsets
862 # deriving from the command substitution clustered with the other
864 unset VISUAL EMAIL LANGUAGE COLUMNS $
("$PERL_PATH" -e '
866 my $ok = join("|", qw(
881 my @vars = grep(/^GIT_/ && !/^GIT_($ok)/o, @env);
882 print join("\n", @vars);
884 unset XDG_CONFIG_HOME
886 GIT_AUTHOR_NAME
='Te s t'
887 GIT_AUTHOR_EMAIL
=test@example.net
888 GIT_COMMITTER_NAME
='Fra mewor k'
889 GIT_COMMITTER_EMAIL
=framework@example.org
890 GIT_MERGE_VERBOSITY
=5
891 GIT_MERGE_AUTOEDIT
=no
892 GIT_TEMPLATE_DIR
="$EMPTY_DIRECTORY"
893 GIT_CONFIG_NOSYSTEM
=1
895 export PATH GIT_TEMPLATE_DIR GIT_CONFIG_NOSYSTEM GIT_ATTR_NOSYSTEM
896 export GIT_MERGE_VERBOSITY GIT_MERGE_AUTOEDIT
897 export GIT_AUTHOR_EMAIL GIT_AUTHOR_NAME
898 export GIT_COMMITTER_EMAIL GIT_COMMITTER_NAME
901 # Tests using GIT_TRACE typically don't want <timestamp> <file>:<line> output
903 export GIT_TRACE_BARE
905 # Protect ourselves from common misconfiguration to export
906 # CDPATH into the environment
912 case "$GIT_TRACE" in 1|
2|
[Tt
][Rr
][Uu
][Ee
])
919 # A regexp to match 5 and 40 hexdigits
920 _x05
='[0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f]'
921 _x40
="$_x05$_x05$_x05$_x05$_x05$_x05$_x05$_x05"
924 _z40
=0000000000000000000000000000000000000000
926 EMPTY_TREE
=4b825dc642cb6eb9a060e54bf8d69288fbee4904
927 EMPTY_BLOB
=e69de29bb2d1d6434b8b29ae775ad8c2e48c5391
933 # UTF-8 ZERO WIDTH NON-JOINER, which HFS+ ignores
934 # when case-folding filenames
935 u200c
="$(printf '\342\200\214')"
937 export _x05 _x40 _z40 LF u200c EMPTY_TREE EMPTY_BLOB
939 while test "$#" -ne 0
942 -d|
--d|
--de|
--deb|
--debu|
--debug)
944 -i|
--i|
--im|
--imm|
--imme|
--immed|
--immedi|
--immedia|
--immediat|
--immediate)
945 immediate
=t
; shift ;;
946 -l|
--l|
--lo|
--lon|
--long|
--long-|
--long-t|
--long-te|
--long-tes|
--long-test|
--long-tests|\
947 --ex|
--exp|
--expe|
--expen|
--expens|
--expensi|
--expensiv|
--expensive)
948 TESTLIB_TEST_LONG
=t
; export TESTLIB_TEST_LONG
; shift ;;
950 shift; test "$#" -ne 0 ||
{
951 echo 'error: -r requires an argument' >&2;
954 run_list
=$1; shift ;;
956 run_list
=${1#--*=}; shift ;;
957 -h|
--h|
--he|
--hel|
--help)
959 -v|
--v|
--ve|
--ver|
--verb|
--verbo|
--verbos|
--verbose)
962 verbose_only
=${1#--*=}
964 -q|
--q|
--qu|
--qui|
--quie|
--quiet)
971 shift ;; # was handled already
976 TESTLIB_TEST_CHAIN_LINT
=1
979 TESTLIB_TEST_CHAIN_LINT
=0
981 -x|
--x|
--xt|
--xtr|
--xtra|
--xtrac|
--xtrace)
989 echo "error: unknown test option '$1'" >&2; exit 1 ;;
993 test "x${color+set}" != "xset" &&
994 test "x$TERM" != "xdumb" && (
995 { test -n "$TESTLIB_FORCETTY" ||
test -t 1; } &&
996 tput bold
>/dev
/null
2>&1 &&
997 tput setaf
1 >/dev
/null
2>&1 &&
998 tput sgr0
>/dev
/null
2>&1
1003 # Save the color control sequences now rather than run tput
1004 # each time say_color() is called. This is done for two
1006 # * TERM will be changed to dumb
1007 # * HOME will be changed to a temporary directory and tput
1008 # might need to read ~/.terminfo from the original HOME
1009 # directory to get the control sequences
1010 getcmd say_color_error
eval 'tput setaf 1' # red
1011 getcmd say_color_skip
eval 'tput bold; tput setaf 5' # bold blue
1012 getcmd say_color_warn
eval 'tput setaf 3' # brown/yellow
1013 getcmd say_color_pass
eval 'tput setaf 2' # green
1014 getcmd say_color_info
eval 'tput setaf 6' # cyan
1015 getcmd say_color_reset
eval 'tput sgr0'
1016 say_color_
="" # no formatting for normal text
1022 # Send any "-x" output directly to stderr to avoid polluting tests
1023 # which capture stderr. We can do this unconditionally since it
1024 # has no effect if tracing isn't turned on.
1026 # Note that this sets up the trace fd as soon as we assign the variable, so it
1027 # must come after the creation of descriptor 4 above. Likewise, we must never
1028 # unset this, as it has the side effect of closing descriptor 4, which we
1029 # use to show verbose tests to the user.
1031 # Note also that we don't need or want to export it. The tracing is local to
1032 # this shell, and we would not want to influence any shells we exec.
1041 test_external_has_tap
=0
1043 # The user-facing functions are loaded from a separate file
1044 .
"$TESTLIB_DIRECTORY/test-lib-functions-tg.sh"
1045 .
"$TESTLIB_DIRECTORY/test-lib-functions.sh"
1046 test_lib_functions_init
1047 test_lib_functions_tg_init
1051 [ -d "$TEST_DIRECTORY/helper" ] && PATH
="$TEST_DIRECTORY/helper:$PATH"
1052 if [ -n "$TG_TEST_INSTALLED" ]; then
1053 TG_FULL_PATH
="$(cmd_path tg)" && [ -n "$TG_FULL_PATH" ] ||
1054 fatal
'error: TG_TEST_INSTALLED set but no tg found in $PATH!'
1056 tg_bin_dir
="$(cd "$TESTLIB_DIRECTORY/..
/bin-wrappers
" 2>/dev/null && pwd -P || :)"
1057 [ -x "$tg_bin_dir/tg" ] ||
1058 fatal
'error: no ../bin-wrappers/tg executable found!'
1059 PATH
="$tg_bin_dir:$PATH"
1060 TG_FULL_PATH
="$tg_bin_dir/tg"
1063 tg_version
="$(tg --version)" ||
1064 fatal
'error: tg --version failed!'
1065 case "$tg_version" in [Tt
][Oo
][Pp
][Gg
][Ii
][Tt
]\
[Vv
][Ee
][Rr
][Ss
][Ii
][Oo
][Nn
]\
[0-9]*);;*)
1066 fatal
"error: tg --version returned bogus value: $tg_version"
1069 vcmp
"$git_version" '>=' "$GIT_MINIMUM_VERSION" ||
1070 fatal
"git version >= $GIT_MINIMUM_VERSION required but found \"$git_version\" instead"
1072 if test -z "$TESTLIB_TEST_CMP"
1074 if test -n "$TESTLIB_TEST_CMP_USE_COPIED_CONTEXT"
1076 TESTLIB_TEST_CMP
="$DIFF -c"
1078 TESTLIB_TEST_CMP
="$DIFF -u"
1082 # Fix some commands on Windows
1083 case "${UNAME_S:=$(uname -s)}" in
1085 # no POSIX permissions
1086 # backslashes in pathspec are converted to '/'
1087 # exec does not inherit the PID
1088 test_set_prereq MINGW
1089 test_set_prereq NATIVE_CRLF
1090 test_set_prereq SED_STRIPS_CR
1091 test_set_prereq GREP_STRIPS_CR
1092 TESTLIB_TEST_CMP
=mingw_test_cmp
1095 test_set_prereq POSIXPERM
1096 test_set_prereq EXECKEEPSPID
1097 test_set_prereq CYGWIN
1098 test_set_prereq SED_STRIPS_CR
1099 test_set_prereq GREP_STRIPS_CR
1102 test_set_prereq POSIXPERM
1103 test_set_prereq BSLASHPSPEC
1104 test_set_prereq EXECKEEPSPID
1108 ( COLUMNS
=1 && test $COLUMNS = 1 ) && test_set_prereq COLUMNS_CAN_BE_1
1110 test_lib_main_init_funcs
1112 test_lazy_prereq PIPE
'
1113 # test whether the filesystem supports FIFOs
1114 case "${UNAME_S:=$(uname -s)}" in
1119 rm -f testfifo && mkfifo testfifo
1124 test_lazy_prereq SYMLINKS
'
1125 # test whether the filesystem supports symbolic links
1126 ln -s x y && test -h y
1129 test_lazy_prereq FILEMODE
'
1130 test "$(git config --bool core.filemode)" = true
1133 test_lazy_prereq CASE_INSENSITIVE_FS
'
1134 echo good >CamelCase &&
1135 echo bad >camelcase &&
1136 test "$(cat CamelCase)" != good
1139 test_lazy_prereq UTF8_NFD_TO_NFC
'
1140 # check whether FS converts nfd unicode to nfc
1141 auml="$(printf "\303\244")"
1142 aumlcdiar="$(printf "\141\314\210")"
1152 test_lazy_prereq AUTOIDENT
'
1153 sane_unset GIT_AUTHOR_NAME &&
1154 sane_unset GIT_AUTHOR_EMAIL &&
1155 git var GIT_AUTHOR_IDENT
1158 test_lazy_prereq EXPENSIVE
'
1159 test -n "$TESTLIB_TEST_LONG"
1162 test_lazy_prereq USR_BIN_TIME
'
1163 test -x /usr/bin/time
1166 test_lazy_prereq NOT_ROOT
'
1171 # SANITY is about "can you correctly predict what the filesystem would
1172 # do by only looking at the permission bits of the files and
1173 # directories?" A typical example of !SANITY is running the test
1174 # suite as root, where a test may expect "chmod -r file && cat file"
1175 # to fail because file is supposed to be unreadable after a successful
1176 # chmod. In an environment (i.e. combination of what filesystem is
1177 # being used and who is running the tests) that lacks SANITY, you may
1178 # be able to delete or create a file when the containing directory
1179 # doesn't have write permissions, or access a file even if the
1180 # containing directory doesn't have read or execute permissions.
1182 test_lazy_prereq SANITY
'
1183 mkdir SANETESTD.1 SANETESTD.2 &&
1185 chmod +w SANETESTD.1 SANETESTD.2 &&
1186 >SANETESTD.1/x 2>SANETESTD.2/x &&
1187 chmod -w SANETESTD.1 &&
1188 chmod -r SANETESTD.1/x &&
1189 chmod -rx SANETESTD.2 ||
1190 error "bug in test sript: cannot prepare SANETESTD"
1192 ! test -r SANETESTD.1/x &&
1193 ! rm SANETESTD.1/x && ! test -f SANETESTD.2/x
1196 chmod +rwx SANETESTD.1 SANETESTD.2 &&
1197 rm -rf SANETESTD.1 SANETESTD.2 ||
1198 error "bug in test sript: cannot clean SANETESTD"
1202 test_lazy_prereq CMDLINE_LIMIT
'run_with_limited_cmdline true'
1205 # End test_lib_main_init_generic
1209 # This function is guaranteed to always be called for every single test.
1210 # Only put things in this function that MUST be done per-test, function
1211 # definitions and sourcing other files generally DO NOT QUALIFY (there can
1213 test_lib_main_init_specific
() {
1214 # Begin test_lib_main_init_specific
1217 # original stdin is on 6, stdout on 5 and stderr on 7
1220 test_lib_main_init_funcs
1222 if test -n "$HARNESS_ACTIVE"
1224 if test "$verbose" = t ||
test -n "$verbose_only" && test -z "$verbose_log$TESTLIB_OVERRIDE"
1226 printf 'Bail out! %s\n' \
1227 'verbose mode forbidden under TAP harness; use --verbose-log'
1232 test "${test_description}" != "" ||
1233 error
"Test script did not set test_description."
1235 if test "$help" = "t"
1237 printf '%s\n' "$(printf '%s\n' "$test_description")" |
1252 if test "$verbose_log" = "t"
1254 exec 3>>"$TESTLIB_TEST_TEE_OUTPUT_FILE" 4>&3
1255 elif test "$verbose" = "t"
1259 exec 4>/dev
/null
3>/dev
/null
1264 trap 'exit $?' HUP INT QUIT ABRT PIPE TERM
1265 trap 'TESTLIB_EXIT_OK=t; exit 1' USR1
1268 TRASH_DIRECTORY
="trash directory.${0##*/}"
1269 TRASH_DIRECTORY
="${TRASH_DIRECTORY%.sh}"
1270 test -n "$root" && TRASH_DIRECTORY
="$root/$TRASH_DIRECTORY"
1271 test -n "$root" && GIT_CEILING_DIRECTORIES
="$root:$GIT_CEILING_DIRECTORIES"
1272 case "$TRASH_DIRECTORY" in
1273 /*) ;; # absolute path is good
1274 *) TRASH_DIRECTORY
="$TEST_OUTPUT_DIRECTORY/$TRASH_DIRECTORY" ;;
1276 test ! -z "$debug" || remove_trash
=$TRASH_DIRECTORY
1277 ! test -e "$TRASH_DIRECTORY" ||
{
1278 rm -rf "$TRASH_DIRECTORY" &&
1279 ! test -e "$TRASH_DIRECTORY" ||
{
1280 chmod -R u
+w
"$TRASH_DIRECTORY" &&
1281 rm -rf "$TRASH_DIRECTORY" &&
1282 ! test -e "$TRASH_DIRECTORY"
1286 echo >&5 "FATAL: Cannot prepare test area"
1290 HOME
="$TRASH_DIRECTORY"
1291 GNUPGHOME
="$HOME/gnupg-home-not-used"
1292 export HOME GNUPGHOME
1294 if test -z "$TEST_NO_CREATE_REPO"
1296 test_create_repo
"$TRASH_DIRECTORY"
1298 mkdir
-p "$TRASH_DIRECTORY"
1300 # Use -P to resolve symlinks in our working directory so that the cwd
1301 # in subprocesses like tg equals our $PWD (for pathname comparisons).
1302 cd -P "$TRASH_DIRECTORY" ||
exit 1
1305 this_test
=${this_test%%-*}
1306 test_wrote_plan_count
=
1307 test_last_subtest_ok
=1
1308 if match_pattern_list
"$this_test" $TESTLIB_SKIP_TESTS
1310 say_color info
>&3 "skipping test $this_test altogether"
1311 skip_all
="skip all tests in $this_test"
1316 # End test_lib_main_init_specific
1321 # THIS SHOULD ALWAYS BE THE LAST FUNCTION DEFINED IN THIS FILE
1323 # Any client that sources this file should immediately execute this function
1324 # afterwards with the command line arguments
1326 # THERE SHOULD NOT BE ANY DIRECTLY EXECUTED LINES OF CODE IN THIS FILE
1328 test_lib_main_init
() {
1330 test_lib_main_init_generic
"$@"
1331 test_lib_main_init_specific
"$@"