Skip to content

Commit 8b507cb

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 f363bc6 commit 8b507cb

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

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)