git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: Eric Sunshine <sunshine@sunshineco.com>
Cc: git@vger.kernel.org
Subject: Re: [PATCH] t3206: test_when_finished before dirtying operations, not after
Date: Tue, 06 Aug 2024 09:52:56 -0700	[thread overview]
Message-ID: <xmqq4j7xvbiv.fsf@gitster.g> (raw)
In-Reply-To: <CAPig+cRO=BqR1WFcni6CSxqyqvt1Ksmsyr0odmqTDKX4JdbDaA@mail.gmail.com> (Eric Sunshine's message of "Mon, 5 Aug 2024 22:21:59 -0400")

Eric Sunshine <sunshine@sunshineco.com> writes:

> On Mon, Aug 5, 2024 at 8:55 PM Junio C Hamano <gitster@pobox.com> wrote:
>> 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`?

Thanks for good eyes.  The original avoids that issue by making sure
it only installs the clean-up after the operation to create crufts
successfully completes ;-)  Of course, if it fails in the middle,
then the crufts are left behind X-<.

>> @@ -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 `|| :`?

Ah, I forgot that "notes remove" would barf when there is no note to
remove, instead of being idempotent no-op.  Yes, you'd need ||: there.

>     test_when_finished "git notes remove topic unmodified || :" &&

  reply	other threads:[~2024-08-06 16:53 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-08-06  0:55 [PATCH] t3206: test_when_finished before dirtying operations, not after Junio C Hamano
2024-08-06  2:21 ` Eric Sunshine
2024-08-06 16:52   ` Junio C Hamano [this message]
2024-08-06 17:04 ` [PATCH v2] " Junio C Hamano

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=xmqq4j7xvbiv.fsf@gitster.g \
    --to=gitster@pobox.com \
    --cc=git@vger.kernel.org \
    --cc=sunshine@sunshineco.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).