diff options
author | Junio C Hamano <gitster@pobox.com> | 2021-10-29 15:43:12 -0700 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2021-10-29 15:43:12 -0700 |
commit | 8ba651b56e5916d864b2a5c4cce8d4e445b87e17 (patch) | |
tree | 19101c5fbbe9ea722015f445e5ec8bcf15777098 /t | |
parent | Merge branch 'ab/make-sparse-for-real' (diff) | |
parent | test-lib.sh: use "Bail out!" syntax on bad SANITIZE=leak use (diff) | |
download | tgif-8ba651b56e5916d864b2a5c4cce8d4e445b87e17.tar.xz |
Merge branch 'ab/test-bail'
A new feature has been added to abort early in the test framework.
* ab/test-bail:
test-lib.sh: use "Bail out!" syntax on bad SANITIZE=leak use
test-lib.sh: de-duplicate error() teardown code
Diffstat (limited to 't')
-rw-r--r-- | t/test-lib.sh | 28 |
1 files changed, 21 insertions, 7 deletions
diff --git a/t/test-lib.sh b/t/test-lib.sh index a291a5d4a2..2679a7596a 100644 --- a/t/test-lib.sh +++ b/t/test-lib.sh @@ -589,17 +589,33 @@ USER_TERM="$TERM" TERM=dumb export TERM USER_TERM -error () { - say_color error "error: $*" +_error_exit () { finalize_junit_xml GIT_EXIT_OK=t exit 1 } +error () { + say_color error "error: $*" + _error_exit +} + BUG () { error >&7 "bug in the test script: $*" } +BAIL_OUT () { + test $# -ne 1 && BUG "1 param" + + # Do not change "Bail out! " string. It's part of TAP syntax: + # https://testanything.org/tap-specification.html + local bail_out="Bail out! " + local message="$1" + + say_color error $bail_out "$message" + _error_exit +} + say () { say_color info "$*" } @@ -608,9 +624,7 @@ if test -n "$HARNESS_ACTIVE" then if test "$verbose" = t || test -n "$verbose_only" then - printf 'Bail out! %s\n' \ - 'verbose mode forbidden under TAP harness; try --verbose-log' - exit 1 + BAIL_OUT 'verbose mode forbidden under TAP harness; try --verbose-log' fi fi @@ -720,7 +734,7 @@ test_failure_ () { say_color error "not ok $test_count - $1" shift printf '%s\n' "$*" | sed -e 's/^/# /' - test "$immediate" = "" || { finalize_junit_xml; GIT_EXIT_OK=t; exit 1; } + test "$immediate" = "" || _error_exit } test_known_broken_ok_ () { @@ -1398,7 +1412,7 @@ then fi elif test_bool_env GIT_TEST_PASSING_SANITIZE_LEAK false then - error "GIT_TEST_PASSING_SANITIZE_LEAK=true has no effect except when compiled with SANITIZE=leak" + BAIL_OUT "GIT_TEST_PASSING_SANITIZE_LEAK=true has no effect except when compiled with SANITIZE=leak" fi # Last-minute variable setup |