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

[PATCH 15/20] t9300: make the cat-blob tests self-contained

From
Karthik Nayak <karthik.188@gmail.com>
Date
Nov 10, 2026, 11:50 UTC
Message-ID
<20261110-kn-fast-import-tests-1-v1-15-dbd9ee502aae@gmail.com>
In-Reply-To
<20261110-kn-fast-import-tests-1-v1-0-dbd9ee502aae@gmail.com>

The 'R: print' tests and 'R: copy using cat-file' write blobs into the repository of the trash directory, which all other tests share. 'R: print two blobs to stdout' and 'R: copy using cat-file' also read the 'big' file written by the preceding 'setup: big file' test, so they can't run on their own.

Run each of these tests in a new repository. Convert the setup test to a 'setup_big_file()' function, which writes the file in the repository of the calling test, and invoke it from both tests.

Signed-off-by: Karthik Nayak <karthik.188@gmail.com>
---
 t/t9300-fast-import.sh | 428 ++++++++++++++++++++++++++++---------------------
 1 file changed, 242 insertions(+), 186 deletions(-)
diff --git a/t/t9300-fast-import.sh b/t/t9300-fast-import.sh
index 04c3bfe0c1..3f0e7b8b1f 100755
--- a/t/t9300-fast-import.sh
+++ b/t/t9300-fast-import.sh
@@ -2983,87 +2983,117 @@ test_expect_success 'R: cat-blob-fd must be a nonnegative integer' '
 '
 
 test_expect_success !MINGW 'R: print old blob' '
-	blob=$(echo "yes it can" | git hash-object -w --stdin) &&
-	cat >expect <<-EOF &&
-	${blob} blob 11
-	yes it can
+	test_when_finished "rm -rf repo" &&
+	git init repo &&
+	(
+		cd repo &&
 
-	EOF
-	echo "cat-blob $blob" |
-	git fast-import --cat-blob-fd=6 6>actual &&
-	test_cmp expect actual
+		blob=$(echo "yes it can" | git hash-object -w --stdin) &&
+		cat >expect <<-EOF &&
+		${blob} blob 11
+		yes it can
+
+		EOF
+		echo "cat-blob $blob" |
+		git fast-import --cat-blob-fd=6 6>actual &&
+		test_cmp expect actual
+	)
 '
 
 test_expect_success !MINGW 'R: in-stream cat-blob-fd not respected' '
-	echo hello >greeting &&
-	blob=$(git hash-object -w greeting) &&
-	cat >expect <<-EOF &&
-	${blob} blob 6
-	hello
+	test_when_finished "rm -rf repo" &&
+	git init repo &&
+	(
+		cd repo &&
 
-	EOF
-	git fast-import --cat-blob-fd=3 3>actual.3 >actual.1 <<-EOF &&
-	cat-blob $blob
-	EOF
-	test_cmp expect actual.3 &&
-	test_must_be_empty actual.1 &&
-	git fast-import 3>actual.3 >actual.1 <<-EOF &&
-	option cat-blob-fd=3
-	cat-blob $blob
-	EOF
-	test_must_be_empty actual.3 &&
-	test_cmp expect actual.1
+		echo hello >greeting &&
+		blob=$(git hash-object -w greeting) &&
+		cat >expect <<-EOF &&
+		${blob} blob 6
+		hello
+
+		EOF
+		git fast-import --cat-blob-fd=3 3>actual.3 >actual.1 <<-EOF &&
+		cat-blob $blob
+		EOF
+		test_cmp expect actual.3 &&
+		test_must_be_empty actual.1 &&
+		git fast-import 3>actual.3 >actual.1 <<-EOF &&
+		option cat-blob-fd=3
+		cat-blob $blob
+		EOF
+		test_must_be_empty actual.3 &&
+		test_cmp expect actual.1
+	)
 '
 
 test_expect_success !MINGW 'R: print mark for new blob' '
