git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH v4 12/12] t: detect errors outside of test cases

From
Jeff King <peff@peff.net>
Date
Apr 18, 2026, 06:50 UTC
Message-ID
<20260418065009.GA2619713@coredump.intra.peff.net>
In-Reply-To
<20260417-b4-pks-tests-with-set-e-v4-12-44d43efdafb1@pks.im>
On Fri, Apr 17, 2026 at 12:50:58PM +0200, Patrick Steinhardt wrote:
Show 10 quoted lines
> --- 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

Thinking on this a little more, it is a shame we cannot easily enable this for dash. That would hit most CI jobs, but also the local builds of most developers. And finding problems early and locally often saves a lot of time versus finding them in CI.

Unfortunately I could not find a way to detect whether we are running dash at all, let alone a recent version. But what if we let the user tell us? Something like:

diff --git a/t/test-lib.sh b/t/test-lib.sh
index 1f7868c537..a0d07f75fb 100644
--- a/t/test-lib.sh
+++ b/t/test-lib.sh
@@ -17,9 +17,10 @@
 
 # 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
+# enable this by default on Bash 5 and newer, as `set -e` has wildly different
+# behaviour across shells. If you trust your shell's `set -e` implementation,
+# you can set GIT_TEST_USE_SET_E manually.
+if test "$GIT_TEST_USE_SET_E" = 1 && test "${BASH_VERSINFO:=0}" -ge 5
 then
 	set -e
 fi

And then those of us who want to stick:

  export GIT_TEST_USE_SET_E = 1

in our config.mak can do so, and we could even set it in the ci/ scripts
for all of the ubuntu builds.

-Peff
Previous: Patrick SteinhardtNext: Ben Knoble
Message 14 of 23 in “t: detect errors outside of test cases”
  1. 00/12 t: detect errors outside of test casesPatrick Steinhardt, Apr 17, 2026
  2. 01/12 t: prepare `test_match_signal ()` calls for `set -e`Patrick Steinhardt, Apr 17, 2026
  3. 02/12 t: prepare `test_must_fail ()` for `set -e`Patrick Steinhardt, Apr 17, 2026
  4. 03/12 t: prepare `stop_git_daemon ()` for `set -e`Patrick Steinhardt, Apr 17, 2026
  5. 04/12 t: prepare `git config --unset` calls for `set -e`Patrick Steinhardt, Apr 17, 2026
  6. 05/12 t: prepare conditional test execution for `set -e`Patrick Steinhardt, Apr 17, 2026
  7. 06/12 t: prepare execution of potentially failing commands for `set -e`Patrick Steinhardt, Apr 17, 2026
  8. 07/12 t: prepare `test_when_finished ()`/`test_atexit()` for `set -e`Patrick Steinhardt, Apr 17, 2026
  9. 08/12 t0008: silence error in subshell when using `grep -v`Patrick Steinhardt, Apr 17, 2026
  10. 09/12 t1301: don't fail in case setfacl(1) doesn't exist or failsPatrick Steinhardt, Apr 17, 2026
  11. 10/12 t6002: fix use of `expr` with `set -e`Patrick Steinhardt, Apr 17, 2026
  12. 11/12 t9902: fix use of `read` with `set -e`Patrick Steinhardt, Apr 17, 2026
  13. 12/12 t: detect errors outside of test casesPatrick Steinhardt, Apr 17, 2026
  14. Jeff KingApr 18, 2026
  15. Ben KnobleApr 18, 2026
  16. Jeff KingApr 18, 2026
  17. Junio C HamanoApr 18, 2026
  18. Jeff KingApr 18, 2026
  19. Patrick SteinhardtApr 20, 2026
  20. brian m. carlsonApr 18, 2026
  21. Jeff KingApr 18, 2026
  22. brian m. carlsonApr 18, 2026
  23. Jeff KingApr 19, 2026

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.