From: "Ævar Arnfjörð Bjarmason" <avarab@gmail.com>
To: git@vger.kernel.org
Cc: "Junio C Hamano" <gitster@pobox.com>, "Jeff King" <peff@peff.net>,
"Ævar Arnfjörð Bjarmason" <avarab@gmail.com>
Subject: [PATCH 3/5] tests: replace [de]packetize() shell+perl test-tool pkt-line
Date: Wed, 7 Jul 2021 12:21:47 +0200 [thread overview]
Message-ID: <patch-3.5-c1015fa6ab0-20210707T101549Z-avarab@gmail.com> (raw)
In-Reply-To: <cover-0.5-00000000000-20210707T101549Z-avarab@gmail.com>
The shell+perl "[de]packetize()" helper functions were added in
4414a150025 (t/lib-git-daemon: add network-protocol helpers,
2018-01-24), and around the same time we added the "pkt-line" helper
in 74e70029615 (test-pkt-line: introduce a packet-line test helper,
2018-03-14).
For some reason it seems we've mostly used the shell+perl version
instead of the helper since then. There were discussions around
88124ab2636 (test-lib-functions: make packetize() more efficient,
2020-03-27) and cacae4329fa (test-lib-functions: simplify packetize()
stdin code, 2020-03-29) to improve them and make them more efficient.
Let's instead just use the test helper, I think this results in both
more legible code, and for anyone who cares about efficiency it'll be
faster.
We can't convert all the users of packetize(), it has a feature the
test-tool is missing. This'll be addressed in the subsequent commit.
Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
---
t/t5410-receive-pack-alternates.sh | 42 ++++++++++++++++++--------
t/t5411/once-0010-report-status-v1.sh | 8 ++---
t/t5500-fetch-pack.sh | 15 +++++----
t/t5530-upload-pack-error.sh | 24 ++++++++-------
t/t5562-http-backend-content-length.sh | 13 ++++----
t/t5570-git-daemon.sh | 12 +++++---
t/t5704-protocol-violations.sh | 30 +++++++++---------
7 files changed, 86 insertions(+), 58 deletions(-)
diff --git a/t/t5410-receive-pack-alternates.sh b/t/t5410-receive-pack-alternates.sh
index 0b28e4e452f..d0053d95a44 100755
--- a/t/t5410-receive-pack-alternates.sh
+++ b/t/t5410-receive-pack-alternates.sh
@@ -16,10 +16,6 @@ test_expect_success 'setup' '
test_commit private
'
-extract_haves () {
- depacketize | perl -lne '/^(\S+) \.have/ and print $1'
-}
-
test_expect_success 'with core.alternateRefsCommand' '
write_script fork/alternate-refs <<-\EOF &&
git --git-dir="$1" for-each-ref \
@@ -27,18 +23,40 @@ test_expect_success 'with core.alternateRefsCommand' '
refs/heads/public/
EOF
test_config -C fork core.alternateRefsCommand ./alternate-refs &&
- git rev-parse public/branch >expect &&
- printf "0000" | git receive-pack fork >actual &&
- extract_haves <actual >actual.haves &&
- test_cmp expect actual.haves
+
+ test-tool pkt-line pack >in <<-\EOF &&
+ 0000
+ EOF
+
+ cat >expect <<-EOF &&
+ $(git rev-parse main) refs/heads/main
+ $(git rev-parse base) refs/tags/base
+ $(git rev-parse public) .have
+ 0000
+ EOF
+
+ git receive-pack fork >out <in &&
+ test-tool pkt-line unpack <out >actual &&
+ test_cmp expect actual
'
test_expect_success 'with core.alternateRefsPrefixes' '
test_config -C fork core.alternateRefsPrefixes "refs/heads/private" &&
- git rev-parse private/branch >expect &&
- printf "0000" | git receive-pack fork >actual &&
- extract_haves <actual >actual.haves &&
- test_cmp expect actual.haves
+
+ test-tool pkt-line pack >in <<-\EOF &&
+ 0000
+ EOF
+
+ cat >expect <<-EOF &&
+ $(git rev-parse main) refs/heads/main
+ $(git rev-parse base) refs/tags/base
+ $(git rev-parse private) .have
+ 0000
+ EOF
+
+ git receive-pack fork >out <in &&
+ test-tool pkt-line unpack <out >actual &&
+ test_cmp expect actual
'
test_done
diff --git a/t/t5411/once-0010-report-status-v1.sh b/t/t5411/once-0010-report-status-v1.sh
index 1233a46eac5..cf33d993192 100644
--- a/t/t5411/once-0010-report-status-v1.sh
+++ b/t/t5411/once-0010-report-status-v1.sh
@@ -34,13 +34,13 @@ test_expect_success "proc-receive: report status v1" '
$A $B | packetize
fi &&
printf "%s %s refs/for/main/topic1\n" \
- $ZERO_OID $A | packetize &&
+ $ZERO_OID $A | test-tool pkt-line pack &&
printf "%s %s refs/heads/foo\n" \
- $ZERO_OID $A | packetize &&
+ $ZERO_OID $A | test-tool pkt-line pack &&
printf "%s %s refs/for/next/topic\n" \
- $ZERO_OID $A | packetize &&
+ $ZERO_OID $A | test-tool pkt-line pack &&
printf "%s %s refs/for/main/topic2\n" \
- $ZERO_OID $A | packetize &&
+ $ZERO_OID $A | test-tool pkt-line pack &&
printf 0000 &&
printf "" | git -C "$upstream" pack-objects --stdout
} | git receive-pack "$upstream" --stateless-rpc \
diff --git a/t/t5500-fetch-pack.sh b/t/t5500-fetch-pack.sh
index 8a5d3492c71..ff0b7dd89f9 100755
--- a/t/t5500-fetch-pack.sh
+++ b/t/t5500-fetch-pack.sh
@@ -872,14 +872,17 @@ test_expect_success 'shallow since with commit graph and already-seen commit' '
git commit-graph write --reachable &&
git config core.commitGraph true &&
- GIT_PROTOCOL=version=2 git upload-pack . <<-EOF >/dev/null
- 0012command=fetch
- $(echo "object-format=$(test_oid algo)" | packetize)
- 00010013deepen-since 1
- $(echo "want $(git rev-parse other)" | packetize)
- $(echo "have $(git rev-parse main)" | packetize)
+ test-tool pkt-line pack >in <<-EOF &&
+ command=fetch
+ object-format=$(test_oid algo)
+ 0001
+ deepen-since 1
+ want $(git rev-parse other)
+ have $(git rev-parse main)
0000
EOF
+
+ GIT_PROTOCOL=version=2 git upload-pack . <in >/dev/null
)
'
diff --git a/t/t5530-upload-pack-error.sh b/t/t5530-upload-pack-error.sh
index 7c1460eaa99..8ccaae10475 100755
--- a/t/t5530-upload-pack-error.sh
+++ b/t/t5530-upload-pack-error.sh
@@ -90,18 +90,20 @@ test_expect_success 'upload-pack fails due to error in pack-objects enumeration'
test_expect_success 'upload-pack tolerates EOF just after stateless client wants' '
test_commit initial &&
- head=$(git rev-parse HEAD) &&
-
- {
- packetize "want $head" &&
- packetize "shallow $head" &&
- packetize "deepen 1" &&
- printf "0000"
- } >request &&
- printf "0000" >expect &&
-
- git upload-pack --stateless-rpc . <request >actual &&
+ head=$(git rev-parse HEAD) &&
+ test-tool pkt-line pack >request <<-EOF &&
+ want $head
+ shallow $head
+ deepen 1
+ 0000
+ EOF
+
+ cat >expect <<-\EOF &&
+ 0000
+ EOF
+ git upload-pack --stateless-rpc . <request >out &&
+ test-tool pkt-line unpack <out >actual &&
test_cmp expect actual
'
diff --git a/t/t5562-http-backend-content-length.sh b/t/t5562-http-backend-content-length.sh
index e5d3d15ba8d..e6c8338b648 100755
--- a/t/t5562-http-backend-content-length.sh
+++ b/t/t5562-http-backend-content-length.sh
@@ -53,12 +53,13 @@ test_expect_success 'setup' '
test_commit c1 &&
hash_head=$(git rev-parse HEAD) &&
hash_prev=$(git rev-parse HEAD~1) &&
- {
- packetize "want $hash_head" &&
- printf 0000 &&
- packetize "have $hash_prev" &&
- packetize "done"
- } >fetch_body &&
+ test-tool pkt-line pack >fetch_body <<-EOF &&
+ want $hash_head
+ 0000
+ have $hash_prev
+ done
+ 0000
+ EOF
test_copy_bytes 10 <fetch_body >fetch_body.trunc &&
hash_next=$(git commit-tree -p HEAD -m next HEAD^{tree}) &&
{
diff --git a/t/t5570-git-daemon.sh b/t/t5570-git-daemon.sh
index 82c31ab6cd8..2dde0348816 100755
--- a/t/t5570-git-daemon.sh
+++ b/t/t5570-git-daemon.sh
@@ -198,12 +198,14 @@ test_expect_success FAKENC 'hostname interpolation works after LF-stripping' '
printf "0000"
} >input &&
fake_nc "$GIT_DAEMON_HOST_PORT" <input >output &&
- depacketize <output >output.raw &&
+ test-tool pkt-line unpack <output >actual &&
+
+ cat >expect <<-EOF &&
+ $(git rev-parse HEAD) HEAD
+ $(git rev-parse refs/heads/main) refs/heads/main
+ 0000
+ EOF
- # just pick out the value of main, which avoids any protocol
- # particulars
- perl -lne "print \$1 if m{^(\\S+) refs/heads/main}" <output.raw >actual &&
- git -C "$repo" rev-parse main >expect &&
test_cmp expect actual
'
diff --git a/t/t5704-protocol-violations.sh b/t/t5704-protocol-violations.sh
index 038fffd3d03..44e2c0d3ded 100755
--- a/t/t5704-protocol-violations.sh
+++ b/t/t5704-protocol-violations.sh
@@ -7,13 +7,14 @@ making sure that we do not segfault or otherwise behave badly.'
. ./test-lib.sh
test_expect_success 'extra delim packet in v2 ls-refs args' '
- {
- packetize command=ls-refs &&
- packetize "object-format=$(test_oid algo)" &&
- printf 0001 &&
- # protocol expects 0000 flush here
- printf 0001
- } >input &&
+ # protocol expects 0000 flush after the 0001
+ test-tool pkt-line pack >input <<-EOF &&
+ command=ls-refs
+ object-format=$(test_oid algo)
+ 0001
+ 0001
+ EOF
+
cat >err.expect <<-\EOF &&
fatal: expected flush after ls-refs arguments
EOF
@@ -23,13 +24,14 @@ test_expect_success 'extra delim packet in v2 ls-refs args' '
'
test_expect_success 'extra delim packet in v2 fetch args' '
- {
- packetize command=fetch &&
- packetize "object-format=$(test_oid algo)" &&
- printf 0001 &&
- # protocol expects 0000 flush here
- printf 0001
- } >input &&
+ # protocol expects 0000 flush after the 0001
+ test-tool pkt-line pack >input <<-EOF &&
+ command=fetch
+ object-format=$(test_oid algo)
+ 0001
+ 0001
+ EOF
+
cat >err.expect <<-\EOF &&
fatal: expected flush after fetch arguments
EOF
--
2.32.0.636.g43e71d69cff
next prev parent reply other threads:[~2021-07-07 10:22 UTC|newest]
Thread overview: 33+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-07-07 10:21 [PATCH 0/5] tests: migrate to "test-tool pkt-line" Ævar Arnfjörð Bjarmason
2021-07-07 10:21 ` [PATCH 1/5] serve tests: add missing "extra delim" test Ævar Arnfjörð Bjarmason
2021-07-07 10:21 ` [PATCH 2/5] serve tests: use test_cmp in "protocol violations" test Ævar Arnfjörð Bjarmason
2021-07-07 10:21 ` Ævar Arnfjörð Bjarmason [this message]
2021-07-07 10:21 ` [PATCH 4/5] tests: replace remaining packetize() with "test-tool pkt-line" Ævar Arnfjörð Bjarmason
2021-07-07 10:21 ` [PATCH 5/5] test-lib-functions.sh: remove unused [de]packetize() functions Ævar Arnfjörð Bjarmason
2021-07-12 16:44 ` [PATCH v2 0/5] tests: migrate to "test-tool pkt-line" Ævar Arnfjörð Bjarmason
2021-07-12 16:44 ` [PATCH v2 1/5] serve tests: add missing "extra delim" test Ævar Arnfjörð Bjarmason
2021-07-12 16:44 ` [PATCH v2 2/5] serve tests: use test_cmp in "protocol violations" test Ævar Arnfjörð Bjarmason
2021-07-12 16:44 ` [PATCH v2 3/5] tests: replace [de]packetize() shell+perl test-tool pkt-line Ævar Arnfjörð Bjarmason
2021-07-13 20:50 ` Jeff King
2021-07-13 23:41 ` Ævar Arnfjörð Bjarmason
2021-07-14 1:12 ` Jeff King
2021-07-12 16:44 ` [PATCH v2 4/5] tests: replace remaining packetize() with "test-tool pkt-line" Ævar Arnfjörð Bjarmason
2021-07-13 20:58 ` Jeff King
2021-07-13 23:52 ` Ævar Arnfjörð Bjarmason
2021-07-14 1:16 ` Jeff King
2021-07-12 16:44 ` [PATCH v2 5/5] test-lib-functions.sh: remove unused [de]packetize() functions Ævar Arnfjörð Bjarmason
2021-07-12 20:41 ` [PATCH v2 0/5] tests: migrate to "test-tool pkt-line" Junio C Hamano
2021-07-13 21:00 ` Jeff King
2021-07-14 0:54 ` [PATCH v3 " Ævar Arnfjörð Bjarmason
2021-07-14 0:54 ` [PATCH v3 1/5] serve tests: add missing "extra delim" test Ævar Arnfjörð Bjarmason
2021-07-14 0:54 ` [PATCH v3 2/5] serve tests: use test_cmp in "protocol violations" test Ævar Arnfjörð Bjarmason
2021-07-14 0:54 ` [PATCH v3 3/5] tests: replace [de]packetize() shell+perl test-tool pkt-line Ævar Arnfjörð Bjarmason
2021-07-14 4:04 ` Taylor Blau
2021-07-14 16:22 ` Junio C Hamano
2021-07-14 0:54 ` [PATCH v3 4/5] tests: replace remaining packetize() with "test-tool pkt-line" Ævar Arnfjörð Bjarmason
2021-07-14 0:54 ` [PATCH v3 5/5] test-lib-functions.sh: remove unused [de]packetize() functions Ævar Arnfjörð Bjarmason
2021-07-16 15:41 ` [PATCH v4] test-lib-functions: use test-tool for [de]packetize() Ævar Arnfjörð Bjarmason
2021-07-16 16:53 ` Taylor Blau
2021-07-16 19:08 ` Jeff King
2021-07-16 19:03 ` Jeff King
2021-07-19 18:54 ` 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
List information: http://vger.kernel.org/majordomo-info.html
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=patch-3.5-c1015fa6ab0-20210707T101549Z-avarab@gmail.com \
--to=avarab@gmail.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=peff@peff.net \
/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.
Code repositories for project(s) associated with this public inbox
https://80x24.org/mirrors/git.git
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 read-only IMAP folder(s) and NNTP newsgroup(s).