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

[PATCH v2 13/15] t4044: update test to work with SHA-256

From
brian m. carlson <sandals@crustytoothpaste.net>
Date
Oct 28, 2019, 00:59 UTC
Message-ID
<20191028005907.24985-14-sandals@crustytoothpaste.net>
In-Reply-To
<20191028005907.24985-1-sandals@crustytoothpaste.net>

This test produces pseudo-collisions and tests git diff's behavior with them, and is therefore sensitive to the hash in use. Update the test to compute the collisions for both SHA-1 and SHA-256 using appropriate constants. Move the heredocs inside the setup block so that all of the setup code can be tested for failure.

Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>
---
 t/t4044-diff-index-unique-abbrev.sh | 46 +++++++++++++++++++----------
 1 file changed, 30 insertions(+), 16 deletions(-)
diff --git a/t/t4044-diff-index-unique-abbrev.sh b/t/t4044-diff-index-unique-abbrev.sh
index 647905e01f..4701796d10 100755
--- a/t/t4044-diff-index-unique-abbrev.sh
+++ b/t/t4044-diff-index-unique-abbrev.sh
@@ -3,34 +3,48 @@
 test_description='test unique sha1 abbreviation on "index from..to" line'
 . ./test-lib.sh
 
-if ! test_have_prereq SHA1
-then
-       skip_all='not using SHA-1 for objects'
-       test_done
-fi
-
-cat >expect_initial <<EOF
-100644 blob 51d2738463ea4ca66f8691c91e33ce64b7d41bb1	foo
-EOF
+test_expect_success 'setup' '
+	test_oid_cache <<-EOF &&
+	val1 sha1:4827
+	val1 sha256:5664
 
-cat >expect_update <<EOF
-100644 blob 51d2738efb4ad8a1e40bed839ab8e116f0a15e47	foo
-EOF
+	val2 sha1:11742
+	val2 sha256:10625
 
-test_expect_success 'setup' '
-	echo 4827 > foo &&
+	hash1 sha1:51d2738463ea4ca66f8691c91e33ce64b7d41bb1
+	hash1 sha256:ae31dfff0af93b2c62b0098a039b38569c43b0a7e97b873000ca42d128f27350
+
+	hasht1 sha1:51d27384
+	hasht1 sha256:ae31dfff
+
+	hash2 sha1:51d2738efb4ad8a1e40bed839ab8e116f0a15e47
+	hash2 sha256:ae31dffada88a46fd5f53c7ed5aa25a7a8951f1d5e88456c317c8d5484d263e5
+
+	hasht2 sha1:51d2738e
+	hasht2 sha256:ae31dffa
+	EOF
+
+	cat >expect_initial <<-EOF &&
+	100644 blob $(test_oid hash1)	foo
+	EOF
+
+	cat >expect_update <<-EOF &&
+	100644 blob $(test_oid hash2)	foo
+	EOF
+
+	echo "$(test_oid val1)" > foo &&
 	git add foo &&
 	git commit -m "initial" &&
 	git cat-file -p HEAD: > actual &&
 	test_cmp expect_initial actual &&
-	echo 11742 > foo &&
+	echo "$(test_oid val2)" > foo &&
 	git commit -a -m "update" &&
 	git cat-file -p HEAD: > actual &&
 	test_cmp expect_update actual
 '
 
 cat >expect <<EOF
-index 51d27384..51d2738e 100644
+index $(test_oid hasht1)..$(test_oid hasht2) 100644
 EOF
 
 test_expect_success 'diff does not produce ambiguous index line' '
Previous: brian m. carlsonNext: brian m. carlson
Message 17 of 19 in “SHA-256 test fixes, part 6”
  1. 00/15 SHA-256 test fixes, part 6brian m. carlson, Oct 28, 2019
  2. 01/15 t/oid-info: allow looking up hash algorithm namebrian m. carlson, Oct 28, 2019
  3. 03/15 rev-parse: add a --show-object-format optionbrian m. carlson, Oct 28, 2019
  4. 02/15 t/oid-info: add empty tree and empty blob valuesbrian m. carlson, Oct 28, 2019
  5. 04/15 t1305: avoid comparing extensionsbrian m. carlson, Oct 28, 2019
  6. 05/15 t3429: remove SHA1 annotationbrian m. carlson, Oct 28, 2019
  7. 06/15 t4010: abstract away SHA-1-specific constantsbrian m. carlson, Oct 28, 2019
  8. 07/15 t4011: abstract away SHA-1-specific constantsbrian m. carlson, Oct 28, 2019
  9. Junio C HamanoOct 28, 2019
  10. brian m. carlsonOct 28, 2019
  11. 08/15 t4015: abstract away SHA-1-specific constantsbrian m. carlson, Oct 28, 2019
  12. 10/15 t4034: abstract away SHA-1-specific constantsbrian m. carlson, Oct 28, 2019
  13. 11/15 t4038: abstract away SHA-1 specific constantsbrian m. carlson, Oct 28, 2019
  14. 09/15 t4027: make hash-size independentbrian m. carlson, Oct 28, 2019
  15. 12/15 t4039: abstract away SHA-1-specific constantsbrian m. carlson, Oct 28, 2019
  16. 15/15 t4048: abstract away SHA-1-specific constantsbrian m. carlson, Oct 28, 2019
  17. 13/15 t4044: update test to work with SHA-256brian m. carlson, Oct 28, 2019
  18. 14/15 t4045: make hash-size independentbrian m. carlson, Oct 28, 2019
  19. Junio C HamanoOct 29, 2019

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.