From: Calvin Wan <calvinwan@google.com>
To: Glen Choo <chooglen@google.com>
Cc: git@vger.kernel.org, Josh Steadmon <steadmon@google.com>,
peff@peff.net, gitster@pobox.com
Subject: Re: [PATCH v2 1/6] t4041, t4060: modernize test style
Date: Mon, 6 Mar 2023 12:40:43 -0800 [thread overview]
Message-ID: <CAFySSZDF5V6nV2uyg0NSvVGgG_ybSpeqGPi7CPSvsyZ10KfYwA@mail.gmail.com> (raw)
In-Reply-To: <kl6l8rg9ekvz.fsf@chooglen-macbookpro.roam.corp.google.com>
On Mon, Mar 6, 2023 at 11:32 AM Glen Choo <chooglen@google.com> wrote:
>
> Calvin Wan <calvinwan@google.com> writes:
>
> > In preparation for later changes, move setup code into test_expect
> > blocks. Smaller sections are moved into existing blocks, while larger
> > sections with a standalone purpose are given their own new blocks.
>
> The changes where we moved lines outside of blocks into blocks without
> changing them look good to me.
>
> > While at it, have tests clean up after themselves with
> > test_when_finished
>
> I believe this came about as part of the discussion in
>
> https://lore.kernel.org/git/xmqqedqtbbf4.fsf@gitster.g
>
> I think it's good to have tests clean up after themselves, but I'm not
> sure if that's what we're doing in all of these cases, see below.
>
> I'm leaving the diff header in place, since the two files have very
> confusingly similar tests.
>
> > diff --git a/t/t4041-diff-submodule-option.sh b/t/t4041-diff-submodule-option.sh
> > test_expect_success 'typechanged submodule(submodule->blob)' '
> > + test_when_finished rm -rf sm1 &&
> > git diff --submodule=log >actual &&
> > cat >expected <<-EOF &&
> > diff --git a/sm1 b/sm1
>
> This hunk and the next...
>
> > @@ -212,9 +215,9 @@ test_expect_success 'typechanged submodule(submodule->blob)' '
> > test_cmp expected actual
> > '
> >
> > -rm -rf sm1 &&
> > -git checkout-index sm1
> > test_expect_success 'typechanged submodule(submodule->blob)' '
> > + test_when_finished rm -f sm1 &&
> > + git checkout-index sm1 &&
> > git diff-index -p --submodule=log HEAD >actual &&
> > cat >expected <<-EOF &&
> > Submodule sm1 $head4...0000000 (submodule deleted)
>
> were changed so that the "rm -rf" happens in the clean up phase of the
> earlier test (test 14) instead of set up phase of the later test (test
> 15). But, the "rm -rf" actually results in a _different_ state from
> before 14, so it isn't actually cleaning up, it really is preparation
> for 15's git checkout-index.
>
> You can observe this by running
>
> ./t4041-diff-submodule-option.sh --run=1-13,15
>
> which fails as expected. On the other hand, it passes if we move the "rm
> -rf" into test 15.
>
> Nearly all of the other test_when_finished here have the same problem,
> where they 'clean up' state that wasn't changed in the same test body. I
> believe they will show similar dependency issues, though I didn't go
> through and test them all.
Good catch. I'll go thru the rest of them and remove the dependency
issues.
>
> > @@ -643,7 +643,6 @@ test_expect_success 'modified submodule contains modified content' '
> > diff_cmp expected actual
> > '
> >
> > -rm -rf sm1
> > test_expect_success 'deleted submodule' '
> > git diff-index -p --submodule=diff HEAD >actual &&
> > cat >expected <<-EOF &&
>
> This one is fairly obvious, since the test says 'deleted submodule', but
> we no longer delete the submodule in the setup.
>
> > @@ -779,9 +780,8 @@ test_expect_success 'diff --submodule=diff with .git file' '
> > diff_cmp expected actual
> > '
> >
> > -mv sm2 sm2-bak
> > -
> > test_expect_success 'deleted submodule with .git file' '
> > + mv sm2 sm2-bak &&
> > git diff-index -p --submodule=diff HEAD >actual &&
> > cat >expected <<-EOF &&
> > Submodule sm1 $head7...0000000 (submodule deleted)
> > @@ -804,9 +804,9 @@ test_expect_success 'deleted submodule with .git file' '
> > diff_cmp expected actual
> > '
> >
> > -echo submodule-to-blob>sm2
> > -
> > test_expect_success 'typechanged(submodule->blob) submodule with .git file' '
> > + test_when_finished "rm sm2 && mv sm2-bak sm2" &&
> > + echo submodule-to-blob>sm2 &&
> > git diff-index -p --submodule=diff HEAD >actual &&
> > cat >expected <<-EOF &&
> > Submodule sm1 $head7...0000000 (submodule deleted)
> > @@ -836,9 +836,6 @@ test_expect_success 'typechanged(submodule->blob) submodule with .git file' '
> > diff_cmp expected actual
> > '
> >
> > -rm sm2
> > -mv sm2-bak sm2
>
> This is the original case that Junio flagged, which I think is an almost
> correct use of test_when_finished, since we do get back to an earlier
> state before this string of tests, but not to the state before the
> actual test with the test_when_finished.
>
> If we want to use test_when_finished here (which I think we do), we
> should add another test_when_finished to remove the dependency between
> the two tests. like so:
>
> test_expect_success 'deleted submodule with .git file' '
> + test_when_finished "mv sm2-bak sm2" &&
> mv sm2 sm2-bak &&
> git diff-index -p --submodule=diff HEAD >actual &&
>
> ...
>
> test_expect_success 'typechanged(submodule->blob) submodule with .git file' '
> test_when_finished "rm sm2 && mv sm2-bak sm2" &&
> + mv sm2 sm2-bak &&
>
> Currently, they're still dependent because one creates sm2-bak and the
> other moves it back, but if we have each test restore sm2, there will be
> no more dependency.
>
That all makes sense. Thanks for the recommendations
next prev parent reply other threads:[~2023-03-06 20:40 UTC|newest]
Thread overview: 40+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-02-13 18:21 [RFC PATCH 0/6] add: block invalid submodules Calvin Wan
2023-02-13 18:21 ` [RFC PATCH 1/6] leak fix: cache_put_path Calvin Wan
2023-02-13 19:23 ` Junio C Hamano
2023-02-14 19:56 ` Calvin Wan
2023-02-14 21:08 ` Junio C Hamano
2023-02-14 21:39 ` Calvin Wan
2023-02-14 21:59 ` Junio C Hamano
2023-02-13 18:21 ` [RFC PATCH 2/6] t4041, t4060: modernize test style Calvin Wan
2023-02-13 19:41 ` Junio C Hamano
2023-02-14 20:22 ` Calvin Wan
2023-02-13 18:21 ` [RFC PATCH 3/6] tests: Use `git submodule add` instead of `git add` Calvin Wan
2023-02-13 18:21 ` [RFC PATCH 4/6] tests: use `git submodule add` and fix expected diffs Calvin Wan
2023-02-13 23:07 ` Junio C Hamano
2023-02-13 23:19 ` Junio C Hamano
2023-02-13 18:21 ` [RFC PATCH 5/6] tests: use `git submodule add` and fix expected status Calvin Wan
2023-02-13 18:21 ` [RFC PATCH 6/6] add: reject nested repositories Calvin Wan
2023-02-13 20:42 ` Jeff King
2023-02-14 2:17 ` Junio C Hamano
2023-02-14 16:07 ` Jeff King
2023-02-14 16:32 ` Junio C Hamano
2023-02-14 21:45 ` Calvin Wan
2023-02-28 18:52 ` [PATCH v2 0/6] add: block invalid submodules Calvin Wan
2023-02-28 18:56 ` [PATCH v2 1/6] t4041, t4060: modernize test style Calvin Wan
2023-03-06 19:32 ` Glen Choo
2023-03-06 20:40 ` Calvin Wan [this message]
2023-02-28 18:56 ` [PATCH v2 2/6] tests: Use `git submodule add` instead of `git add` Calvin Wan
2023-02-28 23:30 ` Junio C Hamano
2023-03-03 0:16 ` Calvin Wan
2023-03-06 21:26 ` Glen Choo
2023-02-28 18:56 ` [PATCH v2 3/6] tests: use `git submodule add` and fix expected diffs Calvin Wan
2023-03-06 23:34 ` Glen Choo
2023-03-06 23:57 ` Junio C Hamano
2023-02-28 18:56 ` [PATCH v2 4/6] tests: use `git submodule add` and fix expected status Calvin Wan
2023-03-07 0:15 ` Glen Choo
2023-02-28 18:56 ` [PATCH v2 5/6] tests: remove duplicate .gitmodules path Calvin Wan
2023-02-28 23:35 ` Junio C Hamano
2023-03-02 23:09 ` Calvin Wan
2023-03-07 0:51 ` Glen Choo
2023-02-28 18:56 ` [PATCH v2 6/6] add: reject nested repositories Calvin Wan
2023-03-07 2:04 ` Glen Choo
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=CAFySSZDF5V6nV2uyg0NSvVGgG_ybSpeqGPi7CPSvsyZ10KfYwA@mail.gmail.com \
--to=calvinwan@google.com \
--cc=chooglen@google.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=peff@peff.net \
--cc=steadmon@google.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).