git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH v2 4/5] tests: replace remaining packetize() with "test-tool pkt-line"

From
Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Date
Jul 12, 2021, 16:44 UTC
Message-ID
<patch-4.5-a44e1790f2a-20210712T164208Z-avarab@gmail.com>
In-Reply-To
<cover-0.5-00000000000-20210712T164208Z-avarab@gmail.com>

Move the only remaining users of "packetize()" over to "test-tool pkt-line", for this we need a new "pack-raw-stdin" subcommand in the test-tool. The "pack" command takes input on stdin, but splits it by "\n", furthermore we'll format the output using C-strings, so the embedded "\0" being tested for here would cause the string to be truncated.

So we need another mode that just calls packet_write() on the raw input we got on stdin.

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
---
 t/helper/test-pkt-line.c               | 12 ++++++++++++
 t/t5411/once-0010-report-status-v1.sh  |  4 ++--
 t/t5562-http-backend-content-length.sh |  3 ++-
 t/t5570-git-daemon.sh                  | 10 ++++++----
 4 files changed, 22 insertions(+), 7 deletions(-)
diff --git a/t/helper/test-pkt-line.c b/t/helper/test-pkt-line.c
index 5e638f0b970..8563a0da4c5 100644
--- a/t/helper/test-pkt-line.c
+++ b/t/helper/test-pkt-line.c
@@ -26,6 +26,16 @@ static void pack(int argc, const char **argv)
 	}
 }
 
