Subject: Re: [PATCH 02/12] t: prepare `test_must_fail ()` for `set -e`

From: Jeff King <[email-masked]>
Date: Tue, 14 Apr 2026 02:23:45 -0400

On Mon, Apr 13, 2026 at 11:49:23AM +0200, Patrick Steinhardt wrote:

> diff --git a/t/test-lib-functions.sh b/t/test-lib-functions.sh
> index f3af10fb7e..f8bc77619b 100644
> --- a/t/test-lib-functions.sh
> +++ b/t/test-lib-functions.sh
> @@ -1195,8 +1195,12 @@ test_must_fail () {
>  		echo >&7 "test_must_fail: only 'git' is allowed: $*"
>  		return 1
>  	fi
> -	"$@" 2>&7
> -	exit_code=$?
> +	if "$@" 2>&7
> +	then
> +		exit_code=0
> +	else
> +		exit_code=$?
> +	fi

One subtle interaction here is that the command in "$@" will be run with
"set -e" suppressed if it's a shell function (even if the body
explicitly says "set -e").

I think it's mostly academic since we don't tend to use "set -e" in the
tests at all, but it may be an eventual gotcha.

-Peff