Subject: Re: [PATCH v2 1/8] log tests: don't use "exit 1" outside a sub-shell

From: Ævar Arnfjörð Bjarmason <[email-masked]>
Date: Fri, 02 Dec 2022 03:45:55 +0100

On Fri, Dec 02 2022, Junio C Hamano wrote:

> Eric Sunshine <[email-masked]> writes:
>
>>>                 git show -s --pretty=oneline "$r" >raw &&
>>> -               cat raw | lf_to_nul || exit 1
>>> +               cat raw | lf_to_nul || return 1
>>>         done >expect &&
>>
>> Using `return 1` here is "obviously correct" since this code is not
>> inside a subshell. Furthermore, the exit code of the for-loop itself
>> is not being lost down a pipe, so `return 1` is indeed an appropriate
>> way to signal failure. Good.
>
> "return 1" is obvious and safe correction.  I have to wonder if
> test_expect_success can be taught to be smarter to intercept "exit"
> so we do not have to bo so careful, but that would be a much more
> involved change to the lower-level of test framework.

I can't think of a way to do so that wouldn't involve running the test
in a sub-shell, which I think would bring us to the state management
problems noted in [1] for Phillip's "test_todo" series, except in this
case we'd have those issues trying to pass state back from the
"test_expect_success".

It's possible, but we'd need to change a lot of code that's expecting to
talk to itself via variables in the same shell to use IPC between
shells, wouldn't we?

1. https://lore.kernel.org/git/[email-masked]/