From: Patrick Steinhardt Date: Fri, 17 Apr 2026 10:50:58 GMT Subject: [PATCH v4 12/12] t: detect errors outside of test cases Message-ID: <20260417-b4-pks-tests-with-set-e-v4-12-44d43efdafb1@pks.im> In-Reply-To: <20260417-b4-pks-tests-with-set-e-v4-0-44d43efdafb1@pks.im> We have recently merged a patch series that had a simple misspelling of `test_expect_success`. Instead of making our tests fail though, this typo went completely undetected and all of our tests passed, which is of course unfortunate. This is a more general issue with our test suite: all commands that run outside of a specific test case can fail, and if we don't explicitly check for such failure then this failure will be silently ignored. Improve the status quo by enabling the errexit option so that any such unchecked failures will cause us to abort immediately. Note that for now, we only enable this option for Bash 5 and newer. This is because other shells have wildly different behaviour, and older versions of Bash (especially on macOS) are buggy. The list of enabled shells may be extended going forward. Signed-off-by: Patrick Steinhardt --- ci/run-build-and-tests.sh | 5 +++++ t/test-lib.sh | 9 +++++++++ 2 files changed, 14 insertions(+) diff --git a/ci/run-build-and-tests.sh b/ci/run-build-and-tests.sh index 28cfe730ee..f0a3597184 100755 --- a/ci/run-build-and-tests.sh +++ b/ci/run-build-and-tests.sh @@ -15,6 +15,11 @@ fedora-breaking-changes-musl|linux-breaking-changes) MESONFLAGS="$MESONFLAGS -Drust=enabled" ;; linux-TEST-vars) + # Ubuntu uses Dash by default, but we only enable use of `set -e` + # when using Bash 5+. Ensure that we have at least one CI job that uses + # it. + export TEST_SHELL_PATH=/usr/bin/bash + export OPENSSL_SHA1_UNSAFE=YesPlease export GIT_TEST_SPLIT_INDEX=yes export GIT_TEST_FULL_IN_PACK_ARRAY=true diff --git a/t/test-lib.sh b/t/test-lib.sh index de7d9e7b92..1f7868c537 100644 --- a/t/test-lib.sh +++ b/t/test-lib.sh @@ -15,6 +15,15 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see https://www.gnu.org/licenses/ . +# Enable the use of errexit so that any unexpected failures will cause us to +# abort tests, even when outside of a specific test case. Note that we only +# enable this on Bash 5 and newer, as `set -e` has wildly different behaviour +# across shells. The list of allowed shells may be extended going forward. +if test "${BASH_VERSINFO:=0}" -ge 5 +then + set -e +fi + # Test the binaries we have just built. The tests are kept in # t/ subdirectory and are run in 'trash directory' subdirectory. if test -z "$TEST_DIRECTORY" -- 2.54.0.rc2.529.gd9106f7525.dirty