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
This commit is contained in:
Junio C Hamano 2021-10-29 15:43:12 -07:00
commit 8ba651b56e

View File

@ -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