-	echo "effluentish" | git hash-object --stdin >expect &&
-	git fast-import --cat-blob-fd=6 6>actual <<-\EOF &&
-	blob
-	mark :1
-	data <<BLOB_END
-	effluentish
-	BLOB_END
-	get-mark :1
-	EOF
-	test_cmp expect actual
+	test_when_finished "rm -rf repo" &&
+	git init repo &&
+	(
+		cd repo &&
+
+		echo "effluentish" | git hash-object --stdin >expect &&
+		git fast-import --cat-blob-fd=6 6>actual <<-\EOF &&
+		blob
+		mark :1
+		data <<BLOB_END
+		effluentish
+		BLOB_END
+		get-mark :1
+		EOF
+		test_cmp expect actual
+	)
 '
 
 test_expect_success !MINGW 'R: print new blob' '
-	blob=$(echo "yep yep yep" | git hash-object --stdin) &&
-	cat >expect <<-EOF &&
-	${blob} blob 12
-	yep yep yep
+	test_when_finished "rm -rf repo" &&
+	git init repo &&
+	(
+		cd repo &&
 
-	EOF
-	git fast-import --cat-blob-fd=6 6>actual <<-\EOF &&
-	blob
-	mark :1
-	data <<BLOB_END
-	yep yep yep
-	BLOB_END
-	cat-blob :1
-	EOF
-	test_cmp expect actual
+		blob=$(echo "yep yep yep" | git hash-object --stdin) &&
+		cat >expect <<-EOF &&
+		${blob} blob 12
+		yep yep yep
+
+		EOF
+		git fast-import --cat-blob-fd=6 6>actual <<-\EOF &&
+		blob
+		mark :1
+		data <<BLOB_END
+		yep yep yep
+		BLOB_END
+		cat-blob :1
+		EOF
+		test_cmp expect actual
+	)
 '
 
 test_expect_success !MINGW 'R: print new blob by sha1' '
-	blob=$(echo "a new blob named by sha1" | git hash-object --stdin) &&
-	cat >expect <<-EOF &&
-	${blob} blob 25
-	a new blob named by sha1
+	test_when_finished "rm -rf repo" &&
+	git init repo &&
+	(
+		cd repo &&
 
-	EOF
-	git fast-import --cat-blob-fd=6 6>actual <<-EOF &&
-	blob
-	data <<BLOB_END
-	a new blob named by sha1
-	BLOB_END
-	cat-blob $blob
-	EOF
-	test_cmp expect actual
+		blob=$(echo "a new blob named by sha1" | git hash-object --stdin) &&
+		cat >expect <<-EOF &&
+		${blob} blob 25
+		a new blob named by sha1
+
+		EOF
+		git fast-import --cat-blob-fd=6 6>actual <<-EOF &&
+		blob
+		data <<BLOB_END
+		a new blob named by sha1
+		BLOB_END
+		cat-blob $blob
+		EOF
+		test_cmp expect actual
+	)
 '
 
-test_expect_success 'setup: big file' '
+setup_big_file () {
 	(
 		echo "the quick brown fox jumps over the lazy dog" >big &&
 		for i in 1 2 3
@@ -3073,153 +3103,179 @@ test_expect_success 'setup: big file' '
 			exit
 		done
 	)
-'
+}
 
 test_expect_success 'R: print two blobs to stdout' '
