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
349 # Emit a delimiting blank line when going from
350 # non-verbose to verbose. Within verbose mode the
351 # delimiter is printed by test_expect_*. The choice
352 # of the initial $last_verbose is such that before
353 # test 1, we do not print it.
354 test -z "$last_verbose" && echo >&3 ""
357 exec 4>/dev
/null
3>/dev
/null
360 last_verbose
=$verbose
364 test "$trace" = t
&& test "$verbose" = t
367 # This is a separate function because some tests use
368 # "return" to end a test_expect_success block early
369 # (and we want to make sure we run any cleanup like
372 # Do not add anything extra (including LF) after '$*'
375 test_subshell_active_=t
376 ! want_trace || ! set -x && ! :
380 # Same thing as test_eval_inner_ but without the subshell
381 test_eval_inner_no_subshell_
() {
382 # Do not add anything extra (including LF) after '$*'
384 ! want_trace || ! set -x && ! :
389 # We run this block with stderr redirected to avoid extra cruft
390 # during a "-x" trace. Once in "set -x" mode, we cannot prevent
391 # the shell from printing the "set +x" to turn it off (nor the saving
392 # of $? before that). But we can make sure that the output goes to
395 # The test itself is run with stderr put back to &4 (so either to
396 # /dev/null, or to the original stderr if --verbose was used).
400 if test "${test_eval_ss_:-0}" = "0"
402 test_eval_inner_no_subshell_
"$@" </dev
/null
>&3 2>&4
404 test_eval_inner_
"$@" </dev
/null
>&3 2>&4
410 if test "$test_eval_ret_" != 0
412 say_color error
>&4 "error: last command exited with \$?=$test_eval_ret_"
416 return $test_eval_ret_
419 # Calls the real test_eval_ss_ with !"$TESTLIB_TEST_NO_SUBSHELL" as first arg
421 if test -n "$TESTLIB_TEST_NO_SUBSHELL"
423 test_eval_ss_
"0" "$@"
425 test_eval_ss_
"1" "$@"
429 # If "$1" = "-" read the script from stdin but ONLY if stdin is NOT a tty
430 # Store the test script in test_script_
434 ! test -t 0 || error
"test script is '-' but STDIN is a tty"
435 test_script_
="$(cat)"
436 test -n "$test_script_" || error
"test script is '-' but STDIN is empty"
437 test_script_
="$LF$test_script_$LF"
449 test_subshell_active_
=
453 if test "${TESTLIB_TEST_CHAIN_LINT:-1}" != 0; then
454 # turn off tracing for this test-eval, as it simply creates
455 # confusing noise in the "-x" output
459 # 117 is magic because it is unlikely to match the exit
460 # code of other programs
461 test_eval_ss_
"1" "fail_ 117 && $1${LF}fail_ \$?"
462 if test "$?" != 117; then
463 error
"bug in the test script: broken &&-chain: $1"
472 if test -z "$immediate" ||
test $eval_ret = 0 ||
473 test -n "$expecting_failure" && test "${test_cleanup:-:}" != ":"
475 test_eval_
"$test_cleanup"
477 if test "$verbose" = "t" && test -n "$HARNESS_ACTIVE"
485 test_count
=$
(($test_count+1))
491 maybe_teardown_verbose
497 if match_pattern_list
$this_test.
$test_count $TESTLIB_SKIP_TESTS
500 skipped_reason
="TESTLIB_SKIP_TESTS"
502 if test -z "$to_skip" && test -n "$test_prereq" &&
503 ! test_have_prereq
"$test_prereq"
508 if test "$missing_prereq" != "$test_prereq"
510 of_prereq
=" of $test_prereq"
512 skipped_reason
="missing $missing_prereq${of_prereq}"
514 if test -z "$to_skip" && test -n "$run_list" &&
515 ! match_test_selector_list
'--run' $test_count "$run_list"
518 skipped_reason
="--run"
523 say_color skip
>&3 "skipping test: $@"
524 say_color_tap skip
"ok $test_count # skip $1 ($skipped_reason)"
533 # stub; runs at end of each successful test
534 test_at_end_hook_
() {
541 if test -z "$HARNESS_ACTIVE"
543 test_results_dir
="$TEST_OUTPUT_DIRECTORY/test-results"
544 mkdir
-p "$test_results_dir"
546 test_results_path
="$test_results_dir/${base%.sh}.counts"
548 cat >"$test_results_path" <<-EOF
550 success $test_success
558 if test "$test_fixed" != 0
560 say_color error
"# $test_fixed known breakage(s) vanished; please update test(s)"
562 if test "$test_broken" != 0
564 say_color warn
"# still have $test_broken known breakage(s)"
566 if test "$test_broken" != 0 ||
test "$test_fixed" != 0
568 test_remaining
=$
(( $test_count - $test_broken - $test_fixed ))
569 msg
="remaining $test_remaining test(s)"
571 test_remaining
=$test_count
572 msg
="$test_count test(s)"
574 case "$test_failure" in
576 # Maybe print SKIP message
577 if test -n "$skip_all" && test $test_count -gt 0
579 error
"Can't use skip_all after running some tests"
581 test -z "$skip_all" || skip_all
=" # SKIP $skip_all"
583 if test $test_external_has_tap -eq 0
585 if test $test_remaining -gt 0
587 say_color pass
"# passed all $msg"
589 say_tap
"1..$test_count$skip_all"
592 test -d "$remove_trash" &&
593 cd "${remove_trash%/*}" &&
594 test_done_td_
="${remove_trash##*/}" &&
595 test -e "$test_done_td_" &&
596 rm -rf "$test_done_td_" &&
597 ! test -e "$test_done_td_" ||
{
598 chmod -R u
+w
"$test_done_td_" &&
599 rm -rf "$test_done_td_"
607 if test $test_external_has_tap -eq 0
609 say_color error
"# failed $test_failure among $msg"
610 say_tap
"1..$test_count"
618 # Provide an implementation of the 'yes' utility
635 run_with_limited_cmdline
() {
636 (ulimit -s 128 && "$@")
641 ## Note that the following functions have bodies that are NOT indented
642 ## to assist with readability
646 test_lib_main_init_tee
() {
647 # Begin test_lib_main_init_tee
650 # if --tee was passed, write the output not only to the terminal, but
651 # additionally to the file test-results/$BASENAME.out, too.
652 case "$TESTLIB_TEST_TEE_STARTED, $* " in
654 # do not redirect again
656 *' --tee '*|
*' --verbose-log '*)
657 mkdir
-p "$TEST_OUTPUT_DIRECTORY/test-results"
658 BASE
="$TEST_OUTPUT_DIRECTORY/test-results/${0##*/}"
661 # Make this filename available to the sub-process in case it is using
663 TESTLIB_TEST_TEE_OUTPUT_FILE
=$BASE.out
664 export TESTLIB_TEST_TEE_OUTPUT_FILE
666 # Truncate before calling "tee -a" to get rid of the results
667 # from any previous runs.
668 >"$TESTLIB_TEST_TEE_OUTPUT_FILE"
671 (ec
=0; TESTLIB_TEST_TEE_STARTED
=done ${SHELL_PATH} "$0" "$@" 2>&1 || ec
=$?
672 echo $ec >"$BASE.exit") |
tee -a "$TESTLIB_TEST_TEE_OUTPUT_FILE"
673 exitcode
="$(cat "$BASE.
exit" 2>/dev/null)" ||
:
679 # End test_lib_main_init_tee
683 test_lib_main_init_funcs
() {
684 # Begin test_lib_main_init_funcs
687 [ -z "$test_lib_main_init_funcs_done" ] ||
return 0
692 test -z "$1" && test -n "$quiet" && return
693 eval "say_color_color=\$say_color_$1"
697 if test -n "$HARNESS_ACTIVE"
699 case "$_sms" in '#'*)
704 printf '%s\n' "$_sfc$say_color_color$_sms$say_color_reset"
708 test -z "$1" && test -n "$quiet" && return
714 # Just like say_color except if HARNESS_ACTIVE it's ALWAYS output and WITHOUT color
716 if test -n "$HARNESS_ACTIVE"
726 # Fix some commands on Windows
727 case "${UNAME_S:=$(uname -s)}" in
729 # Windows has its own (incompatible) sort and find
739 # git sees Windows-style pwd
746 test_lib_main_init_funcs_done
=1
749 # End test_lib_main_init_funcs
753 # This function is called with all the test args and must perform all
754 # initialization that involves variables and is not specific to "$0"
755 # or "$test_description" in any way. This function may only be called
756 # once per run of the entire test suite.
757 test_lib_main_init_generic
() {
758 # Begin test_lib_main_init_generic
760 [ -n "$TESTLIB_DIRECTORY" ] || whats_the_dir
-L -- "${TEST_DIRECTORY:-.}/test-lib.sh" TESTLIB_DIRECTORY
761 [ -f "$TESTLIB_DIRECTORY/test-lib.sh" ] && [ -f "$TESTLIB_DIRECTORY/test-lib-main.sh" ] &&
762 [ -f "$TESTLIB_DIRECTORY/test-lib-functions.sh" ] ||
763 fatal
"error: invalid TESTLIB_DIRECOTRY: $TESTLIB_DIRECTORY"
764 export TESTLIB_DIRECTORY
766 ! [ -f "$TESTLIB_DIRECTORY/../TG-BUILD-SETTINGS" ] || .
"$TESTLIB_DIRECTORY/../TG-BUILD-SETTINGS"
767 ! [ -f "$TESTLIB_DIRECTORY/TG-TEST-SETTINGS" ] || .
"$TESTLIB_DIRECTORY/TG-TEST-SETTINGS"
769 : "${SHELL_PATH:=/bin/sh}"
771 : "${GIT_PATH:=$(cmd_path git)}"
772 : "${PERL_PATH:=$(cmd_path perl || :)}"
774 # Test the binaries we have just built. The tests are kept in
775 # t/ subdirectory and are run in 'trash directory' subdirectory.
776 if test -z "$TEST_DIRECTORY"
778 # We allow tests to override this, in case they want to run tests
779 # outside of t/, e.g. for running tests on the test library
781 TEST_DIRECTORY
="$TESTLIB_DIRECTORY"
783 # ensure that TEST_DIRECTORY is an absolute path so that it
784 # is valid even if the current working directory is changed
785 TEST_DIRECTORY
="$(cd "$TEST_DIRECTORY" && pwd)" ||
exit 1
787 if test -z "$TEST_OUTPUT_DIRECTORY"
789 # Similarly, override this to store the test-results subdir
791 TEST_OUTPUT_DIRECTORY
="$TEST_DIRECTORY"
793 [ -d "$TESTLIB_DIRECTORY"/empty
] ||
{
794 mkdir
"$TESTLIB_DIRECTORY/empty" ||
:
795 chmod a-w
"$TESTLIB_DIRECTORY/empty" ||
:
796 test -d "$TESTLIB_DIRECTORY"/empty ||
797 fatal
"error: could not make empty directory: '$TESTLIB_DIRECTORY/empty'"
799 EMPTY_DIRECTORY
="$TESTLIB_DIRECTORY/empty"
800 export TEST_DIRECTORY TEST_OUTPUT_DIRECTORY EMPTY_DIRECTORY
802 ################################################################
803 # It appears that people try to run tests with missing perl or git...
804 git_version
="$("$GIT_PATH" --version 2>&1)" ||
805 fatal
'error: you do not seem to have git available?'
806 case "$git_version" in [Gg
][Ii
][Tt
]\
[Vv
][Ee
][Rr
][Ss
][Ii
][Oo
][Nn
]\
[0-9]*);;*)
807 fatal
"error: git --version returned bogus value: $git_version"
809 #"$PERL_PATH" --version >/dev/null 2>&1 ||
810 # fatal 'error: you do not seem to have perl available?'
812 test_lib_main_init_tee
"$@"
814 # For repeatability, reset the environment to known value.
815 # TERM is sanitized below, after saving color control sequences.
820 export LANG LC_ALL PAGER TZ
822 # A call to "unset" with no arguments causes at least Solaris 10
823 # /usr/xpg4/bin/sh and /bin/ksh to bail out. So keep the unsets
824 # deriving from the command substitution clustered with the other
826 unset VISUAL EMAIL LANGUAGE COLUMNS $
("$PERL_PATH" -e '
828 my $ok = join("|", qw(
842 my @vars = grep(/^GIT_/ && !/^GIT_($ok)/o, @env);
843 print join("\n", @vars);
845 unset XDG_CONFIG_HOME
847 GIT_AUTHOR_NAME
='Te s t'
848 GIT_AUTHOR_EMAIL
=test@example.net
849 GIT_COMMITTER_NAME
='Fra mewor k'
850 GIT_COMMITTER_EMAIL
=framework@example.org
851 GIT_MERGE_VERBOSITY
=5
852 GIT_MERGE_AUTOEDIT
=no
853 GIT_TEMPLATE_DIR
="$EMPTY_DIRECTORY"
854 GIT_CONFIG_NOSYSTEM
=1
856 export PATH GIT_TEMPLATE_DIR GIT_CONFIG_NOSYSTEM GIT_ATTR_NOSYSTEM
857 export GIT_MERGE_VERBOSITY GIT_MERGE_AUTOEDIT
858 export GIT_AUTHOR_EMAIL GIT_AUTHOR_NAME
859 export GIT_COMMITTER_EMAIL GIT_COMMITTER_NAME
862 # Tests using GIT_TRACE typically don't want <timestamp> <file>:<line> output
864 export GIT_TRACE_BARE
866 # Protect ourselves from common misconfiguration to export
867 # CDPATH into the environment
873 case "$GIT_TRACE" in 1|
2|
[Tt
][Rr
][Uu
][Ee
])
880 # A regexp to match 5 and 40 hexdigits
881 _x05
='[0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f]'
882 _x40
="$_x05$_x05$_x05$_x05$_x05$_x05$_x05$_x05"
885 _z40
=0000000000000000000000000000000000000000
887 EMPTY_TREE
=4b825dc642cb6eb9a060e54bf8d69288fbee4904
888 EMPTY_BLOB
=e69de29bb2d1d6434b8b29ae775ad8c2e48c5391
894 # UTF-8 ZERO WIDTH NON-JOINER, which HFS+ ignores
895 # when case-folding filenames
896 u200c
="$(printf '\342\200\214')"
898 export _x05 _x40 _z40 LF u200c EMPTY_TREE EMPTY_BLOB
900 while test "$#" -ne 0
903 -d|
--d|
--de|
--deb|
--debu|
--debug)
905 -i|
--i|
--im|
--imm|
--imme|
--immed|
--immedi|
--immedia|
--immediat|
--immediate)
906 immediate
=t
; shift ;;
907 -l|
--l|
--lo|
--lon|
--long|
--long-|
--long-t|
--long-te|
--long-tes|
--long-test|
--long-tests|\
908 --ex|
--exp|
--expe|
--expen|
--expens|
--expensi|
--expensiv|
--expensive)
909 TESTLIB_TEST_LONG
=t
; export TESTLIB_TEST_LONG
; shift ;;
911 shift; test "$#" -ne 0 ||
{
912 echo 'error: -r requires an argument' >&2;
915 run_list
=$1; shift ;;
917 run_list
=${1#--*=}; shift ;;
918 -h|
--h|
--he|
--hel|
--help)
920 -v|
--v|
--ve|
--ver|
--verb|
--verbo|
--verbos|
--verbose)
923 verbose_only
=${1#--*=}
925 -q|
--q|
--qu|
--qui|
--quie|
--quiet)
932 shift ;; # was handled already
937 TESTLIB_TEST_CHAIN_LINT
=1
940 TESTLIB_TEST_CHAIN_LINT
=0
942 -x|
--x|
--xt|
--xtr|
--xtra|
--xtrac|
--xtrace)
950 echo "error: unknown test option '$1'" >&2; exit 1 ;;
954 test "x${color+set}" != "xset" &&
955 test "x$TERM" != "xdumb" && (
956 { test -n "$TESTLIB_FORCETTY" ||
test -t 1; } &&
957 tput bold
>/dev
/null
2>&1 &&
958 tput setaf
1 >/dev
/null
2>&1 &&
959 tput sgr0
>/dev
/null
2>&1
964 # Save the color control sequences now rather than run tput
965 # each time say_color() is called. This is done for two
967 # * TERM will be changed to dumb
968 # * HOME will be changed to a temporary directory and tput
969 # might need to read ~/.terminfo from the original HOME
970 # directory to get the control sequences
971 getcmd say_color_error
eval 'tput setaf 1' # red
972 getcmd say_color_skip
eval 'tput bold; tput setaf 5' # bold blue
973 getcmd say_color_warn
eval 'tput setaf 3' # brown/yellow
974 getcmd say_color_pass
eval 'tput setaf 2' # green
975 getcmd say_color_info
eval 'tput setaf 6' # cyan
976 getcmd say_color_reset
eval 'tput sgr0'
977 say_color_
="" # no formatting for normal text
983 # Send any "-x" output directly to stderr to avoid polluting tests
984 # which capture stderr. We can do this unconditionally since it
985 # has no effect if tracing isn't turned on.
987 # Note that this sets up the trace fd as soon as we assign the variable, so it
988 # must come after the creation of descriptor 4 above. Likewise, we must never
989 # unset this, as it has the side effect of closing descriptor 4, which we
990 # use to show verbose tests to the user.
992 # Note also that we don't need or want to export it. The tracing is local to
993 # this shell, and we would not want to influence any shells we exec.
1002 test_external_has_tap
=0
1004 # The user-facing functions are loaded from a separate file
1005 .
"$TESTLIB_DIRECTORY/test-lib-functions.sh"
1006 test_lib_functions_init
1010 if [ -n "$TG_TEST_INSTALLED" ]; then
1011 [ -n "$(cmd_path tg || :)" ] ||
1012 fatal
'error: TG_TEST_INSTALLED set but no tg found in $PATH!'
1014 tg_bin_dir
="$(cd "$TESTLIB_DIRECTORY/..
/bin-wrappers
" 2>/dev/null && pwd -P || :)"
1015 [ -x "$tg_bin_dir/tg" ] ||
1016 fatal
'error: no ../bin-wrappers/tg executable found!'
1017 PATH
="$tg_bin_dir:$PATH"
1019 tg_version
="$(tg --version)" ||
1020 fatal
'error: tg --version failed!'
1021 case "$tg_version" in [Tt
][Oo
][Pp
][Gg
][Ii
][Tt
]\
[Vv
][Ee
][Rr
][Ss
][Ii
][Oo
][Nn
]\
[0-9]*);;*)
1022 fatal
"error: tg --version returned bogus value: $tg_version"
1025 vcmp
"$git_version" '>=' "$GIT_MINIMUM_VERSION" ||
1026 fatal
"git version >= $GIT_MINIMUM_VERSION required but found \"$git_version\" instead"
1028 if test -z "$TESTLIB_TEST_CMP"
1030 if test -n "$TESTLIB_TEST_CMP_USE_COPIED_CONTEXT"
1032 TESTLIB_TEST_CMP
="$DIFF -c"
1034 TESTLIB_TEST_CMP
="$DIFF -u"
1038 # Fix some commands on Windows
1039 case "${UNAME_S:=$(uname -s)}" in
1041 # no POSIX permissions
1042 # backslashes in pathspec are converted to '/'
1043 # exec does not inherit the PID
1044 test_set_prereq MINGW
1045 test_set_prereq NATIVE_CRLF
1046 test_set_prereq SED_STRIPS_CR
1047 test_set_prereq GREP_STRIPS_CR
1048 TESTLIB_TEST_CMP
=mingw_test_cmp
1051 test_set_prereq POSIXPERM
1052 test_set_prereq EXECKEEPSPID
1053 test_set_prereq CYGWIN
1054 test_set_prereq SED_STRIPS_CR
1055 test_set_prereq GREP_STRIPS_CR
1058 test_set_prereq POSIXPERM
1059 test_set_prereq BSLASHPSPEC
1060 test_set_prereq EXECKEEPSPID
1064 ( COLUMNS
=1 && test $COLUMNS = 1 ) && test_set_prereq COLUMNS_CAN_BE_1
1066 test_lib_main_init_funcs
1068 test_lazy_prereq PIPE
'
1069 # test whether the filesystem supports FIFOs
1070 case "${UNAME_S:=$(uname -s)}" in
1075 rm -f testfifo && mkfifo testfifo
1080 test_lazy_prereq SYMLINKS
'
1081 # test whether the filesystem supports symbolic links
1082 ln -s x y && test -h y
1085 test_lazy_prereq FILEMODE
'
1086 test "$(git config --bool core.filemode)" = true
1089 test_lazy_prereq CASE_INSENSITIVE_FS
'
1090 echo good >CamelCase &&
1091 echo bad >camelcase &&
1092 test "$(cat CamelCase)" != good
1095 test_lazy_prereq UTF8_NFD_TO_NFC
'
1096 # check whether FS converts nfd unicode to nfc
1097 auml="$(printf "\303\244")"
1098 aumlcdiar="$(printf "\141\314\210")"
1108 test_lazy_prereq AUTOIDENT
'
1109 sane_unset GIT_AUTHOR_NAME &&
1110 sane_unset GIT_AUTHOR_EMAIL &&
1111 git var GIT_AUTHOR_IDENT
1114 test_lazy_prereq EXPENSIVE
'
1115 test -n "$TESTLIB_TEST_LONG"
1118 test_lazy_prereq USR_BIN_TIME
'
1119 test -x /usr/bin/time
1122 test_lazy_prereq NOT_ROOT
'
1127 # SANITY is about "can you correctly predict what the filesystem would
1128 # do by only looking at the permission bits of the files and
1129 # directories?" A typical example of !SANITY is running the test
1130 # suite as root, where a test may expect "chmod -r file && cat file"
1131 # to fail because file is supposed to be unreadable after a successful
1132 # chmod. In an environment (i.e. combination of what filesystem is
1133 # being used and who is running the tests) that lacks SANITY, you may
1134 # be able to delete or create a file when the containing directory
1135 # doesn't have write permissions, or access a file even if the
1136 # containing directory doesn't have read or execute permissions.
1138 test_lazy_prereq SANITY
'
1139 mkdir SANETESTD.1 SANETESTD.2 &&
1141 chmod +w SANETESTD.1 SANETESTD.2 &&
1142 >SANETESTD.1/x 2>SANETESTD.2/x &&
1143 chmod -w SANETESTD.1 &&
1144 chmod -r SANETESTD.1/x &&
1145 chmod -rx SANETESTD.2 ||
1146 error "bug in test sript: cannot prepare SANETESTD"
1148 ! test -r SANETESTD.1/x &&
1149 ! rm SANETESTD.1/x && ! test -f SANETESTD.2/x
1152 chmod +rwx SANETESTD.1 SANETESTD.2 &&
1153 rm -rf SANETESTD.1 SANETESTD.2 ||
1154 error "bug in test sript: cannot clean SANETESTD"
1158 test_lazy_prereq CMDLINE_LIMIT
'run_with_limited_cmdline true'
1161 # End test_lib_main_init_generic
1165 # This function is guaranteed to always be called for every single test.
1166 # Only put things in this function that MUST be done per-test, function
1167 # definitions and sourcing other files generally DO NOT QUALIFY (there can
1169 test_lib_main_init_specific
() {
1170 # Begin test_lib_main_init_specific
1173 # original stdin is on 6, stdout on 5 and stderr on 7
1176 test_lib_main_init_funcs
1178 if test -n "$HARNESS_ACTIVE"
1180 if test "$verbose" = t ||
test -n "$verbose_only" && test -z "$TESTLIB_OVERRIDE"
1182 printf 'Bail out! %s\n' \
1183 'verbose mode forbidden under TAP harness; try --verbose-log'
1188 test "${test_description}" != "" ||
1189 error
"Test script did not set test_description."
1191 if test "$help" = "t"
1193 printf '%s\n' "$(printf '%s\n' "$test_description")" |
1208 if test "$verbose_log" = "t"
1210 exec 3>>"$TESTLIB_TEST_TEE_OUTPUT_FILE" 4>&3
1211 elif test "$verbose" = "t"
1215 exec 4>/dev
/null
3>/dev
/null
1220 trap 'exit $?' HUP INT QUIT ABRT PIPE TERM
1221 trap 'TESTLIB_EXIT_OK=t; exit 1' USR1
1224 TRASH_DIRECTORY
="trash directory.${0##*/}"
1225 TRASH_DIRECTORY
="${TRASH_DIRECTORY%.sh}"
1226 test -n "$root" && TRASH_DIRECTORY
="$root/$TRASH_DIRECTORY"
1227 case "$TRASH_DIRECTORY" in
1228 /*) ;; # absolute path is good
1229 *) TRASH_DIRECTORY
="$TEST_OUTPUT_DIRECTORY/$TRASH_DIRECTORY" ;;
1231 test ! -z "$debug" || remove_trash
=$TRASH_DIRECTORY
1232 ! test -e "$TRASH_DIRECTORY" ||
{
1233 rm -rf "$TRASH_DIRECTORY" &&
1234 ! test -e "$TRASH_DIRECTORY" ||
{
1235 chmod -R u
+w
"$TRASH_DIRECTORY" &&
1236 rm -rf "$TRASH_DIRECTORY" &&
1237 ! test -e "$TRASH_DIRECTORY"
1241 echo >&5 "FATAL: Cannot prepare test area"
1245 HOME
="$TRASH_DIRECTORY"
1246 GNUPGHOME
="$HOME/gnupg-home-not-used"
1247 export HOME GNUPGHOME
1249 if test -z "$TEST_NO_CREATE_REPO"
1251 test_create_repo
"$TRASH_DIRECTORY"
1253 mkdir
-p "$TRASH_DIRECTORY"
1255 # Use -P to resolve symlinks in our working directory so that the cwd
1256 # in subprocesses like tg equals our $PWD (for pathname comparisons).
1257 cd -P "$TRASH_DIRECTORY" ||
exit 1
1260 this_test
=${this_test%%-*}
1261 if match_pattern_list
"$this_test" $TESTLIB_SKIP_TESTS
1263 say_color info
>&3 "skipping test $this_test altogether"
1264 skip_all
="skip all tests in $this_test"
1269 # End test_lib_main_init_specific
1274 # THIS SHOULD ALWAYS BE THE LAST FUNCTION DEFINED IN THIS FILE
1276 # Any client that sources this file should immediately execute this function
1277 # afterwards with the command line arguments
1279 # THERE SHOULD NOT BE ANY DIRECTLY EXECUTED LINES OF CODE IN THIS FILE
1281 test_lib_main_init
() {
1283 test_lib_main_init_generic
"$@"
1284 test_lib_main_init_specific
"$@"