Skip to content

Commit 9115b39

Browse files
pks-tgitster
authored andcommitted
t: detect errors outside of test cases
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 <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent 505123f commit 9115b39

2 files changed

Lines changed: 14 additions & 0 deletions

File tree

ci/run-build-and-tests.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,11 @@ fedora-breaking-changes-musl|linux-breaking-changes)
1515
MESONFLAGS="$MESONFLAGS -Drust=enabled"
1616
;;
1717
linux-TEST-vars)
18+
# Ubuntu uses Dash by default, but we only enable use of `set -e`
19+
# when using Bash 5+. Ensure that we have at least one CI job that uses
20+
# it.
21+
export TEST_SHELL_PATH=/usr/bin/bash
22+
1823
export OPENSSL_SHA1_UNSAFE=YesPlease
1924
export GIT_TEST_SPLIT_INDEX=yes
2025
export GIT_TEST_FULL_IN_PACK_ARRAY=true

t/test-lib.sh

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,15 @@
1515
# You should have received a copy of the GNU General Public License
1616
# along with this program. If not, see https://www.gnu.org/licenses/ .
1717

18+
# Enable the use of errexit so that any unexpected failures will cause us to
19+
# abort tests, even when outside of a specific test case. Note that we only
20+
# enable this on Bash 5 and newer, as `set -e` has wildly different behaviour
21+
# across shells. The list of allowed shells may be extended going forward.
22+
if test "${BASH_VERSINFO:=0}" -ge 5
23+
then
24+
set -e
25+
fi
26+
1827
# Test the binaries we have just built. The tests are kept in
1928
# t/ subdirectory and are run in 'trash directory' subdirectory.
2029
if test -z "$TEST_DIRECTORY"

0 commit comments

Comments
 (0)