From: Jeff King Date: Tue, 14 Apr 2026 06:23:45 GMT Subject: Re: [PATCH 02/12] t: prepare `test_must_fail ()` for `set -e` Message-ID: <20260414062345.GA2902286@coredump.intra.peff.net> In-Reply-To: <20260413-b4-pks-tests-with-set-e-v1-2-5b83763a0e84@pks.im> 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