git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH 3/3] t: detect and signal failure within loop

From
Elijah Newren <newren@gmail.com>
Date
Aug 23, 2022, 03:05 UTC
Message-ID
<CABPp-BH-QzH-5MmvBwqncxr2VQQPfAk0oEYus2HMgdmpX3ppUg@mail.gmail.com>
In-Reply-To
<31a962fd5070d68964e545fb5506d795e8845ec3.1661192802.git.gitgitgadget@gmail.com>

On Mon, Aug 22, 2022 at 11:26 AM Eric Sunshine via GitGitGadget <gitgitgadget@gmail.com> wrote:

Show 12 quoted lines
>
> From: Eric Sunshine <sunshine@sunshineco.com>
>
> Failures within `for` and `while` loops can go unnoticed if not detected
> and signaled manually since the loop itself does not abort when a
> contained command fails, nor will a failure necessarily be detected when
> the loop finishes since the loop returns the exit code of the last
> command it ran on the final iteration, which may not be the command
> which failed. Therefore, detect and signal failures manually within
> loops using the idiom `|| return 1` (or `|| exit 1` within subshells).
>
> Signed-off-by: Eric Sunshine <sunshine@sunshineco.com>
[...]
Show 15 quoted lines
> diff --git a/t/t6429-merge-sequence-rename-caching.sh b/t/t6429-merge-sequence-rename-caching.sh
> index e1ce9199164..650b3cd14ff 100755
> --- a/t/t6429-merge-sequence-rename-caching.sh
> +++ b/t/t6429-merge-sequence-rename-caching.sh
> @@ -725,7 +725,7 @@ test_expect_success 'avoid assuming we detected renames' '
>                 mkdir unrelated &&
>                 for i in $(test_seq 1 10)
>                 do
> -                       >unrelated/$i
> +                       >unrelated/$i || exit 1
>                 done &&
>                 test_seq  2 10 >numbers &&
>                 test_seq 12 20 >values &&
> --
> gitgitgadget

That's not something I'm likely ever going to remember to think of as capable of failing and needing this special care. Is this a preliminary series before you send chainlint improvements that finds this kind of thing for us? Or did you notice this some other way?

Change is fine, of course, I'm just curious how it was found (and how I can avoid adding more of these that you'll need to later fix up).

Previous: Johannes SixtNext: Eric Sunshine
Message 9 of 10 in “tests: fix broken &&-chains & abort loops on error”
  1. 0/3 tests: fix broken &&-chains & abort loops on errorEric Sunshine via GitGitGadget, Aug 22, 2022
  2. 1/3 t2407: fix broken &&-chains in compound statementEric Sunshine via GitGitGadget, Aug 22, 2022
  3. 2/3 t1092: fix buggy sparse "blame" testEric Sunshine via GitGitGadget, Aug 22, 2022
  4. Derrick StoleeAug 22, 2022
  5. 3/3 t: detect and signal failure within loopEric Sunshine via GitGitGadget, Aug 22, 2022
  6. Junio C HamanoAug 22, 2022
  7. Junio C HamanoAug 22, 2022
  8. Johannes SixtAug 23, 2022
  9. Elijah NewrenAug 23, 2022
  10. Eric SunshineAug 28, 2022

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.