]> git.ipfire.org Git - thirdparty/git.git/commitdiff
t: prepare execution of potentially failing commands for `set -e`
authorPatrick Steinhardt <ps@pks.im>
Tue, 21 Apr 2026 07:34:19 +0000 (09:34 +0200)
committerJunio C Hamano <gitster@pobox.com>
Wed, 22 Apr 2026 22:53:36 +0000 (15:53 -0700)
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>
t/lib-git-svn.sh
t/lib-httpd.sh
t/t3901-i18n-patch.sh
t/t5000-tar-tree.sh
t/t7422-submodule-output.sh
t/t9200-git-cvsexportcommit.sh
t/t9400-git-cvsserver-server.sh
t/t9401-git-cvsserver-crlf.sh
t/t9402-git-cvsserver-refs.sh
t/test-lib-functions.sh
t/test-lib.sh

index 2fde2353fd38356548fd40e4808984618b0d9585..52843f667de0d6ac1844d577c4bfa33459f6aefb 100644 (file)
@@ -15,8 +15,7 @@ GIT_SVN_DIR=$GIT_DIR/svn/refs/remotes/git-svn
 SVN_TREE=$GIT_SVN_DIR/svn-tree
 test_set_port SVNSERVE_PORT
 
-svn >/dev/null 2>&1
-if test $? -ne 1
+if ! svn help >/dev/null 2>&1
 then
        skip_all='skipping git svn tests, svn not found'
        test_done
@@ -27,13 +26,13 @@ export svnrepo
 svnconf=$PWD/svnconf
 export svnconf
 
+x=0
 perl -w -e "
 use SVN::Core;
 use SVN::Repos;
 \$SVN::Core::VERSION gt '1.1.0' or exit(42);
 system(qw/svnadmin create --fs-type fsfs/, \$ENV{svnrepo}) == 0 or exit(41);
-" >&3 2>&4
-x=$?
+" >&3 2>&4 || x=$?
 if test $x -ne 0
 then
        if test $x -eq 42; then
index 4c76e813e396bfaf311d8db75f6e1e7e4af47230..fc646447d5c03859bdc6dceb084492338b999c14 100644 (file)
@@ -235,11 +235,10 @@ start_httpd() {
 
        test_atexit stop_httpd
 
-       "$LIB_HTTPD_PATH" -d "$HTTPD_ROOT_PATH" \
+       if ! "$LIB_HTTPD_PATH" -d "$HTTPD_ROOT_PATH" \
                -f "$TEST_PATH/apache.conf" $HTTPD_PARA \
                -c "Listen 127.0.0.1:$LIB_HTTPD_PORT" -k start \
                >&3 2>&4
-       if test $? -ne 0
        then
                cat "$HTTPD_ROOT_PATH"/error.log >&4 2>/dev/null
                test_skip_or_die GIT_TEST_HTTPD "web server setup failed"
index f03601b49a93970eeb0d0393f9979fc71dbe9ce1..ef7d7e1edc2aee3d5b89a0bbf66cda94ebf575a8 100755 (executable)
@@ -28,7 +28,8 @@ check_encoding () {
                8859)
                        grep "^encoding ISO8859-1" ;;
                *)
-                       grep "^encoding ISO8859-1"; test "$?" != 0 ;;
+                       ret=0; grep "^encoding ISO8859-1" || ret=$?
+                       test "$ret" != 0 ;;
                esac || return 1
                j=$i
                i=$(($i+1))
index 5465054f1779f06e94998a7f342f27b9993af8d4..a8c28533dc73f821ecb7bafdde22690435a47c9f 100755 (executable)
@@ -503,8 +503,8 @@ test_expect_success LONG_IS_64BIT 'set up repository with huge blob' '
 # would generate the whole 64GB).
 test_expect_success LONG_IS_64BIT 'generate tar with huge size' '
        {
-               git archive HEAD
-               echo $? >exit-code
+               { ret=0 && git archive HEAD || ret=$?; } &&
+               echo "$ret" >exit-code
        } | test_copy_bytes 4096 >huge.tar &&
        echo 141 >expect &&
        test_cmp expect exit-code
