A trivial series to improve the bundle tests a bit. This is split off
from some larger changes to "git bundle" I have cooking, where the
"test_cmp" in 2/2 helped assert & catch regressions.
Ævar Arnfjörð Bjarmason (2):
bundle tests: use ">file" not ": >file"
bundle tests: use test_cmp instead of grep
t/t5607-clone-bundle.sh | 74 ++++++++++++++++++++++++++++++++---------
1 file changed, 58 insertions(+), 16 deletions(-)
--
2.32.0.874.ge7a9d58bfcf
Change redundant uses of ":" on the LHS of a ">" to the more commonly
use ">file" pattern.
Signed-off-by: Ævar Arnfjörð Bjarmason <redacted>
---
t/t5607-clone-bundle.sh | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
@@ -54,14 +54,14 @@ test_expect_success 'bundle --stdin <rev-list options>' '' test_expect_success'empty bundle file is rejected''-:>empty-bundle&&+>empty-bundle&&test_must_failgitfetchempty-bundle'# This triggers a bug in older versions where the resulting line (with# --pretty=oneline) was longer than a 1024-char buffer. test_expect_success'ridiculously long subject in boundary''-:>file4&&+>file4&&test_tick&&gitaddfile4&&printf"%01200d\n"0|gitcommit-F-&&
@@ -75,7 +75,7 @@ test_expect_success 'ridiculously long subject in boundary' '' test_expect_success'prerequisites with an empty commit message''-:>file1&&+>file1&&gitaddfile1&&test_tick&&gitcommit--allow-empty-message-m""&&
Change the bundle tests to fully compare the expected "git ls-remote"
or "git bundle list-heads" output, instead of merely grepping it.
This avoids subtle regressions in the tests. In
f62e0a39b6 (t5704 (bundle): add tests for bundle --stdin, 2010-04-19)
the "bundle --stdin <rev-list options>" test was added to make sure we
didn't include the tag.
But since the --stdin mode didn't work until 5bb0fd2cab (bundle:
arguments can be read from stdin, 2021-01-11) our grepping of
"master" (later "main") missed the important part of the test.
Namely that we should not include the "refs/tags/tag" tag in that
case. Since the test only grepped for "main" in the output we'd miss a
regression in that code.
So let's use test_cmp instead, and also in the other nearby tests
where it's easy.
This does make things a bit more verbose in the case of the test
that's checking the bundle header, since it's different under SHA1 and
SHA256. I think this makes test easier to follow.
I've got some WIP changes to extend the "git bundle" command to dump
parts of the header out, which are easier to understand if we test the
output explicitly like this.
Signed-off-by: Ævar Arnfjörð Bjarmason <redacted>
---
t/t5607-clone-bundle.sh | 68 +++++++++++++++++++++++++++++++++--------
1 file changed, 55 insertions(+), 13 deletions(-)
@@ -29,11 +29,21 @@ test_expect_success '"verify" needs a worktree' ' test_expect_success'annotated tags can be excluded by rev-list options''gitbundlecreatebundle--all--since=7.Apr.2005.15:14:00.-0700&&-gitls-remotebundle>output&&-greptagoutput&&+cat>expect<<-EOF&&+$(gitrev-parseHEAD)HEAD+$(gitrev-parsetag)refs/tags/tag+$(gitrev-parsemain)refs/heads/main+EOF+gitls-remotebundle>actual&&+test_cmpexpectactual&&+gitbundlecreatebundle--all--since=7.Apr.2005.15:16:00.-0700&&-gitls-remotebundle>output&&-!greptagoutput+cat>expect<<-EOF&&+$(gitrev-parseHEAD)HEAD+$(gitrev-parsemain)refs/heads/main+EOF+gitls-remotebundle>actual&&+test_cmpexpectactual' test_expect_success'die if bundle file cannot be created''
@@ -43,14 +53,20 @@ test_expect_success 'die if bundle file cannot be created' ' test_expect_success'bundle --stdin''echomain|gitbundlecreatestdin-bundle.bdl--stdin&&-gitls-remotestdin-bundle.bdl>output&&-grepmainoutput+cat>expect<<-EOF&&+$(gitrev-parsemain)refs/heads/main+EOF+gitls-remotestdin-bundle.bdl>actual&&+test_cmpexpectactual' test_expect_success'bundle --stdin <rev-list options>''echomain|gitbundlecreatehybrid-bundle.bdl--stdintag&&-gitls-remotehybrid-bundle.bdl>output&&-grepmainoutput+cat>expect<<-EOF&&+$(gitrev-parsemain)refs/heads/main+EOF+gitls-remotestdin-bundle.bdl>actual&&+test_cmpexpectactual' test_expect_success'empty bundle file is rejected''
@@ -67,11 +83,33 @@ test_expect_success 'ridiculously long subject in boundary' 'printf"%01200d\n"0|gitcommit-F-&&test_commitfifth&&gitbundlecreatelong-subject-bundle.bdlHEAD^..HEAD&&-gitbundlelist-headslong-subject-bundle.bdl>heads&&-test-sheads&&+cat>expect<<-EOF&&+$(gitrev-parsemain)HEAD+EOF+gitbundlelist-headslong-subject-bundle.bdl>actual&&+test_cmpexpectactual&&+gitfetchlong-subject-bundle.bdl&&-sed-n"/^-/{p;q;}"long-subject-bundle.bdl>boundary&&-grep"^-$OID_REGEX "boundary++cat>expect.common<<-EOF&&+-$(gitlog--pretty=format:"%H %s"-1HEAD^)+$(gitrev-parseHEAD)HEAD+EOF+iftest_have_prereqSHA1+then+cpexpect.commonexpect+else+echo@object-format=sha256>expect+catexpect.common>>expect+fi&&+iftest_have_prereqSHA1+then+head-n3long-subject-bundle.bdl>bundle-header+else+head-n4long-subject-bundle.bdl>bundle-header+fi&&+grep-v"^#"bundle-header>actual&&+test_cmpexpectactual' test_expect_success'prerequisites with an empty commit message''
From: Taylor Blau <hidden> Date: 2021-07-20 17:16:33
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.
quoted hunk
test_expect_success 'empty bundle file is rejected' '
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 &&
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).
+ 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
From: Taylor Blau <hidden> Date: 2021-07-20 17:20:25
On Tue, Jul 20, 2021 at 01:52:07PM +0200, Ævar Arnfjörð Bjarmason wrote:
A trivial series to improve the bundle tests a bit. This is split off
from some larger changes to "git bundle" I have cooking, where the
"test_cmp" in 2/2 helped assert & catch regressions.
Thanks. Both patches looked good to me, and I left a couple of minor
suggestions on the latter patch to potentially clean things up a little
bit.
But please feel free to ignore them, and only pick them up if you feel
they do improve the readability. Since I would be happy to see this
picked up as-is, it has my:
Reviewed-by: Taylor Blau [off-list ref]
Thanks,
Taylor
From: Felipe Contreras <hidden> Date: 2021-07-20 21:03:53
Ævar Arnfjörð Bjarmason wrote:
Change redundant uses of ":" on the LHS of a ">" to the more commonly
use ">file" pattern.
While this is redundant in bash, it's not redundant in zsh.
Probably not a big deal since I don't think the test suite can run in
zsh right now, but it's taking us on the opposite direction.
--
Felipe Contreras
A trivial series to improve the bundle tests a bit. This is split off
from some larger changes to "git bundle" I have cooking, where the
"test_cmp" in 2/2 helped assert & catch regressions.
Ævar Arnfjörð Bjarmason (2):
bundle tests: use ">file" not ": >file"
bundle tests: use test_cmp instead of grep
t/t5607-clone-bundle.sh | 72 ++++++++++++++++++++++++++++++++---------
1 file changed, 56 insertions(+), 16 deletions(-)
Range-diff against v1:
1: 746d727113b ! 1: 2a77f80725d bundle tests: use ">file" not ": >file"
@@ Metadata
## Commit message ##
bundle tests: use ">file" not ": >file"
- Change redundant uses of ":" on the LHS of a ">" to the more commonly
- use ">file" pattern.
+ Change uses of ":" on the LHS of a ">" to the more commonly used
+ ">file" pattern in t/t5607-clone-bundle.sh.
Signed-off-by: Ævar Arnfjörð Bjarmason [off-list ref]
2: 062f34abf1a ! 2: d5504fd764c bundle tests: use test_cmp instead of grep
@@ t/t5607-clone-bundle.sh: test_expect_success 'ridiculously long subject in bound
- sed -n "/^-/{p;q;}" long-subject-bundle.bdl >boundary &&
- grep "^-$OID_REGEX " boundary
+
-+ cat >expect.common <<-EOF &&
++ if ! test_have_prereq SHA1
++ then
++ echo "@object-format=sha256"
++ fi >expect &&
++ cat >>expect <<-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 &&
-+ if test_have_prereq SHA1
-+ then
-+ head -n 3 long-subject-bundle.bdl >bundle-header
++ head -n 3 long-subject-bundle.bdl
+ else
-+ head -n 4 long-subject-bundle.bdl >bundle-header
-+ fi &&
-+ grep -v "^#" bundle-header >actual &&
++ head -n 4 long-subject-bundle.bdl
++ fi | grep -v "^#" >actual &&
++
+ test_cmp expect actual
'
--
2.32.0.955.ge7c5360f7e7
Change uses of ":" on the LHS of a ">" to the more commonly used
">file" pattern in t/t5607-clone-bundle.sh.
Signed-off-by: Ævar Arnfjörð Bjarmason <redacted>
---
t/t5607-clone-bundle.sh | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
@@ -54,14 +54,14 @@ test_expect_success 'bundle --stdin <rev-list options>' '' test_expect_success'empty bundle file is rejected''-:>empty-bundle&&+>empty-bundle&&test_must_failgitfetchempty-bundle'# This triggers a bug in older versions where the resulting line (with# --pretty=oneline) was longer than a 1024-char buffer. test_expect_success'ridiculously long subject in boundary''-:>file4&&+>file4&&test_tick&&gitaddfile4&&printf"%01200d\n"0|gitcommit-F-&&
@@ -75,7 +75,7 @@ test_expect_success 'ridiculously long subject in boundary' '' test_expect_success'prerequisites with an empty commit message''-:>file1&&+>file1&&gitaddfile1&&test_tick&&gitcommit--allow-empty-message-m""&&
Change the bundle tests to fully compare the expected "git ls-remote"
or "git bundle list-heads" output, instead of merely grepping it.
This avoids subtle regressions in the tests. In
f62e0a39b6 (t5704 (bundle): add tests for bundle --stdin, 2010-04-19)
the "bundle --stdin <rev-list options>" test was added to make sure we
didn't include the tag.
But since the --stdin mode didn't work until 5bb0fd2cab (bundle:
arguments can be read from stdin, 2021-01-11) our grepping of
"master" (later "main") missed the important part of the test.
Namely that we should not include the "refs/tags/tag" tag in that
case. Since the test only grepped for "main" in the output we'd miss a
regression in that code.
So let's use test_cmp instead, and also in the other nearby tests
where it's easy.
This does make things a bit more verbose in the case of the test
that's checking the bundle header, since it's different under SHA1 and
SHA256. I think this makes test easier to follow.
I've got some WIP changes to extend the "git bundle" command to dump
parts of the header out, which are easier to understand if we test the
output explicitly like this.
Signed-off-by: Ævar Arnfjörð Bjarmason <redacted>
---
t/t5607-clone-bundle.sh | 66 +++++++++++++++++++++++++++++++++--------
1 file changed, 53 insertions(+), 13 deletions(-)
@@ -29,11 +29,21 @@ test_expect_success '"verify" needs a worktree' ' test_expect_success'annotated tags can be excluded by rev-list options''gitbundlecreatebundle--all--since=7.Apr.2005.15:14:00.-0700&&-gitls-remotebundle>output&&-greptagoutput&&+cat>expect<<-EOF&&+$(gitrev-parseHEAD)HEAD+$(gitrev-parsetag)refs/tags/tag+$(gitrev-parsemain)refs/heads/main+EOF+gitls-remotebundle>actual&&+test_cmpexpectactual&&+gitbundlecreatebundle--all--since=7.Apr.2005.15:16:00.-0700&&-gitls-remotebundle>output&&-!greptagoutput+cat>expect<<-EOF&&+$(gitrev-parseHEAD)HEAD+$(gitrev-parsemain)refs/heads/main+EOF+gitls-remotebundle>actual&&+test_cmpexpectactual' test_expect_success'die if bundle file cannot be created''
@@ -43,14 +53,20 @@ test_expect_success 'die if bundle file cannot be created' ' test_expect_success'bundle --stdin''echomain|gitbundlecreatestdin-bundle.bdl--stdin&&-gitls-remotestdin-bundle.bdl>output&&-grepmainoutput+cat>expect<<-EOF&&+$(gitrev-parsemain)refs/heads/main+EOF+gitls-remotestdin-bundle.bdl>actual&&+test_cmpexpectactual' test_expect_success'bundle --stdin <rev-list options>''echomain|gitbundlecreatehybrid-bundle.bdl--stdintag&&-gitls-remotehybrid-bundle.bdl>output&&-grepmainoutput+cat>expect<<-EOF&&+$(gitrev-parsemain)refs/heads/main+EOF+gitls-remotestdin-bundle.bdl>actual&&+test_cmpexpectactual' test_expect_success'empty bundle file is rejected''
@@ -67,11 +83,31 @@ test_expect_success 'ridiculously long subject in boundary' 'printf"%01200d\n"0|gitcommit-F-&&test_commitfifth&&gitbundlecreatelong-subject-bundle.bdlHEAD^..HEAD&&-gitbundlelist-headslong-subject-bundle.bdl>heads&&-test-sheads&&+cat>expect<<-EOF&&+$(gitrev-parsemain)HEAD+EOF+gitbundlelist-headslong-subject-bundle.bdl>actual&&+test_cmpexpectactual&&+gitfetchlong-subject-bundle.bdl&&-sed-n"/^-/{p;q;}"long-subject-bundle.bdl>boundary&&-grep"^-$OID_REGEX "boundary++if!test_have_prereqSHA1+then+echo"@object-format=sha256"+fi>expect&&+cat>>expect<<-EOF&&+-$(gitlog--pretty=format:"%H %s"-1HEAD^)+$(gitrev-parseHEAD)HEAD+EOF++iftest_have_prereqSHA1+then+head-n3long-subject-bundle.bdl+else+head-n4long-subject-bundle.bdl+fi|grep-v"^#">actual&&++test_cmpexpectactual' test_expect_success'prerequisites with an empty commit message''
On Tue, Jul 20, 2021 at 01:52:09PM +0200, Ævar Arnfjörð Bjarmason wrote:
quoted
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.
quoted
test_expect_success 'empty bundle file is rejected' '
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.
quoted
+ 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
From: Taylor Blau <hidden> Date: 2021-07-22 18:20:23
On Thu, Jul 22, 2021 at 01:53:54AM +0200, Ævar Arnfjörð Bjarmason wrote:
quoted
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.
Ah, you're totally right: good catch. I think it's avoidable by smashing
the first two lines into one. If the subshell prints nothing, then the
first line will start with "-$(git log ...)", otherwise, if it does
print something, then the echo will print a newline to separate it from
the "-$(git log ...) output which will go on the second line.
But that is definitely uglier than my first suggestion, so I'm glad that
you didn't try and make what I wrote above work :).
Thanks,
Taylor
From: Taylor Blau <hidden> Date: 2021-07-22 18:20:23
On Thu, Jul 22, 2021 at 01:53:27AM +0200, Ævar Arnfjörð Bjarmason wrote:
A trivial series to improve the bundle tests a bit. This is split off
from some larger changes to "git bundle" I have cooking, where the
"test_cmp" in 2/2 helped assert & catch regressions.
Thanks, this version looks great to me, so I'd be happy to see it get
picked up.
Reviewed-by: Taylor Blau [off-list ref]
Thanks,
Taylor
From: Taylor Blau <hidden> Date: 2021-07-22 18:20:23
On Thu, Jul 22, 2021 at 01:53:29AM +0200, Ævar Arnfjörð Bjarmason wrote:
Change the bundle tests to fully compare the expected "git ls-remote"
or "git bundle list-heads" output, instead of merely grepping it.
Thanks; this version makes all of those tests more readable. I did have
one idle thought while reading, but what you wrote is right (so I'm just
thinking out loud as opposed to anything else).
- sed -n "/^-/{p;q;}" long-subject-bundle.bdl >boundary &&
- grep "^-$OID_REGEX " boundary
+
+ if ! test_have_prereq SHA1
+ then
+ echo "@object-format=sha256"
+ fi >expect &&
+ cat >>expect <<-EOF &&
On my first read, I worried that this 'cat >>expect' when we're in
SHA-1 mode would append to the 'expect' we generated a few lines up. But
it doesn't, since we redirect the output of the 'if' statement into
'expect' instead of doing the redirect attached to the echo.
Subtle, but that's right. Good.
Thanks,
Taylor