Skip to content

Commit 8ba651b

Browse files
committed
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
2 parents 23112fc + 234383c commit 8ba651b

File tree

1 file changed

+21
-7
lines changed

1 file changed

+21
-7
lines changed

t/test-lib.sh

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -589,17 +589,33 @@ USER_TERM="$TERM"
589589
TERM=dumb
590590
export TERM USER_TERM
591591

592-
error () {
593-
say_color error "error: $*"
592+
_error_exit () {
594593
finalize_junit_xml
595594
GIT_EXIT_OK=t
596595
exit 1
597596
}
598597

598+
error () {
599+
say_color error "error: $*"
600+
_error_exit
601+
}
602+
599603
BUG () {
600604
error >&7 "bug in the test script: $*"
601605
}
602606

607+
BAIL_OUT () {
608+
test $# -ne 1 && BUG "1 param"
609+
610+
# Do not change "Bail out! " string. It's part of TAP syntax:
611+
# https://testanything.org/tap-specification.html
612+
local bail_out="Bail out! "
613+
local message="$1"
614+
615+
say_color error $bail_out "$message"
616+
_error_exit
617+
}
618+
603619
say () {
604620
say_color info "$*"
605621
}
@@ -608,9 +624,7 @@ if test -n "$HARNESS_ACTIVE"
608624
then
609625
if test "$verbose" = t || test -n "$verbose_only"
610626
then
611-
printf 'Bail out! %s\n' \
612-
'verbose mode forbidden under TAP harness; try --verbose-log'
613-
exit 1
627+
BAIL_OUT 'verbose mode forbidden under TAP harness; try --verbose-log'
614628
fi
615629
fi
616630

@@ -720,7 +734,7 @@ test_failure_ () {
720734
say_color error "not ok $test_count - $1"
721735
shift
722736
printf '%s\n' "$*" | sed -e 's/^/# /'
723-
test "$immediate" = "" || { finalize_junit_xml; GIT_EXIT_OK=t; exit 1; }
737+
test "$immediate" = "" || _error_exit
724738
}
725739

726740
test_known_broken_ok_ () {
@@ -1398,7 +1412,7 @@ then
13981412
fi
13991413
elif test_bool_env GIT_TEST_PASSING_SANITIZE_LEAK false
14001414
then
1401-
error "GIT_TEST_PASSING_SANITIZE_LEAK=true has no effect except when compiled with SANITIZE=leak"
1415+
BAIL_OUT "GIT_TEST_PASSING_SANITIZE_LEAK=true has no effect except when compiled with SANITIZE=leak"
14021416
fi
14031417

14041418
# Last-minute variable setup

0 commit comments

Comments
 (0)