1 # Test framework from Git with modifications.
3 # Modifications Copyright (C) 2016 Kyle J. McKay
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_my_dir, vcmp, test_possibly_broken_ok_ and
15 # 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
55 # determine script's location and name
57 while [ -L "$myname" ]; do
59 myname
="$(readlink "$myname")"
60 case "$myname" in /*) :;; *)
61 myname
="$(dirname "$oldname")/$myname"
64 mydir
="$(cd "$
(dirname "$myname")" && pwd -P)"
65 printf '%s\n' "$mydir"
69 # Compare $1 to $2 each of which must match \d+(\.\d+)*
70 # An empty string ('') for $1 or $2 is treated like 0
75 # Note that $(vcmp 1.8 1.8.0.0.0.0) correctly outputs 0.
79 [ -n "$_a" -o -n "$_b" ]
81 if [ "${_a:-0}" -lt "${_b:-0}" ]; then
84 elif [ "${_a:-0}" -gt "${_b:-0}" ]; then
90 set -- "${_a2#.}" "${_b2#.}"
96 say_color error
"error: $*"
107 if test -n "$TESTLIB_EXIT_OK"
111 echo >&5 "FATAL: Unexpected exit with code $code"
116 # You are not expected to call test_ok_ and test_failure_ directly, use
117 # the test_expect_* functions instead.
120 test_success
=$
(($test_success + 1))
121 say_color
"" "ok $test_count - $@"
125 test_failure
=$
(($test_failure + 1))
126 say_color error
"not ok $test_count - $1"
128 printf '%s\n' "$*" |
sed -e 's/^/# /'
129 test "$immediate" = "" ||
{ TESTLIB_EXIT_OK
=t
; exit 1; }
132 test_known_broken_ok_
() {
133 test_fixed
=$
(($test_fixed + 1))
134 say_color error
"ok $test_count - $@ # TODO known breakage vanished"
137 test_known_broken_failure_
() {
138 test_broken
=$
(($test_broken + 1))
139 say_color warn
"not ok $test_count - $@ # TODO known breakage"
142 test_possibly_broken_ok_
() {
143 test_success
=$
(($test_success + 1))
144 say_color
"" "ok $test_count - $@"
147 test_possibly_broken_failure_
() {
148 test_broken
=$
(($test_broken + 1))
149 say_color warn
"not ok $test_count - $@ # TODO tolerated breakage"
153 test "$debug" = "" ||
test $# -eq 0 ||
test -z "$*" ||
"$@"
156 match_pattern_list
() {
159 test -z "$*" && return 1
170 match_test_selector_list
() {
175 test -z "$1" && return 0
177 # Both commas and whitespace are accepted as separators.
183 # If the first selector is negative we include by default.
191 orig_selector
=$selector
197 selector
=${selector##?}
201 test -z "$selector" && continue
205 if expr "z${selector%%-*}" : "z[0-9]*[^0-9]" >/dev
/null
207 echo "error: $title: invalid non-numeric in range" \
208 "start: '$orig_selector'" >&2
211 if expr "z${selector#*-}" : "z[0-9]*[^0-9]" >/dev
/null
213 echo "error: $title: invalid non-numeric in range" \
214 "end: '$orig_selector'" >&2
219 if expr "z$selector" : "z[0-9]*[^0-9]" >/dev
/null
221 echo "error: $title: invalid non-numeric in test" \
222 "selector: '$orig_selector'" >&2
227 # Short cut for "obvious" cases
228 test -z "$include" && test -z "$positive" && continue
229 test -n "$include" && test -n "$positive" && continue
233 if test $arg -le ${selector#-}
239 if test $arg -ge ${selector%-}
245 if test ${selector%%-*} -le $arg \
246 && test $arg -le ${selector#*-}
252 if test $arg -eq $selector
263 maybe_teardown_verbose
() {
264 test -z "$verbose_only" && return
265 exec 4>/dev
/null
3>/dev
/null
269 maybe_setup_verbose
() {
270 test -z "$verbose_only" && return
271 if match_pattern_list
$test_count $verbose_only
274 # Emit a delimiting blank line when going from
275 # non-verbose to verbose. Within verbose mode the
276 # delimiter is printed by test_expect_*. The choice
277 # of the initial $last_verbose is such that before
278 # test 1, we do not print it.
279 test -z "$last_verbose" && echo >&3 ""
282 exec 4>/dev
/null
3>/dev
/null
285 last_verbose
=$verbose
289 test "$trace" = t
&& test "$verbose" = t
292 # This is a separate function because some tests use
293 # "return" to end a test_expect_success block early
294 # (and we want to make sure we run any cleanup like
297 # Do not add anything extra (including LF) after '$*'
304 # We run this block with stderr redirected to avoid extra cruft
305 # during a "-x" trace. Once in "set -x" mode, we cannot prevent
306 # the shell from printing the "set +x" to turn it off (nor the saving
307 # of $? before that). But we can make sure that the output goes to
310 # The test itself is run with stderr put back to &4 (so either to
311 # /dev/null, or to the original stderr if --verbose was used).
313 test_eval_inner_
"$@" </dev
/null
>&3 2>&4
318 if test "$test_eval_ret_" != 0
320 say_color error
>&4 "error: last command exited with \$?=$test_eval_ret_"
324 return $test_eval_ret_
331 if test "${TESTLIB_TEST_CHAIN_LINT:-1}" != 0; then
332 # turn off tracing for this test-eval, as it simply creates
333 # confusing noise in the "-x" output
336 # 117 is magic because it is unlikely to match the exit
337 # code of other programs
338 test_eval_
"(exit 117) && $1"
339 if test "$?" != 117; then
340 error
"bug in the test script: broken &&-chain: $1"
348 if test -z "$immediate" ||
test $eval_ret = 0 ||
349 test -n "$expecting_failure" && test "${test_cleanup:-:}" != ":"
351 test_eval_
"$test_cleanup"
353 if test "$verbose" = "t" && test -n "$HARNESS_ACTIVE"
361 test_count
=$
(($test_count+1))
367 maybe_teardown_verbose
373 if match_pattern_list
$this_test.
$test_count $TESTLIB_SKIP_TESTS
376 skipped_reason
="TESTLIB_SKIP_TESTS"
378 if test -z "$to_skip" && test -n "$test_prereq" &&
379 ! test_have_prereq
"$test_prereq"
384 if test "$missing_prereq" != "$test_prereq"
386 of_prereq
=" of $test_prereq"
388 skipped_reason
="missing $missing_prereq${of_prereq}"
390 if test -z "$to_skip" && test -n "$run_list" &&
391 ! match_test_selector_list
'--run' $test_count "$run_list"
394 skipped_reason
="--run"
399 say_color skip
>&3 "skipping test: $@"
400 say_color skip
"ok $test_count # skip $1 ($skipped_reason)"
409 # stub; runs at end of each successful test
410 test_at_end_hook_
() {
417 if test -z "$HARNESS_ACTIVE"
419 test_results_dir
="$TEST_OUTPUT_DIRECTORY/test-results"
420 mkdir
-p "$test_results_dir"
422 test_results_path
="$test_results_dir/${base%.sh}.counts"
424 cat >"$test_results_path" <<-EOF
426 success $test_success
434 if test "$test_fixed" != 0
436 say_color error
"# $test_fixed known breakage(s) vanished; please update test(s)"
438 if test "$test_broken" != 0
440 say_color warn
"# still have $test_broken known breakage(s)"
442 if test "$test_broken" != 0 ||
test "$test_fixed" != 0
444 test_remaining
=$
(( $test_count - $test_broken - $test_fixed ))
445 msg
="remaining $test_remaining test(s)"
447 test_remaining
=$test_count
448 msg
="$test_count test(s)"
450 case "$test_failure" in
452 # Maybe print SKIP message
453 if test -n "$skip_all" && test $test_count -gt 0
455 error
"Can't use skip_all after running some tests"
457 test -z "$skip_all" || skip_all
=" # SKIP $skip_all"
459 if test $test_external_has_tap -eq 0
461 if test $test_remaining -gt 0
463 say_color pass
"# passed all $msg"
465 say
"1..$test_count$skip_all"
468 test -d "$remove_trash" &&
469 cd "$(dirname "$remove_trash")" &&
470 rm -rf "$(basename "$remove_trash")"
477 if test $test_external_has_tap -eq 0
479 say_color error
"# failed $test_failure among $msg"
488 # Provide an implementation of the 'yes' utility
505 run_with_limited_cmdline
() {
506 (ulimit -s 128 && "$@")
511 ## Note that the following functions have bodies that are NOT indented
512 ## to assist with readability
516 # This function is called with all the test args and must perform all
517 # initialization that involves variables and is not specific to "$0"
518 # or "$test_description" in any way. This function may only be called
519 # once per run of the entire test suite.
520 test_lib_main_init_generic
() {
521 # Begin test_lib_main_init_generic
524 ! [ -f ..
/TG-BUILD-SETTINGS
] || . ..
/TG-BUILD-SETTINGS
525 ! [ -f TG-TEST-SETTINGS
] || . .
/TG-TEST-SETTINGS
527 : "${SHELL_PATH:=/bin/sh}"
529 : "${GIT_PATH:=$(cmd_path git)}"
530 : "${PERL_PATH:=$(cmd_path perl || :)}"
531 TESTLIB_DIRECTORY
="$(whats_my_dir)"
533 # Test the binaries we have just built. The tests are kept in
534 # t/ subdirectory and are run in 'trash directory' subdirectory.
535 if test -z "$TEST_DIRECTORY"
537 # We allow tests to override this, in case they want to run tests
538 # outside of t/, e.g. for running tests on the test library
540 TEST_DIRECTORY
="$TESTLIB_DIRECTORY"
542 # ensure that TEST_DIRECTORY is an absolute path so that it
543 # is valid even if the current working directory is changed
544 TEST_DIRECTORY
="$(cd "$TEST_DIRECTORY" && pwd)" ||
exit 1
546 if test -z "$TEST_OUTPUT_DIRECTORY"
548 # Similarly, override this to store the test-results subdir
550 TEST_OUTPUT_DIRECTORY
="$TEST_DIRECTORY"
552 [ -d "$TESTLIB_DIRECTORY"/empty
] ||
{
553 mkdir
"$TESTLIB_DIRECTORY/empty"
554 chmod a-w
"$TESTLIB_DIRECTORY/empty"
556 EMPTY_DIRECTORY
="$TESTLIB_DIRECTORY/empty"
558 ################################################################
559 # It appears that people try to run tests with missing perl or git...
560 git_version
="$("$GIT_PATH" --version 2>&1)" ||
561 fatal
'error: you do not seem to have git available?'
562 case "$git_version" in [Gg
][Ii
][Tt
]\
[Vv
][Ee
][Rr
][Ss
][Ii
][Oo
][Nn
]\
[0-9]*) :;; *)
563 fatal
"error: git --version returned bogus value: $git_version"
565 #"$PERL_PATH" --version >/dev/null 2>&1 ||
566 # fatal 'error: you do not seem to have perl available?'
568 # if --tee was passed, write the output not only to the terminal, but
569 # additionally to the file test-results/$BASENAME.out, too.
570 case "$TESTLIB_TEST_TEE_STARTED, $* " in
572 # do not redirect again
574 *' --tee '*|
*' --verbose-log '*)
575 mkdir
-p "$TEST_OUTPUT_DIRECTORY/test-results"
576 BASE
="$TEST_OUTPUT_DIRECTORY/test-results/$(basename "$0" .sh)"
578 # Make this filename available to the sub-process in case it is using
580 TESTLIB_TEST_TEE_OUTPUT_FILE
=$BASE.out
581 export TESTLIB_TEST_TEE_OUTPUT_FILE
583 # Truncate before calling "tee -a" to get rid of the results
584 # from any previous runs.
585 >"$TESTLIB_TEST_TEE_OUTPUT_FILE"
587 (TESTLIB_TEST_TEE_STARTED
=done ${SHELL_PATH} "$0" "$@" 2>&1;
588 echo $?
>"$BASE.exit") |
tee -a "$TESTLIB_TEST_TEE_OUTPUT_FILE"
589 test "$(cat "$BASE.
exit")" = 0
594 # For repeatability, reset the environment to known value.
595 # TERM is sanitized below, after saving color control sequences.
600 export LANG LC_ALL PAGER TZ
602 # A call to "unset" with no arguments causes at least Solaris 10
603 # /usr/xpg4/bin/sh and /bin/ksh to bail out. So keep the unsets
604 # deriving from the command substitution clustered with the other
606 unset VISUAL EMAIL LANGUAGE COLUMNS $
("$PERL_PATH" -e '
608 my $ok = join("|", qw(
622 my @vars = grep(/^GIT_/ && !/^GIT_($ok)/o, @env);
623 print join("\n", @vars);
625 unset XDG_CONFIG_HOME
627 GIT_AUTHOR_NAME
='Te s t'
628 GIT_AUTHOR_EMAIL
=test@example.net
629 GIT_COMMITTER_NAME
='Fra mewor k'
630 GIT_COMMITTER_EMAIL
=framework@example.org
631 GIT_MERGE_VERBOSITY
=5
632 GIT_MERGE_AUTOEDIT
=no
633 GIT_TEMPLATE_DIR
="$EMPTY_DIRECTORY"
634 GIT_CONFIG_NOSYSTEM
=1
636 export PATH GIT_TEMPLATE_DIR GIT_CONFIG_NOSYSTEM GIT_ATTR_NOSYSTEM
637 export GIT_MERGE_VERBOSITY GIT_MERGE_AUTOEDIT
638 export GIT_AUTHOR_EMAIL GIT_AUTHOR_NAME
639 export GIT_COMMITTER_EMAIL GIT_COMMITTER_NAME
642 # Tests using GIT_TRACE typically don't want <timestamp> <file>:<line> output
644 export GIT_TRACE_BARE
646 # Protect ourselves from common misconfiguration to export
647 # CDPATH into the environment
653 case $
(echo $GIT_TRACE |
tr "[A-Z]" "[a-z]") in
661 # A regexp to match 5 and 40 hexdigits
662 _x05
='[0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f]'
663 _x40
="$_x05$_x05$_x05$_x05$_x05$_x05$_x05$_x05"
666 _z40
=0000000000000000000000000000000000000000
668 EMPTY_TREE
=4b825dc642cb6eb9a060e54bf8d69288fbee4904
669 EMPTY_BLOB
=e69de29bb2d1d6434b8b29ae775ad8c2e48c5391
675 # UTF-8 ZERO WIDTH NON-JOINER, which HFS+ ignores
676 # when case-folding filenames
677 u200c
=$
(printf '\342\200\214')
679 export _x05 _x40 _z40 LF u200c EMPTY_TREE EMPTY_BLOB
681 test "x$TERM" != "xdumb" && (
682 { test -n "$TESTLIB_FORCETTY" ||
test -t 1; } &&
683 tput bold
>/dev
/null
2>&1 &&
684 tput setaf
1 >/dev
/null
2>&1 &&
685 tput sgr0
>/dev
/null
2>&1
689 while test "$#" -ne 0
692 -d|
--d|
--de|
--deb|
--debu|
--debug)
694 -i|
--i|
--im|
--imm|
--imme|
--immed|
--immedi|
--immedia|
--immediat|
--immediate)
695 immediate
=t
; shift ;;
696 -l|
--l|
--lo|
--lon|
--long|
--long-|
--long-t|
--long-te|
--long-tes|
--long-test|
--long-tests)
697 TESTLIB_TEST_LONG
=t
; export TESTLIB_TEST_LONG
; shift ;;
699 shift; test "$#" -ne 0 ||
{
700 echo 'error: -r requires an argument' >&2;
703 run_list
=$1; shift ;;
705 run_list
=${1#--*=}; shift ;;
706 -h|
--h|
--he|
--hel|
--help)
708 -v|
--v|
--ve|
--ver|
--verb|
--verbo|
--verbos|
--verbose)
711 verbose_only
=${1#--*=}
713 -q|
--q|
--qu|
--qui|
--quie|
--quiet)
714 # Ignore --quiet under a TAP::Harness. Saying how many tests
715 # passed without the ok/not ok details is always an error.
716 test -z "$HARNESS_ACTIVE" && quiet
=t
; shift ;;
720 shift ;; # was handled already
725 TESTLIB_TEST_CHAIN_LINT
=1
728 TESTLIB_TEST_CHAIN_LINT
=0
738 echo "error: unknown test option '$1'" >&2; exit 1 ;;
744 # Save the color control sequences now rather than run tput
745 # each time say_color() is called. This is done for two
747 # * TERM will be changed to dumb
748 # * HOME will be changed to a temporary directory and tput
749 # might need to read ~/.terminfo from the original HOME
750 # directory to get the control sequences
751 # Note: This approach assumes the control sequences don't end
752 # in a newline for any terminal of interest (command
753 # substitutions strip trailing newlines). Given that most
754 # (all?) terminals in common use are related to ECMA-48, this
755 # shouldn't be a problem.
756 say_color_error
=$
(tput bold
; tput setaf
1) # bold red
757 say_color_skip
=$
(tput setaf
4) # blue
758 say_color_warn
=$
(tput setaf
3) # brown/yellow
759 say_color_pass
=$
(tput setaf
2) # green
760 say_color_info
=$
(tput setaf
6) # cyan
761 say_color_reset
=$
(tput sgr0
)
762 say_color_
="" # no formatting for normal text
768 # Send any "-x" output directly to stderr to avoid polluting tests
769 # which capture stderr. We can do this unconditionally since it
770 # has no effect if tracing isn't turned on.
772 # Note that this sets up the trace fd as soon as we assign the variable, so it
773 # must come after the creation of descriptor 4 above. Likewise, we must never
774 # unset this, as it has the side effect of closing descriptor 4, which we
775 # use to show verbose tests to the user.
777 # Note also that we don't need or want to export it. The tracing is local to
778 # this shell, and we would not want to influence any shells we exec.
787 test_external_has_tap
=0
789 # The user-facing functions are loaded from a separate file
790 .
"$TEST_DIRECTORY/test-lib-functions.sh"
791 test_lib_functions_init
795 if [ -n "$TG_TEST_INSTALLED" ]; then
796 [ -n "$(cmd_path tg || :)" ] ||
797 fatal
'error: TG_TEST_INSTALLED set but no tg found in $PATH!'
799 tg_bin_dir
="$(cd "$TESTLIB_DIRECTORY/..
/bin-wrappers
" 2>/dev/null && pwd -P || :)"
800 [ -x "$tg_bin_dir/tg" ] ||
801 fatal
'error: no ../bin-wrappers/tg executable found!'
802 PATH
="$tg_bin_dir:$PATH"
804 tg_version
="$(tg --version)" ||
805 fatal
'error: tg --version failed!'
806 case "$tg_version" in [Tt
][Oo
][Pp
][Gg
][Ii
][Tt
]\
[Vv
][Ee
][Rr
][Ss
][Ii
][Oo
][Nn
]\
[0-9]*) :;; *)
807 fatal
"error: tg --version returned bogus value: $tg_version"
810 if [ -n "$GIT_MINIMUM_VERSION" ] && [ -n "$git_version" ]; then
811 git_vernum
="$(sed -ne '1s/^[^0-9]*\([0-9][0-9]*\(\.[0-9][0-9]*\)*\).*$/\1/p' <<-EOT
815 [ "$(vcmp "$git_vernum" $GIT_MINIMUM_VERSION)" -ge 0 ] ||
816 fatal
"git version >= $GIT_MINIMUM_VERSION required but found git version $git_vernum instead"
819 if test -z "$TESTLIB_TEST_CMP"
821 if test -n "$TESTLIB_TEST_CMP_USE_COPIED_CONTEXT"
823 TESTLIB_TEST_CMP
="$DIFF -c"
825 TESTLIB_TEST_CMP
="$DIFF -u"
829 # Fix some commands on Windows
830 uname_s
="$(uname -s)"
833 # no POSIX permissions
834 # backslashes in pathspec are converted to '/'
835 # exec does not inherit the PID
836 test_set_prereq MINGW
837 test_set_prereq NATIVE_CRLF
838 test_set_prereq SED_STRIPS_CR
839 test_set_prereq GREP_STRIPS_CR
840 TESTLIB_TEST_CMP
=mingw_test_cmp
843 test_set_prereq POSIXPERM
844 test_set_prereq EXECKEEPSPID
845 test_set_prereq CYGWIN
846 test_set_prereq SED_STRIPS_CR
847 test_set_prereq GREP_STRIPS_CR
850 test_set_prereq POSIXPERM
851 test_set_prereq BSLASHPSPEC
852 test_set_prereq EXECKEEPSPID
856 ( COLUMNS
=1 && test $COLUMNS = 1 ) && test_set_prereq COLUMNS_CAN_BE_1
858 test_lazy_prereq PIPE
'
859 # test whether the filesystem supports FIFOs
865 rm -f testfifo && mkfifo testfifo
870 test_lazy_prereq SYMLINKS
'
871 # test whether the filesystem supports symbolic links
872 ln -s x y && test -h y
875 test_lazy_prereq FILEMODE
'
876 test "$(git config --bool core.filemode)" = true
879 test_lazy_prereq CASE_INSENSITIVE_FS
'
880 echo good >CamelCase &&
881 echo bad >camelcase &&
882 test "$(cat CamelCase)" != good
885 test_lazy_prereq UTF8_NFD_TO_NFC
'
886 # check whether FS converts nfd unicode to nfc
887 auml=$(printf "\303\244")
888 aumlcdiar=$(printf "\141\314\210")
898 test_lazy_prereq AUTOIDENT
'
899 sane_unset GIT_AUTHOR_NAME &&
900 sane_unset GIT_AUTHOR_EMAIL &&
901 git var GIT_AUTHOR_IDENT
904 test_lazy_prereq EXPENSIVE
'
905 test -n "$TESTLIB_TEST_LONG"
908 test_lazy_prereq USR_BIN_TIME
'
909 test -x /usr/bin/time
912 test_lazy_prereq NOT_ROOT
'
917 # SANITY is about "can you correctly predict what the filesystem would
918 # do by only looking at the permission bits of the files and
919 # directories?" A typical example of !SANITY is running the test
920 # suite as root, where a test may expect "chmod -r file && cat file"
921 # to fail because file is supposed to be unreadable after a successful
922 # chmod. In an environment (i.e. combination of what filesystem is
923 # being used and who is running the tests) that lacks SANITY, you may
924 # be able to delete or create a file when the containing directory
925 # doesn't have write permissions, or access a file even if the
926 # containing directory doesn't have read or execute permissions.
928 test_lazy_prereq SANITY
'
929 mkdir SANETESTD.1 SANETESTD.2 &&
931 chmod +w SANETESTD.1 SANETESTD.2 &&
932 >SANETESTD.1/x 2>SANETESTD.2/x &&
933 chmod -w SANETESTD.1 &&
934 chmod -r SANETESTD.1/x &&
935 chmod -rx SANETESTD.2 ||
936 error "bug in test sript: cannot prepare SANETESTD"
938 ! test -r SANETESTD.1/x &&
939 ! rm SANETESTD.1/x && ! test -f SANETESTD.2/x
942 chmod +rwx SANETESTD.1 SANETESTD.2 &&
943 rm -rf SANETESTD.1 SANETESTD.2 ||
944 error "bug in test sript: cannot clean SANETESTD"
948 test_lazy_prereq CMDLINE_LIMIT
'run_with_limited_cmdline true'
951 # End test_lib_main_init_generic
955 # This function is guaranteed to always be called for every single test.
956 # Only put things in this function that MUST be done per-test, function
957 # definitions and sourcing other files generally DO NOT QUALIFY (there can
959 test_lib_main_init_specific
() {
960 # Begin test_lib_main_init_specific
963 # Ignore --quiet under a TAP::Harness. Saying how many tests
964 # passed without the ok/not ok details is always an error.
965 test -n "$HARNESS_ACTIVE" && unset quiet
970 test -z "$1" && test -n "$quiet" && return
971 eval "say_color_color=\$say_color_$1"
973 printf "%s\\n" "$say_color_color$*$say_color_reset"
977 test -z "$1" && test -n "$quiet" && return
983 if test -n "$HARNESS_ACTIVE"
985 if test "$verbose" = t ||
test -n "$verbose_only"
987 printf 'Bail out! %s\n' \
988 'verbose mode forbidden under TAP harness; try --verbose-log'
993 test "${test_description}" != "" ||
994 error
"Test script did not set test_description."
996 if test "$help" = "t"
998 printf '%s\n' "$test_description"
1004 if test "$verbose_log" = "t"
1006 exec 3>>"$TESTLIB_TEST_TEE_OUTPUT_FILE" 4>&3
1007 elif test "$verbose" = "t"
1011 exec 4>/dev
/null
3>/dev
/null
1016 trap 'exit $?' HUP INT QUIT ABRT PIPE TERM
1019 TRASH_DIRECTORY
="trash directory.$(basename "$0" .sh)"
1020 test -n "$root" && TRASH_DIRECTORY
="$root/$TRASH_DIRECTORY"
1021 case "$TRASH_DIRECTORY" in
1022 /*) ;; # absolute path is good
1023 *) TRASH_DIRECTORY
="$TEST_OUTPUT_DIRECTORY/$TRASH_DIRECTORY" ;;
1025 test ! -z "$debug" || remove_trash
=$TRASH_DIRECTORY
1026 ! [ -e "$TRASH_DIRECTORY" ] ||
rm -fr "$TRASH_DIRECTORY" ||
{
1028 echo >&5 "FATAL: Cannot prepare test area"
1032 HOME
="$TRASH_DIRECTORY"
1033 GNUPGHOME
="$HOME/gnupg-home-not-used"
1034 export HOME GNUPGHOME
1036 if test -z "$TEST_NO_CREATE_REPO"
1038 test_create_repo
"$TRASH_DIRECTORY"
1040 mkdir
-p "$TRASH_DIRECTORY"
1042 # Use -P to resolve symlinks in our working directory so that the cwd
1043 # in subprocesses like tg equals our $PWD (for pathname comparisons).
1044 cd -P "$TRASH_DIRECTORY" ||
exit 1
1047 this_test
=${this_test%%-*}
1048 if match_pattern_list
"$this_test" $TESTLIB_SKIP_TESTS
1050 say_color info
>&3 "skipping test $this_test altogether"
1051 skip_all
="skip all tests in $this_test"
1055 # Fix some commands on Windows
1058 # Windows has its own (incompatible) sort and find
1068 # git sees Windows-style pwd
1076 # End test_lib_main_init_specific
1081 # THIS SHOULD ALWAYS BE THE LAST FUNCTION DEFINED IN THIS FILE
1083 # Any client that sources this file should immediately execute this function
1084 # afterwards with the command line arguments
1086 # THERE SHOULD NOT BE ANY DIRECTLY EXECUTED LINES OF CODE IN THIS FILE
1088 test_lib_main_init
() {
1090 test_lib_main_init_generic
"$@"
1091 test_lib_main_init_specific
"$@"