From: "Ævar Arnfjörð Bjarmason" <avarab@gmail.com>
To: Taylor Blau <me@ttaylorr.com>
Cc: git@vger.kernel.org, Junio C Hamano <gitster@pobox.com>,
Jonathan Nieder <jrnieder@gmail.com>,
Jiang Xin <zhiyou.jx@alibaba-inc.com>
Subject: Re: [PATCH 2/2] bundle tests: use test_cmp instead of grep
Date: Thu, 22 Jul 2021 01:53:54 +0200 [thread overview]
Message-ID: <87fsw7ussi.fsf@evledraar.gmail.com> (raw)
In-Reply-To: <YPcE24InpY4evFyE@nand.local>
On Tue, Jul 20 2021, Taylor Blau wrote:
> On Tue, Jul 20, 2021 at 01:52:09PM +0200, Ævar Arnfjörð Bjarmason wrote:
>> So let's use test_cmp instead, and also in the other nearby tests
>> where it's easy.
>
> I took a look at this patch carefully to make sure that this
> transformation also improved the readability, too.
>
> Looking around, I think that this was a good improvement in readability,
> but also hardened the tests (for the reasons that you mentioned). One
> tiny note below.
>
>> test_expect_success 'empty bundle file is rejected' '
>> @@ -67,11 +83,33 @@ test_expect_success 'ridiculously long subject in boundary' '
>> printf "%01200d\n" 0 | git commit -F - &&
>> test_commit fifth &&
>> git bundle create long-subject-bundle.bdl HEAD^..HEAD &&
>> - git bundle list-heads long-subject-bundle.bdl >heads &&
>> - test -s heads &&
>> + cat >expect <<-EOF &&
>> + $(git rev-parse main) HEAD
>> + EOF
>> + git bundle list-heads long-subject-bundle.bdl >actual &&
>> + test_cmp expect actual &&
>
> This is quite readable, but the assertion below gets much more
> complicated as a result of the change.
>
>> git fetch long-subject-bundle.bdl &&
>> - sed -n "/^-/{p;q;}" long-subject-bundle.bdl >boundary &&
>> - grep "^-$OID_REGEX " boundary
>> +
>> + cat >expect.common <<-EOF &&
>> + -$(git log --pretty=format:"%H %s" -1 HEAD^)
>> + $(git rev-parse HEAD) HEAD
>> + EOF
>> + if test_have_prereq SHA1
>> + then
>> + cp expect.common expect
>> + else
>> + echo @object-format=sha256 >expect
>> + cat expect.common >>expect
>> + fi &&
>
> Here we're setting up expect, but I think flipping the order might make
> things a little easier to follow. Maybe something like this:
>
> rm expect &&
> if ! test_have_prereq SHA1
> then
> echo "@object-format=sha256" >expect
> fi &&
> cat >>expect <<-EOF &&
> -$(git log --pretty=format:"%H %s" -1 HEAD^)
> $(git rev-parse HEAD) HEAD
> EOF &&
Thanks, I used pretty much that as-is for v2.
> Or, if you wanted to go further, you could do something like:
>
> cat >expect <<-EOF
> $(test_have_prereq SHA1 || echo "@object-format=sha256")
> -$(git log --pretty=format:"%H %s" -1 HEAD^)
> $(git rev-parse HEAD) HEAD
> EOF
>
> which is arguably a little tighter (although I find the
> echo-in-a-heredoc thing to be kind of ugly).
This one won't work because you'll have an empty line at the start under
SHA-1.
>> + if test_have_prereq SHA1
>> + then
>> + head -n 3 long-subject-bundle.bdl >bundle-header
>> + else
>> + head -n 4 long-subject-bundle.bdl >bundle-header
>> + fi &&
>> + grep -v "^#" bundle-header >actual &&
>
> Here I would suggest getting rid of the bundle-header intermediary and
> instead writing:
>
> if test_have_prereq SHA1
> then
> head -n 3 long-subject-bundle.bdl
> else
> head -n 4 long-subject-bundle.bdl
> fi | grep -v "^#" >actual
>
> and then having your
Thanks, used that.
next prev parent reply other threads:[~2021-07-21 23:54 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-07-20 11:52 [PATCH 0/2] bundle tests: modernize, fix missing coverage & test_cmp Ævar Arnfjörð Bjarmason
2021-07-20 11:52 ` [PATCH 1/2] bundle tests: use ">file" not ": >file" Ævar Arnfjörð Bjarmason
2021-07-20 19:57 ` Junio C Hamano
2021-07-20 20:57 ` Felipe Contreras
2021-07-20 11:52 ` [PATCH 2/2] bundle tests: use test_cmp instead of grep Ævar Arnfjörð Bjarmason
2021-07-20 17:16 ` Taylor Blau
2021-07-21 23:53 ` Ævar Arnfjörð Bjarmason [this message]
2021-07-22 18:13 ` Taylor Blau
2021-07-20 17:18 ` [PATCH 0/2] bundle tests: modernize, fix missing coverage & test_cmp Taylor Blau
2021-07-21 23:53 ` [PATCH v2 " Ævar Arnfjörð Bjarmason
2021-07-21 23:53 ` [PATCH v2 1/2] bundle tests: use ">file" not ": >file" Ævar Arnfjörð Bjarmason
2021-07-21 23:53 ` [PATCH v2 2/2] bundle tests: use test_cmp instead of grep Ævar Arnfjörð Bjarmason
2021-07-22 18:17 ` Taylor Blau
2021-07-22 18:17 ` [PATCH v2 0/2] bundle tests: modernize, fix missing coverage & test_cmp Taylor Blau
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=87fsw7ussi.fsf@evledraar.gmail.com \
--to=avarab@gmail.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=jrnieder@gmail.com \
--cc=me@ttaylorr.com \
--cc=zhiyou.jx@alibaba-inc.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.