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

From: Junio C Hamano <[email-masked]>
Date: Thu, 16 Apr 2026 09:06:15 -0700

Patrick Steinhardt <[email-masked]> writes:

>  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
> +

OK.

> 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

A possible alternative would be to actually test "$TEST_SHELL_PATH"
with the features we want to be working, e.g.,

    out=$("$TEST_SHELL_PATH" -e -c '
	# basics - "set -e" suppressed when "tested"
	false && echo 0

	# <[email-masked]>
	# ancient bash dies after "command false"
	command false && echo 1

	# <[email-masked]>
	# failure inside a function excempt from "set -e"
	f () { false ; echo 2; }
	f || echo 3
    ')
    if test "$out" = 2
    then
            set -e
    fi

which adds some documentation value, but I think "this one is
known-good, and we know we use it somewhere" is probably good
enough.