Skip to content

Commit 234383c

Browse files
avargitster
authored andcommitted
test-lib.sh: use "Bail out!" syntax on bad SANITIZE=leak use
Improve the "GIT_TEST_PASSING_SANITIZE_LEAK=true" test mode added in 956d2e4 (tests: add a test mode for SANITIZE=leak, run it in CI, 2021-09-23) to use a TAP "Bail out!" message when exiting. This will cause the test run to exit immediately under a TAP consumer like "prove(1)". See 614fe01 (test-lib: bail out when "-v" used under "prove", 2016-10-22) for the initial introduction of "Bail out!" to the --verbose being amended here. Before this compiling with "SANITIZE=" and running the tests with "prove(1)" would cause all the tests to be run to the end (output trimmed for fewer columns): $ GIT_TEST_PASSING_SANITIZE_LEAK=true make rm -f -r 'test-results' *** prove *** t0000-basic.sh ......... Dubious, test returned 1 (wstat 256, 0x100) No subtests run t0001-init.sh .......... Dubious, test returned 1 (wstat 256, 0x100) No subtests run [...output where we list every single t[0-9]*.sh file as failing snipped] Whereas now we'll fail early, like this ("->" line wrapping added): $ GIT_TEST_PASSING_SANITIZE_LEAK=true make [...] t0000-basic.sh ..................................... Bailout called. Further testing stopped: -> GIT_TEST_PASSING_SANITIZE_LEAK=true has no effect except when compiled with SANITIZE=leak FAILED--Further testing stopped: GIT_TEST_PASSING_SANITIZE_LEAK=true has no effect except -> when compiled with SANITIZE=leak make: *** [Makefile:53: prove] Error 1 This change also adds a red color to the "Bailout called" line, as we're now using "say_color error". That improves existing output in the case of e.g.: $ prove -j8 t[0-9]*.sh :: -v Bailout called. Further testing stopped: verbose mode forbidden under TAP harness; try --verbose-log FAILED--Further testing stopped: verbose mode forbidden under TAP harness; try --verbose-log We don't need to have a "Bail out! " prefix when we're not running under a TAP consumer (i.e. if test -n "$HARNESS_ACTIVE"), but let's not make the output conditional on that. Showing it under e.g.: $ GIT_TEST_PASSING_SANITIZE_LEAK=true ./t0095-bloom.sh Bail out! GIT_TEST_PASSING_SANITIZE_LEAK=true has no effect except when compiled with SANITIZE=leak Doesn't harm anything, and I don't think the (small) complexity of only adding this if we're under "$HARNESS_ACTIVE" is worth it. Signed-off-by: Ævar Arnfjörð Bjarmason <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 8583bf7 commit 234383c

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

t/test-lib.sh

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -604,6 +604,18 @@ BUG () {
604604
error >&7 "bug in the test script: $*"
605605
}
606606

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+
607619
say () {
608620
say_color info "$*"
609621
}
@@ -612,9 +624,7 @@ if test -n "$HARNESS_ACTIVE"
612624
then
613625
if test "$verbose" = t || test -n "$verbose_only"
614626
then
615-
printf 'Bail out! %s\n' \
616-
'verbose mode forbidden under TAP harness; try --verbose-log'
617-
exit 1
627+
BAIL_OUT 'verbose mode forbidden under TAP harness; try --verbose-log'
618628
fi
619629
fi
620630

@@ -1402,7 +1412,7 @@ then
14021412
fi
14031413
elif test_bool_env GIT_TEST_PASSING_SANITIZE_LEAK false
14041414
then
1405-
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"
14061416
fi
14071417

14081418
# Last-minute variable setup

0 commit comments

Comments
 (0)