+static void pack_raw_stdin(void)
+{
+	struct strbuf sb = STRBUF_INIT;
+	strbuf_read(&sb, 0, 0);
+	if (strbuf_read(&sb, 0, 0) < 0)
+		die_errno("failed to read from stdin");
+	packet_write(1, sb.buf, sb.len);
+	strbuf_release(&sb);
+}
+
 static void unpack(void)
 {
 	struct packet_reader reader;
@@ -110,6 +120,8 @@ int cmd__pkt_line(int argc, const char **argv)
 
 	if (!strcmp(argv[1], "pack"))
 		pack(argc - 2, argv + 2);
+	else if (!strcmp(argv[1], "pack-raw-stdin"))
+		pack_raw_stdin();
 	else if (!strcmp(argv[1], "unpack"))
 		unpack();
 	else if (!strcmp(argv[1], "unpack-sideband"))
diff --git a/t/t5411/once-0010-report-status-v1.sh b/t/t5411/once-0010-report-status-v1.sh
index cf33d993192..75d4233e49f 100644
--- a/t/t5411/once-0010-report-status-v1.sh
+++ b/t/t5411/once-0010-report-status-v1.sh
@@ -28,10 +28,10 @@ test_expect_success "proc-receive: report status v1" '
 		if test -z "$GIT_DEFAULT_HASH" || test "$GIT_DEFAULT_HASH" = "sha1"
 		then
 			printf "%s %s refs/heads/main\0report-status\n" \
-				$A $B | packetize
+				$A $B | test-tool pkt-line pack-raw-stdin
 		else
 			printf "%s %s refs/heads/main\0report-status object-format=$GIT_DEFAULT_HASH\n" \
-				$A $B | packetize
+				$A $B | test-tool pkt-line pack-raw-stdin
 		fi &&
 		printf "%s %s refs/for/main/topic1\n" \
 			$ZERO_OID $A | test-tool pkt-line pack &&
diff --git a/t/t5562-http-backend-content-length.sh b/t/t5562-http-backend-content-length.sh
index e6c8338b648..23a8a8d5c70 100755
--- a/t/t5562-http-backend-content-length.sh
+++ b/t/t5562-http-backend-content-length.sh
@@ -64,7 +64,8 @@ test_expect_success 'setup' '
 	hash_next=$(git commit-tree -p HEAD -m next HEAD^{tree}) &&
 	{
 		printf "%s %s refs/heads/newbranch\\0report-status object-format=%s\\n" \
-			"$ZERO_OID" "$hash_next" "$(test_oid algo)" | packetize &&
+			"$ZERO_OID" "$hash_next" "$(test_oid algo)" |
+			test-tool pkt-line pack-raw-stdin &&
 		printf 0000 &&
 		echo "$hash_next" | git pack-objects --stdout
 	} >push_body &&
diff --git a/t/t5570-git-daemon.sh b/t/t5570-git-daemon.sh
index 2dde0348816..b52afb0cdea 100755
--- a/t/t5570-git-daemon.sh
+++ b/t/t5570-git-daemon.sh
@@ -193,10 +193,12 @@ test_expect_success 'hostname cannot break out of directory' '
 '
 
 test_expect_success FAKENC 'hostname interpolation works after LF-stripping' '
-	{
-		printf "git-upload-pack /interp.git\n\0host=localhost" | packetize
-		printf "0000"
-	} >input &&
+	printf "git-upload-pack /interp.git\n\0host=localhost" >has-null &&
+	test-tool pkt-line pack-raw-stdin >input <has-null &&
+	test-tool pkt-line pack >>input <<-\EOF &&
+	0000
+	EOF
+
 	fake_nc "$GIT_DAEMON_HOST_PORT" <input >output &&
 	test-tool pkt-line unpack <output >actual &&
 
-- 
2.32.0-dev
Previous: Jeff KingNext: Jeff King
Message 14 of 33 in “tests: migrate to "test-tool pkt-line"”
  1. 0/5 tests: migrate to "test-tool pkt-line"Ævar Arnfjörð Bjarmason, Jul 7, 2021
  2. 1/5 serve tests: add missing "extra delim" testÆvar Arnfjörð Bjarmason, Jul 7, 2021
  3. 2/5 serve tests: use test_cmp in "protocol violations" testÆvar Arnfjörð Bjarmason, Jul 7, 2021
  4. 3/5 tests: replace [de]packetize() shell+perl test-tool pkt-lineÆvar Arnfjörð Bjarmason, Jul 7, 2021
  5. 4/5 tests: replace remaining packetize() with "test-tool pkt-line"Ævar Arnfjörð Bjarmason, Jul 7, 2021
  6. 5/5 test-lib-functions.sh: remove unused [de]packetize() functionsÆvar Arnfjörð Bjarmason, Jul 7, 2021
  7. 0/5 tests: migrate to "test-tool pkt-line"Ævar Arnfjörð Bjarmason, Jul 12, 2021
  8. 1/5 serve tests: add missing "extra delim" testÆvar Arnfjörð Bjarmason, Jul 12, 2021
  9. 2/5 serve tests: use test_cmp in "protocol violations" testÆvar Arnfjörð Bjarmason, Jul 12, 2021
  10. 3/5 tests: replace [de]packetize() shell+perl test-tool pkt-lineÆvar Arnfjörð Bjarmason, Jul 12, 2021
  11. Jeff KingJul 13, 2021
  12. Ævar Arnfjörð BjarmasonJul 13, 2021
  13. Jeff KingJul 14, 2021
  14. 4/5 tests: replace remaining packetize() with "test-tool pkt-line"Ævar Arnfjörð Bjarmason, Jul 12, 2021
  15. Jeff KingJul 13, 2021
  16. Ævar Arnfjörð BjarmasonJul 13, 2021
  17. Jeff KingJul 14, 2021
  18. 5/5 test-lib-functions.sh: remove unused [de]packetize() functionsÆvar Arnfjörð Bjarmason, Jul 12, 2021
  19. Junio C HamanoJul 12, 2021
  20. Jeff KingJul 13, 2021
  21. 0/5 tests: migrate to "test-tool pkt-line"Ævar Arnfjörð Bjarmason, Jul 14, 2021
  22. 1/5 serve tests: add missing "extra delim" testÆvar Arnfjörð Bjarmason, Jul 14, 2021
  23. 3/5 tests: replace [de]packetize() shell+perl test-tool pkt-lineÆvar Arnfjörð Bjarmason, Jul 14, 2021
  24. Taylor BlauJul 14, 2021
  25. Junio C HamanoJul 14, 2021
  26. 2/5 serve tests: use test_cmp in "protocol violations" testÆvar Arnfjörð Bjarmason, Jul 14, 2021
  27. 4/5 tests: replace remaining packetize() with "test-tool pkt-line"Ævar Arnfjörð Bjarmason, Jul 14, 2021
  28. 5/5 test-lib-functions.sh: remove unused [de]packetize() functionsÆvar Arnfjörð Bjarmason, Jul 14, 2021
  29. test-lib-functions: use test-tool for [de]packetize()Ævar Arnfjörð Bjarmason, Jul 16, 2021
  30. Taylor BlauJul 16, 2021
  31. Jeff KingJul 16, 2021
  32. Jeff KingJul 16, 2021
  33. Junio C HamanoJul 19, 2021

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.