test-lib: fix GIT_EXIT_OK logic errors, use BAIL_OUT

Change various "exit 1" checks that happened after our "die" handler had been set up to use BAIL_OUT instead. See 234383cd401 (test-lib.sh: use "Bail out!" syntax on bad SANITIZE=leak use, 2021-10-14) for the benefits of the BAIL_OUT function. The previous use of "error" here was not a logic error, but the "exit" without "GIT_EXIT_OK" would emit the "FATAL: Unexpected exit with code $code" message on top of the error we wanted to emit. Since we'd also like to stop "prove" in its tracks here, the right thing to do is to emit a "Bail out!" message. Let's also move the "GIT_EXIT_OK=t" assignments to just above the "exit [01]" in "test_done". It's not OK if we exit in e.g. finalize_test_output. Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Ævar Arnfjörð Bjarmason committed Jul 28, 2022 at 01:13 UTC 25c2351d85bf19cfd0b19e2de8468c3604897dcf
1 file changed +6 -10
t/test-lib.sh
+6 -10
@@ -1173,8 +1173,6 @@ test_done () {
1173 # removed, so the commands can access pidfiles and socket files.
1174 test_atexit_handler
1175
1176 - GIT_EXIT_OK=t
1177 -
1176 finalize_test_output
1177
1178 if test -z "$HARNESS_ACTIVE"
@@ -1246,6 +1244,7 @@ test_done () {
1244 fi
1245 test_at_end_hook_
1246
1247 + GIT_EXIT_OK=t
1248 exit 0 ;;
1249
1250 *)
@@ -1255,6 +1254,7 @@ test_done () {
1254 say "1..$test_count"
1255 fi
1256
1257 + GIT_EXIT_OK=t
1258 exit 1 ;;
1259
1260 esac
@@ -1387,14 +1387,12 @@ fi
1387 GITPERLLIB="$GIT_BUILD_DIR"/perl/build/lib
1388 export GITPERLLIB
1389 test -d "$GIT_BUILD_DIR"/templates/blt || {
1390 - error "You haven't built things yet, have you?"
1390 + BAIL_OUT "You haven't built things yet, have you?"
1391 }
1392
1393 if ! test -x "$GIT_BUILD_DIR"/t/helper/test-tool$X
1394 then
1395 - echo >&2 'You need to build test-tool:'
1396 - echo >&2 'Run "make t/helper/test-tool" in the source (toplevel) directory'
1397 - exit 1
1395 + BAIL_OUT 'You need to build test-tool; Run "make t/helper/test-tool" in the source (toplevel) directory'
1396 fi
1397
1398 # Are we running this test at all?
@@ -1448,9 +1446,7 @@ remove_trash_directory () {
1446
1447 # Test repository
1448 remove_trash_directory "$TRASH_DIRECTORY" || {
1451 - GIT_EXIT_OK=t
1452 - echo >&5 "FATAL: Cannot prepare test area"
1453 - exit 1
1449 + BAIL_OUT 'cannot prepare test area'
1450 }
1451
1452 remove_trash=t
@@ -1466,7 +1462,7 @@ fi
1462
1463 # Use -P to resolve symlinks in our working directory so that the cwd
1464 # in subprocesses like git equals our $PWD (for pathname comparisons).
1469 -cd -P "$TRASH_DIRECTORY" || exit 1
1465 +cd -P "$TRASH_DIRECTORY" || BAIL_OUT "cannot cd -P to \"$TRASH_DIRECTORY\""
1466
1467 start_test_output "$0"
1468