git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: Calvin Wan <calvinwan@google.com>
Cc: git@vger.kernel.org, Josh Steadmon <steadmon@google.com>
Subject: Re: [RFC PATCH 2/6] t4041, t4060: modernize test style
Date: Mon, 13 Feb 2023 11:41:35 -0800	[thread overview]
Message-ID: <xmqqedqtbbf4.fsf@gitster.g> (raw)
In-Reply-To: <20230213182134.2173280-3-calvinwan@google.com> (Calvin Wan's message of "Mon, 13 Feb 2023 18:21:30 +0000")

Calvin Wan <calvinwan@google.com> writes:

> From: Josh Steadmon <steadmon@google.com>
>
> 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.

Nice.

> -test_create_repo sm1 &&
> -add_file . foo >/dev/null
> -
> -head1=$(add_file sm1 foo1 foo2)
> -fullhead1=$(cd sm1; git rev-parse --verify HEAD)
> +test_expect_success 'setup' '
> +	test_create_repo sm1 &&
> +	add_file . foo >/dev/null &&

Now this is inside test_expect_success, redirection to /dev/null is
unnecessary.

> +	head1=$(add_file sm1 foo1 foo2) &&
> +	fullhead1=$(cd sm1 && git rev-parse --verify HEAD)
> +'

Or "fullhead1=$(git -C sm1 rev-parse ...)".

Both of the above can be ignored if we are trying to be a strict
rewrite of the original, but moving code inside test_expect_success
block is a large enough change that there may not be much point in
avoiding such an obvious modernization "while at it".


> -rm sm2
> -mv sm2-bak sm2
> -
>  test_expect_success 'setup nested submodule' '
> +	rm sm2 &&
> +	mv sm2-bak sm2 &&

To me, this looks more like something test_when_finished in the test
that wanted not to have sm2 (i.e. "deleted submodule with .git file")
should have done as part of its own clean-up.

There certainly can be two schools of thought when it comes to how to
arrange the precondition of subsequent tests.  More modern tests tend
to clean after themselves by reverting the damage they made to the
environment inside test_when_finished in themselves.  This one, as
the posted patch does, goes to the other extreme and forces the
subsequent test to undo the damage done by the previous ones.

The latter approach has two major downsides.  It would not work if
the tester wants to skip an earlier step, or if an earlier step
failed to cause the expected damage this step wants to undo.  The
correctness of "what we should see as sm2 here must be in sm2-bak
because we know an earlier step should have moved it there" can
easily be broken.  It also makes it harder to update the earlier
step to cause different damage to the environment---the "undoing the
damage done by the previous step(s)" done as early parts of this
step also needs to be updated.

Whichever approach we pick to use in each script, it would be better
to stick to one philosophy, and if we can make each step revert the
damage it caused when it is done, that would be nice.

> -mv sm2-bak sm2
> +test_expect_success 'submodule cleanup' '
> +	mv sm2-bak sm2
> +'
>  
>  test_done

Likewise.

Thanks.

  reply	other threads:[~2023-02-13 19:42 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 [this message]
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
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=xmqqedqtbbf4.fsf@gitster.g \
    --to=gitster@pobox.com \
    --cc=calvinwan@google.com \
    --cc=git@vger.kernel.org \
    --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).