Skip to content

Commit 25c2351

Browse files
avargitster
authored andcommitted
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 234383c (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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent e0258f1 commit 25c2351

File tree

1 file changed

+6
-10
lines changed

1 file changed

+6
-10
lines changed

t/test-lib.sh

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1173,8 +1173,6 @@ test_done () {
11731173
# removed, so the commands can access pidfiles and socket files.
11741174
test_atexit_handler
11751175

1176-
GIT_EXIT_OK=t
1177-
11781176
finalize_test_output
11791177

11801178
if test -z "$HARNESS_ACTIVE"
@@ -1246,6 +1244,7 @@ test_done () {
12461244
fi
12471245
test_at_end_hook_
12481246

1247+
GIT_EXIT_OK=t
12491248
exit 0 ;;
12501249

12511250
*)
@@ -1255,6 +1254,7 @@ test_done () {
12551254
say "1..$test_count"
12561255
fi
12571256

1257+
GIT_EXIT_OK=t
12581258
exit 1 ;;
12591259

12601260
esac
@@ -1387,14 +1387,12 @@ fi
13871387
GITPERLLIB="$GIT_BUILD_DIR"/perl/build/lib
13881388
export GITPERLLIB
13891389
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?"
13911391
}
13921392

13931393
if ! test -x "$GIT_BUILD_DIR"/t/helper/test-tool$X
13941394
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'
13981396
fi
13991397

14001398
# Are we running this test at all?
@@ -1448,9 +1446,7 @@ remove_trash_directory () {
14481446

14491447
# Test repository
14501448
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'
14541450
}
14551451

14561452
remove_trash=t
@@ -1466,7 +1462,7 @@ fi
14661462

14671463
# Use -P to resolve symlinks in our working directory so that the cwd
14681464
# 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\""
14701466

14711467
start_test_output "$0"
14721468

0 commit comments

Comments
 (0)