index aea1ddf117e8ee6c73809b67306647acab057818..852136fdfd3ec884024313fde5f0991c60c1b49f 100755 (executable)
@@ -198,7 +198,7 @@ test_expect_success !MINGW 'git submodule status --recursive propagates SIGPIPE'
        (
                cd repo &&
                GIT_ALLOW_PROTOCOL=file git submodule add "$(pwd)"/../submodule &&
-               { git submodule status --recursive 2>err; echo $?>status; } |
+               { { ret=0 && git submodule status --recursive 2>err || ret=$?; } && echo $ret >status; } |
                        grep -q recursive-submodule-path-1 &&
                test_must_be_empty err &&
                test_match_signal 13 "$(cat status)"
index 14cbe9652779bc4481f4d71baa28394212a37a05..581cf3d28fc05b7e967862c32f81855d0f9eaa3d 100755 (executable)
@@ -11,8 +11,7 @@ if ! test_have_prereq PERL; then
        test_done
 fi
 
-cvs >/dev/null 2>&1
-if test $? -ne 1
+if ! cvs version >/dev/null 2>&1
 then
     skip_all='skipping git cvsexportcommit tests, cvs not found'
     test_done
index e499c7f955125eb25ce0dfdcd78012adf8cf4d7a..4b45398bab2295d7a80402a4e6dc93b172db359e 100755 (executable)
@@ -17,12 +17,13 @@ if ! test_have_prereq PERL; then
        skip_all='skipping git cvsserver tests, perl not available'
        test_done
 fi
-cvs >/dev/null 2>&1
-if test $? -ne 1
+
+if ! cvs version >/dev/null 2>&1
 then
     skip_all='skipping git-cvsserver tests, cvs not found'
     test_done
 fi
+
 perl -e 'use DBI; use DBD::SQLite' >/dev/null 2>&1 || {
     skip_all='skipping git-cvsserver tests, Perl SQLite interface unavailable'
     test_done
index a34805acdc25cca244b5d10e1bae68f5937a279a..6b4cbb165131e043c2dab17073a2c19e20914ecf 100755 (executable)
@@ -60,12 +60,12 @@ check_status_options() {
     return $stat
 }
 
-cvs >/dev/null 2>&1
-if test $? -ne 1
+if ! cvs version >/dev/null 2>&1
 then
     skip_all='skipping git-cvsserver tests, cvs not found'
     test_done
 fi
+
 if ! test_have_prereq PERL
 then
     skip_all='skipping git-cvsserver tests, perl not available'
index 2ee41f9443eefb234dd48786f8c57d109f7dbbe3..65f2ceedecb2e73b3a7dcca75b10ec5f645c115a 100755 (executable)
@@ -68,12 +68,12 @@ check_diff() {
 
 #########
 
-cvs >/dev/null 2>&1
-if test $? -ne 1
+if ! cvs version >/dev/null 2>&1
 then
        skip_all='skipping git-cvsserver tests, cvs not found'
        test_done
 fi
+
 if ! test_have_prereq PERL
 then
        skip_all='skipping git-cvsserver tests, perl not available'
index 5fd5494ef1030c4014d8863ecfe9dae64fa291f6..879ee1ee597715933ee222f01545552a025a4544 100644 (file)
@@ -1248,8 +1248,7 @@ test_might_fail () {
 test_expect_code () {
        want_code=$1
        shift
-       "$@" 2>&7
-       exit_code=$?
+       exit_code=0; "$@" 2>&7 || exit_code=$?
        if test $exit_code = $want_code
        then
                return 0
index 70fd3e9bafb8007071ddbd6377fa7474fc2f7b74..de7d9e7b925049cee92526d4ee3d28122b65cefb 100644 (file)
@@ -143,8 +143,8 @@ export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
 ################################################################
 # It appears that people try to run tests without building...
 GIT_BINARY="${GIT_TEST_INSTALLED:-$GIT_BUILD_DIR}/git$X"
-"$GIT_BINARY" >/dev/null
-if test $? != 1
+
+if ! "$GIT_BINARY" version >/dev/null
 then
        if test -n "$GIT_TEST_INSTALLED"
        then
@@ -454,8 +454,10 @@ then
        # from any previous runs.
        >"$GIT_TEST_TEE_OUTPUT_FILE"
 
-       (GIT_TEST_TEE_STARTED=done ${TEST_SHELL_PATH} "$0" "$@" 2>&1;
-        echo $? >"$TEST_RESULTS_BASE.exit") | tee -a "$GIT_TEST_TEE_OUTPUT_FILE"
+       (
+               ret=0 && GIT_TEST_TEE_STARTED=done ${TEST_SHELL_PATH} "$0" "$@" 2>&1 || ret=$?
+               echo "$ret" >"$TEST_RESULTS_BASE.exit"
+       ) | tee -a "$GIT_TEST_TEE_OUTPUT_FILE"
        test "$(cat "$TEST_RESULTS_BASE.exit")" = 0
        exit
 fi