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

Re: [PATCH] t3206: test_when_finished before dirtying operations, not after

From
Eric Sunshine <sunshine@sunshineco.com>
Date
Aug 6, 2024, 02:21 UTC
Message-ID
<CAPig+cRO=BqR1WFcni6CSxqyqvt1Ksmsyr0odmqTDKX4JdbDaA@mail.gmail.com>
In-Reply-To
<xmqqttfyzd01.fsf@gitster.g>
On Mon, Aug 5, 2024 at 8:55 PM Junio C Hamano <gitster@pobox.com> wrote:
Show 23 quoted lines
> Many existing tests in this script perform operation(s) and then use
> test_when_finished to define how to undo the effect of the
> operation(s).
>
> This is backwards.  When your operation(s) fail before you manage to
> successfully call test_when_finished (remember, that these commands
> must be all &&-chained, so a failure of an earlier operation mean
> your test_when_finished may not be executed at all).  You must
> establish how to clean up your mess with test_when_finished before
> you create the mess to be cleaned up.
>
> Signed-off-by: Junio C Hamano <gitster@pobox.com>
> ---
>  t/t3206-range-diff.sh | 52 +++++++++++++++++++++----------------------
> diff --git a/t/t3206-range-diff.sh b/t/t3206-range-diff.sh
> @@ -533,9 +533,9 @@ test_expect_success 'dual-coloring' '
>  for prev in topic main..topic
>  do
>         test_expect_success "format-patch --range-diff=$prev" '
> +               test_when_finished "rm 000?-*" &&
>                 git format-patch --cover-letter --range-diff=$prev \
>                         main..unmodified >actual &&
> -               test_when_finished "rm 000?-*" &&

Do we care whether the action invoked by `test_when_finished` itself succeeds or fails? In particular, should this be using `rm -f` rather than `rm`?

    test_when_finished "rm -f 000?-*" &&
Show 6 quoted lines
> @@ -606,9 +606,9 @@ test_expect_success 'basic with modified format.pretty without "commit "' '
>  test_expect_success 'range-diff compares notes by default' '
> +       test_when_finished git notes remove topic unmodified &&
>         git notes add -m "topic note" topic &&
>         git notes add -m "unmodified note" unmodified &&
> -       test_when_finished git notes remove topic unmodified &&
Similarly, should this be using `|| :`?
    test_when_finished "git notes remove topic unmodified || :" &&
Previous: Junio C HamanoNext: Junio C Hamano
Message 2 of 4 in “t3206: test_when_finished before dirtying operations, not after”
  1. t3206: test_when_finished before dirtying operations, not afterJunio C Hamano, Aug 6, 2024
  2. Eric SunshineAug 6, 2024
  3. Junio C HamanoAug 6, 2024
  4. t3206: test_when_finished before dirtying operations, not afterJunio C Hamano, Aug 6, 2024

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.