-	blob1=$(git hash-object big) &&
-	blob1_len=$(wc -c <big) &&
-	blob2=$(echo hello | git hash-object --stdin) &&
-	{
-		echo ${blob1} blob $blob1_len &&
-		cat big &&
-		cat <<-EOF
+	test_when_finished "rm -rf repo" &&
+	git init repo &&
+	(
+		cd repo &&
 
-		${blob2} blob 6
-		hello
+		setup_big_file &&
+		blob1=$(git hash-object big) &&
+		blob1_len=$(wc -c <big) &&
+		blob2=$(echo hello | git hash-object --stdin) &&
+		{
+			echo ${blob1} blob $blob1_len &&
+			cat big &&
+			cat <<-EOF
 
-		EOF
-	} >expect &&
-	{
-		cat <<-\END_PART1 &&
-			blob
-			mark :1
-			data <<data_end
-		END_PART1
-		cat big &&
-		cat <<-\EOF
-			data_end
-			blob
-			mark :2
-			data <<data_end
+			${blob2} blob 6
 			hello
-			data_end
-			cat-blob :1
-			cat-blob :2
-		EOF
-	} |
-	git fast-import >actual &&
-	test_cmp expect actual
+
+			EOF
+		} >expect &&
+		{
+			cat <<-\END_PART1 &&
+				blob
+				mark :1
+				data <<data_end
+			END_PART1
+			cat big &&
+			cat <<-\EOF
+				data_end
+				blob
+				mark :2
+				data <<data_end
+				hello
+				data_end
+				cat-blob :1
+				cat-blob :2
+			EOF
+		} |
+		git fast-import >actual &&
+		test_cmp expect actual
+	)
 '
 
 test_expect_success PIPE 'R: copy using cat-file' '
-	expect_id=$(git hash-object big) &&
-	expect_len=$(wc -c <big) &&
-	echo $expect_id blob $expect_len >expect.response &&
-
-	rm -f blobs &&
-
-	mkfifo blobs &&
+	test_when_finished "rm -rf repo" &&
+	git init repo &&
 	(
-		export GIT_COMMITTER_NAME GIT_COMMITTER_EMAIL GIT_COMMITTER_DATE &&
-		cat <<-\EOF &&
-		feature cat-blob
-		blob
-		mark :1
-		data <<BLOB
-		EOF
-		cat big &&
-		cat <<-\EOF &&
-		BLOB
-		cat-blob :1
-		EOF
+		cd repo &&
 
-		read blob_id type size <&3 &&
-		echo "$blob_id $type $size" >response &&
-		test_copy_bytes $size >blob <&3 &&
-		read newline <&3 &&
+		setup_big_file &&
+		expect_id=$(git hash-object big) &&
+		expect_len=$(wc -c <big) &&
+		echo $expect_id blob $expect_len >expect.response &&
 
-		cat <<-EOF &&
-		commit refs/heads/copied
-		committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
-		data <<COMMIT
-		copy big file as file3
-		COMMIT
-		M 644 inline file3
-		data <<BLOB
-		EOF
-		cat blob &&
-		echo BLOB
-	) 3<blobs |
-	git fast-import --cat-blob-fd=3 3>blobs &&
-	git show copied:file3 >actual &&
-	test_cmp expect.response response &&
-	test_cmp big actual
+		rm -f blobs &&
+
+		mkfifo blobs &&
+		(
+			export GIT_COMMITTER_NAME GIT_COMMITTER_EMAIL GIT_COMMITTER_DATE &&
+			cat <<-\EOF &&
+			feature cat-blob
+			blob
+			mark :1
+			data <<BLOB
+			EOF
+			cat big &&
+			cat <<-\EOF &&
+			BLOB
+			cat-blob :1
+			EOF
+
+			read blob_id type size <&3 &&
+			echo "$blob_id $type $size" >response &&
+			test_copy_bytes $size >blob <&3 &&
+			read newline <&3 &&
+
+			cat <<-EOF &&
+			commit refs/heads/copied
+			committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
+			data <<COMMIT
+			copy big file as file3
+			COMMIT
+			M 644 inline file3
+			data <<BLOB
+			EOF
+			cat blob &&
+			echo BLOB
+		) 3<blobs |
+		git fast-import --cat-blob-fd=3 3>blobs &&
+		git show copied:file3 >actual &&
+		test_cmp expect.response response &&
+		test_cmp big actual
+	)
 '
 
 test_expect_success PIPE 'R: print blob mid-commit' '
