t: prepare execution of potentially failing commands for `set -e`

Several of our tests verify whether a certain binary can be executed, potentially skipping tests in case we cannot, for example because the binary doesn't exist. In those cases we often run the binary outside of any conditionally. This will start to fail once we enable `set -e`, as that will cause us to bail out the test immediately. Improve these tests by executing them inside of a conditional instead. Signed-off-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Patrick Steinhardt committed Apr 21, 2026 at 09:34 UTC 5f0d596fe4a7a4ea8752d3e5115190906c1bea4a
11 files changed +24 -24
t/lib-git-svn.sh
+3 -4
@@ -15,8 +15,7 @@ GIT_SVN_DIR=$GIT_DIR/svn/refs/remotes/git-svn
15 SVN_TREE=$GIT_SVN_DIR/svn-tree
16 test_set_port SVNSERVE_PORT
17
18 -svn >/dev/null 2>&1
19 -if test $? -ne 1
18 +if ! svn help >/dev/null 2>&1
19 then
20 skip_all='skipping git svn tests, svn not found'
21 test_done
@@ -27,13 +26,13 @@ export svnrepo
26 svnconf=$PWD/svnconf
27 export svnconf
28
29 +x=0
30 perl -w -e "
31 use SVN::Core;
32 use SVN::Repos;
33 \$SVN::Core::VERSION gt '1.1.0' or exit(42);
34 system(qw/svnadmin create --fs-type fsfs/, \$ENV{svnrepo}) == 0 or exit(41);
35 -" >&3 2>&4
36 -x=$?
35 +" >&3 2>&4 || x=$?
36 if test $x -ne 0
37 then
38 if test $x -eq 42; then
t/lib-httpd.sh
+1 -2
@@ -235,11 +235,10 @@ start_httpd() {
235
236 test_atexit stop_httpd
237
238 - "$LIB_HTTPD_PATH" -d "$HTTPD_ROOT_PATH" \
238 + if ! "$LIB_HTTPD_PATH" -d "$HTTPD_ROOT_PATH" \
239 -f "$TEST_PATH/apache.conf" $HTTPD_PARA \
240 -c "Listen 127.0.0.1:$LIB_HTTPD_PORT" -k start \
241 >&3 2>&4
242 - if test $? -ne 0
242 then
243 cat "$HTTPD_ROOT_PATH"/error.log >&4 2>/dev/null
244 test_skip_or_die GIT_TEST_HTTPD "web server setup failed"
t/t3901-i18n-patch.sh
+2 -1
@@ -28,7 +28,8 @@ check_encoding () {
28 8859)
29 grep "^encoding ISO8859-1" ;;
30 *)
31 - grep "^encoding ISO8859-1"; test "$?" != 0 ;;
31 + ret=0; grep "^encoding ISO8859-1" || ret=$?
32 + test "$ret" != 0 ;;
33 esac || return 1
34 j=$i
35 i=$(($i+1))
t/t5000-tar-tree.sh
+2 -2
@@ -503,8 +503,8 @@ test_expect_success LONG_IS_64BIT 'set up repository with huge blob' '
503 # would generate the whole 64GB).
504 test_expect_success LONG_IS_64BIT 'generate tar with huge size' '
505 {
506 - git archive HEAD
507 - echo $? >exit-code
506 + { ret=0 && git archive HEAD || ret=$?; } &&
507 + echo "$ret" >exit-code
508 } | test_copy_bytes 4096 >huge.tar &&
509 echo 141 >expect &&
510 test_cmp expect exit-code
t/t7422-submodule-output.sh
+1 -1
@@ -198,7 +198,7 @@ test_expect_success !MINGW 'git submodule status --recursive propagates SIGPIPE'
198 (
199 cd repo &&
200 GIT_ALLOW_PROTOCOL=file git submodule add "$(pwd)"/../submodule &&
201 - { git submodule status --recursive 2>err; echo $?>status; } |
201 + { { ret=0 && git submodule status --recursive 2>err || ret=$?; } && echo $ret >status; } |
202 grep -q recursive-submodule-path-1 &&
203 test_must_be_empty err &&
204 test_match_signal 13 "$(cat status)"
t/t9200-git-cvsexportcommit.sh
+1 -2
@@ -11,8 +11,7 @@ if ! test_have_prereq PERL; then
11 test_done
12 fi
13
14 -cvs >/dev/null 2>&1
15 -if test $? -ne 1
14 +if ! cvs version >/dev/null 2>&1
15 then
16 skip_all='skipping git cvsexportcommit tests, cvs not found'
17 test_done
t/t9400-git-cvsserver-server.sh
+3 -2
@@ -17,12 +17,13 @@ if ! test_have_prereq PERL; then
17 skip_all='skipping git cvsserver tests, perl not available'
18 test_done
19 fi
20 -cvs >/dev/null 2>&1
21 -if test $? -ne 1
20 +
21 +if ! cvs version >/dev/null 2>&1
22 then
23 skip_all='skipping git-cvsserver tests, cvs not found'
24 test_done
25 fi
26 +
27 perl -e 'use DBI; use DBD::SQLite' >/dev/null 2>&1 || {
28 skip_all='skipping git-cvsserver tests, Perl SQLite interface unavailable'
29 test_done
t/t9401-git-cvsserver-crlf.sh
+2 -2
@@ -60,12 +60,12 @@ check_status_options() {
60 return $stat
61 }
62
63 -cvs >/dev/null 2>&1
64 -if test $? -ne 1
63 +if ! cvs version >/dev/null 2>&1
64 then
65 skip_all='skipping git-cvsserver tests, cvs not found'
66 test_done
67 fi
68 +
69 if ! test_have_prereq PERL
70 then
71 skip_all='skipping git-cvsserver tests, perl not available'
t/t9402-git-cvsserver-refs.sh
+2 -2
@@ -68,12 +68,12 @@ check_diff() {
68
69 #########
70
71 -cvs >/dev/null 2>&1
72 -if test $? -ne 1
71 +if ! cvs version >/dev/null 2>&1
72 then
73 skip_all='skipping git-cvsserver tests, cvs not found'
74 test_done
75 fi
76 +
77 if ! test_have_prereq PERL
78 then
79 skip_all='skipping git-cvsserver tests, perl not available'
t/test-lib-functions.sh
+1 -2
@@ -1248,8 +1248,7 @@ test_might_fail () {
1248 test_expect_code () {
1249 want_code=$1
1250 shift
1251 - "$@" 2>&7
1252 - exit_code=$?
1251 + exit_code=0; "$@" 2>&7 || exit_code=$?
1252 if test $exit_code = $want_code
1253 then
1254 return 0
t/test-lib.sh
+6 -4
@@ -143,8 +143,8 @@ export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
143 ################################################################
144 # It appears that people try to run tests without building...
145 GIT_BINARY="${GIT_TEST_INSTALLED:-$GIT_BUILD_DIR}/git$X"
146 -"$GIT_BINARY" >/dev/null
147 -if test $? != 1
146 +
147 +if ! "$GIT_BINARY" version >/dev/null
148 then
149 if test -n "$GIT_TEST_INSTALLED"
150 then
@@ -454,8 +454,10 @@ then
454 # from any previous runs.
455 >"$GIT_TEST_TEE_OUTPUT_FILE"
456
457 - (GIT_TEST_TEE_STARTED=done ${TEST_SHELL_PATH} "$0" "$@" 2>&1;
458 - echo $? >"$TEST_RESULTS_BASE.exit") | tee -a "$GIT_TEST_TEE_OUTPUT_FILE"
457 + (
458 + ret=0 && GIT_TEST_TEE_STARTED=done ${TEST_SHELL_PATH} "$0" "$@" 2>&1 || ret=$?
459 + echo "$ret" >"$TEST_RESULTS_BASE.exit"
460 + ) | tee -a "$GIT_TEST_TEE_OUTPUT_FILE"
461 test "$(cat "$TEST_RESULTS_BASE.exit")" = 0
462 exit
463 fi