Re: [PATCH v3 12/12] t: detect errors outside of test cases
- From
Junio C Hamano <gitster@pobox.com>
- Date
- Apr 16, 2026, 16:06 UTC
- Message-ID
- <xmqqpl3y3n60.fsf@gitster.g>
- In-Reply-To
- <20260416-b4-pks-tests-with-set-e-v3-12-7a90e5dccadd@pks.im>
Patrick Steinhardt <ps@pks.im> writes:
Show 6 quoted lines
> 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.
Show 16 quoted lines
> 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
> +fiA 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# <20260414225206.GA3486072@coredump.intra.peff.net> # ancient bash dies after "command false" command false && echo 1
# <20260416054038.GA646814@coredump.intra.peff.net>
# failure inside a function excempt from "set -e"
f () { false ; echo 2; }
f || echo 3
')
if test "$out" = 2
then
set -e
fiwhich adds some documentation value, but I think "this one is known-good, and we know we use it somewhere" is probably good enough.