-	rm -f blobs &&
-	echo "A blob from _before_ the commit." >expect &&
-	mkfifo blobs &&
+	test_when_finished "rm -rf repo" &&
+	git init repo &&
 	(
-		exec 3<blobs &&
-		cat <<-EOF &&
-		feature cat-blob
-		blob
-		mark :1
-		data <<BLOB
-		A blob from _before_ the commit.
-		BLOB
-		commit refs/heads/temporary
-		committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
-		data <<COMMIT
-		Empty commit
-		COMMIT
-		cat-blob :1
-		EOF
+		cd repo &&
 
-		read blob_id type size <&3 &&
-		test_copy_bytes $size >actual <&3 &&
-		read newline <&3 &&
+		rm -f blobs &&
+		echo "A blob from _before_ the commit." >expect &&
+		mkfifo blobs &&
+		(
+			exec 3<blobs &&
+			cat <<-EOF &&
+			feature cat-blob
+			blob
+			mark :1
+			data <<BLOB
+			A blob from _before_ the commit.
+			BLOB
+			commit refs/heads/temporary
+			committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
+			data <<COMMIT
+			Empty commit
+			COMMIT
+			cat-blob :1
+			EOF
 
-		echo
-	) |
-	git fast-import --cat-blob-fd=3 3>blobs &&
-	test_cmp expect actual
+			read blob_id type size <&3 &&
+			test_copy_bytes $size >actual <&3 &&
+			read newline <&3 &&
+
+			echo
+		) |
+		git fast-import --cat-blob-fd=3 3>blobs &&
+		test_cmp expect actual
+	)
 '
 
 test_expect_success PIPE 'R: print staged blob within commit' '
-	rm -f blobs &&
-	echo "A blob from _within_ the commit." >expect &&
-	mkfifo blobs &&
+	test_when_finished "rm -rf repo" &&
+	git init repo &&
 	(
-		exec 3<blobs &&
-		cat <<-EOF &&
-		feature cat-blob
-		commit refs/heads/within
-		committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
-		data <<COMMIT
-		Empty commit
-		COMMIT
-		M 644 inline within
-		data <<BLOB
-		A blob from _within_ the commit.
-		BLOB
-		EOF
+		cd repo &&
 
-		to_get=$(
-			echo "A blob from _within_ the commit." |
-			git hash-object --stdin
-		) &&
-		echo "cat-blob $to_get" &&
+		rm -f blobs &&
+		echo "A blob from _within_ the commit." >expect &&
+		mkfifo blobs &&
+		(
+			exec 3<blobs &&
+			cat <<-EOF &&
+			feature cat-blob
+			commit refs/heads/within
+			committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
+			data <<COMMIT
+			Empty commit
+			COMMIT
+			M 644 inline within
+			data <<BLOB
+			A blob from _within_ the commit.
+			BLOB
+			EOF
 
-		read blob_id type size <&3 &&
-		test_copy_bytes $size >actual <&3 &&
-		read newline <&3 &&
+			to_get=$(
+				echo "A blob from _within_ the commit." |
+				git hash-object --stdin
+			) &&
+			echo "cat-blob $to_get" &&
 
-		echo deleteall
-	) |
-	git fast-import --cat-blob-fd=3 3>blobs &&
-	test_cmp expect actual
+			read blob_id type size <&3 &&
+			test_copy_bytes $size >actual <&3 &&
+			read newline <&3 &&
+
+			echo deleteall
+		) |
+		git fast-import --cat-blob-fd=3 3>blobs &&
+		test_cmp expect actual
+	)
 '
 
 test_expect_success 'R: quiet option results in no stats being output' '
-- 
2.56.GIT
Previous: Karthik NayakNext: Karthik Nayak
Message 16 of 45 in “t9300: group and move tests to other files”
  1. 00/20 t9300: group and move tests to other filesKarthik Nayak, Nov 10, 2026
  2. 01/20 t9300: move 'fastimport.unpackLimit' to the required testKarthik Nayak, Nov 10, 2026
  3. 02/20 t9300: make the series B tests self-containedKarthik Nayak, Nov 10, 2026
  4. 03/20 t9300: make the series T tests self-containedKarthik Nayak, Nov 10, 2026
  5. 04/20 t9300: make the series S tests self-containedKarthik Nayak, Nov 10, 2026
  6. 05/20 t9300: make the series V tests self-containedKarthik Nayak, Nov 10, 2026
  7. 06/20 t9300: make the series Q tests self-containedKarthik Nayak, Nov 10, 2026
  8. 07/20 t9300: make the series P tests self-containedKarthik Nayak, Nov 10, 2026
  9. 08/20 t9300: make the series O tests self-containedKarthik Nayak, Nov 10, 2026
  10. 09/20 t9300: make the big blob tests self-containedKarthik Nayak, Nov 10, 2026
  11. 10/20 t9300: make the ref update tests self-containedKarthik Nayak, Nov 10, 2026
  12. 11/20 t9300: make the date format tests self-containedKarthik Nayak, Nov 10, 2026
  13. 12/20 t9300: make the pack edges test self-containedKarthik Nayak, Nov 10, 2026
  14. 13/20 t9300: make the marks tests self-containedKarthik Nayak, Nov 10, 2026
  15. 14/20 t9300: make the series Y tests self-containedKarthik Nayak, Nov 10, 2026
  16. 15/20 t9300: make the cat-blob tests self-containedKarthik Nayak, Nov 10, 2026
  17. 16/20 t9300: make the feature and option tests self-containedKarthik Nayak, Nov 10, 2026
  18. 17/20 t9300: make the stream tests self-containedKarthik Nayak, Nov 10, 2026
  19. 18/20 t9300: make the get-mark and encoding tests self-containedKarthik Nayak, Nov 10, 2026
  20. 19/20 t9300: move self-contained tests into dedicated filesKarthik Nayak, Nov 10, 2026
  21. 20/20 t93xx: drop the series letter from the moved test namesKarthik Nayak, Nov 10, 2026
  22. Junio C HamanoNov 10, 2026
  23. Junio C HamanoNov 10, 2026
  24. Karthik NayakNov 11, 2026
  25. 00/20 t9300: group and move tests to other filesKarthik Nayak, Nov 12, 2026
  26. 01/20 t9300: move 'fastimport.unpackLimit' to the required testKarthik Nayak, Nov 12, 2026
  27. 02/20 t9300: make the series B tests self-containedKarthik Nayak, Nov 12, 2026
  28. 03/20 t9300: make the series T tests self-containedKarthik Nayak, Nov 12, 2026
  29. 04/20 t9300: make the series S tests self-containedKarthik Nayak, Nov 12, 2026
  30. 05/20 t9300: make the series V tests self-containedKarthik Nayak, Nov 12, 2026
  31. 06/20 t9300: make the series Q tests self-containedKarthik Nayak, Nov 12, 2026
  32. 07/20 t9300: make the series P tests self-containedKarthik Nayak, Nov 12, 2026
  33. 08/20 t9300: make the series O tests self-containedKarthik Nayak, Nov 12, 2026
  34. 09/20 t9300: make the big blob tests self-containedKarthik Nayak, Nov 12, 2026
  35. 10/20 t9300: make the ref update tests self-containedKarthik Nayak, Nov 12, 2026
  36. 11/20 t9300: make the date format tests self-containedKarthik Nayak, Nov 12, 2026
  37. 12/20 t9300: make the pack edges test self-containedKarthik Nayak, Nov 12, 2026
  38. 13/20 t9300: make the marks tests self-containedKarthik Nayak, Nov 12, 2026
  39. 14/20 t9300: make the series Y tests self-containedKarthik Nayak, Nov 12, 2026
  40. 15/20 t9300: make the cat-blob tests self-containedKarthik Nayak, Nov 12, 2026
  41. 16/20 t9300: make the feature and option tests self-containedKarthik Nayak, Nov 12, 2026
  42. 17/20 t9300: make the stream tests self-containedKarthik Nayak, Nov 12, 2026
  43. 18/20 t9300: make the get-mark and encoding tests self-containedKarthik Nayak, Nov 12, 2026
  44. 19/20 t9300: move self-contained tests into dedicated filesKarthik Nayak, Nov 12, 2026
  45. 20/20 t93xx: drop the series letter from the moved test namesKarthik Nayak, Nov 12, 2026

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.