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

[PATCH v3 16/28] t4008: abstract away SHA-1-specific constants

From
brian m. carlson <sandals@crustytoothpaste.net>
Date
May 16, 2018, 01:56 UTC
Message-ID
<20180516015630.661349-17-sandals@crustytoothpaste.net>
In-Reply-To
<20180516015630.661349-1-sandals@crustytoothpaste.net>

Adjust the test so that it computes variables for blobs instead of using hard-coded hashes.

Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>
---
 t/t4008-diff-break-rewrite.sh | 59 +++++++++++++++++++----------------
 1 file changed, 32 insertions(+), 27 deletions(-)
diff --git a/t/t4008-diff-break-rewrite.sh b/t/t4008-diff-break-rewrite.sh
index 9dd1bc5e16..b1ccd4102e 100755
--- a/t/t4008-diff-break-rewrite.sh
+++ b/t/t4008-diff-break-rewrite.sh
@@ -27,29 +27,32 @@ Further, with -B and -M together, these should turn into two renames.
 test_expect_success setup '
 	cat "$TEST_DIRECTORY"/diff-lib/README >file0 &&
 	cat "$TEST_DIRECTORY"/diff-lib/COPYING >file1 &&
+	blob0_id=$(git hash-object file0) &&
+	blob1_id=$(git hash-object file1) &&
 	git update-index --add file0 file1 &&
 	git tag reference $(git write-tree)
 '
 
 test_expect_success 'change file1 with copy-edit of file0 and remove file0' '
 	sed -e "s/git/GIT/" file0 >file1 &&
+	blob2_id=$(git hash-object file1) &&
 	rm -f file0 &&
 	git update-index --remove file0 file1
 '
 
 test_expect_success 'run diff with -B (#1)' '
 	git diff-index -B --cached reference >current &&
-	cat >expect <<-\EOF &&
-	:100644 000000 548142c327a6790ff8821d67c2ee1eff7a656b52 0000000000000000000000000000000000000000 D	file0
-	:100644 100644 6ff87c4664981e4397625791c8ea3bbb5f2279a3 2fbedd0b5d4b8126e4750c3bee305e8ff79f80ec M100	file1
+	cat >expect <<-EOF &&
+	:100644 000000 $blob0_id $ZERO_OID D	file0
+	:100644 100644 $blob1_id $blob2_id M100	file1
 	EOF
 	compare_diff_raw expect current
 '
 
 test_expect_success 'run diff with -B and -M (#2)' '
 	git diff-index -B -M reference >current &&
-	cat >expect <<-\EOF &&
-	:100644 100644 548142c327a6790ff8821d67c2ee1eff7a656b52 2fbedd0b5d4b8126e4750c3bee305e8ff79f80ec R100	file0	file1
+	cat >expect <<-EOF &&
+	:100644 100644 $blob0_id $blob2_id R100	file0	file1
 	EOF
 	compare_diff_raw expect current
 '
@@ -66,18 +69,18 @@ test_expect_success 'swap file0 and file1' '
 
 test_expect_success 'run diff with -B (#3)' '
 	git diff-index -B reference >current &&
-	cat >expect <<-\EOF &&
-	:100644 100644 548142c327a6790ff8821d67c2ee1eff7a656b52 6ff87c4664981e4397625791c8ea3bbb5f2279a3 M100	file0
-	:100644 100644 6ff87c4664981e4397625791c8ea3bbb5f2279a3 548142c327a6790ff8821d67c2ee1eff7a656b52 M100	file1
+	cat >expect <<-EOF &&
+	:100644 100644 $blob0_id $blob1_id M100	file0
+	:100644 100644 $blob1_id $blob0_id M100	file1
 	EOF
 	compare_diff_raw expect current
 '
 
 test_expect_success 'run diff with -B and -M (#4)' '
 	git diff-index -B -M reference >current &&
-	cat >expect <<-\EOF &&
-	:100644 100644 6ff87c4664981e4397625791c8ea3bbb5f2279a3 6ff87c4664981e4397625791c8ea3bbb5f2279a3 R100	file1	file0
-	:100644 100644 548142c327a6790ff8821d67c2ee1eff7a656b52 548142c327a6790ff8821d67c2ee1eff7a656b52 R100	file0	file1
+	cat >expect <<-EOF &&
+	:100644 100644 $blob1_id $blob1_id R100	file1	file0
+	:100644 100644 $blob0_id $blob0_id R100	file0	file1
 	EOF
 	compare_diff_raw expect current
 '
@@ -85,14 +88,15 @@ test_expect_success 'run diff with -B and -M (#4)' '
 test_expect_success 'make file0 into something completely different' '
 	rm -f file0 &&
 	test_ln_s_add frotz file0 &&
+	slink_id=$(printf frotz | git hash-object --stdin) &&
 	git update-index file1
 '
 
 test_expect_success 'run diff with -B (#5)' '
 	git diff-index -B reference >current &&
-	cat >expect <<-\EOF &&
-	:100644 120000 548142c327a6790ff8821d67c2ee1eff7a656b52 67be421f88824578857624f7b3dc75e99a8a1481 T	file0
-	:100644 100644 6ff87c4664981e4397625791c8ea3bbb5f2279a3 548142c327a6790ff8821d67c2ee1eff7a656b52 M100	file1
+	cat >expect <<-EOF &&
+	:100644 120000 $blob0_id $slink_id T	file0
+	:100644 100644 $blob1_id $blob0_id M100	file1
 	EOF
 	compare_diff_raw expect current
 '
@@ -103,9 +107,9 @@ test_expect_success 'run diff with -B -M (#6)' '
 	# file0 changed from regular to symlink.  file1 is the same as the preimage
 	# of file0.  Because the change does not make file0 disappear, file1 is
 	# denoted as a copy of file0
-	cat >expect <<-\EOF &&
-	:100644 120000 548142c327a6790ff8821d67c2ee1eff7a656b52 67be421f88824578857624f7b3dc75e99a8a1481 T	file0
-	:100644 100644 548142c327a6790ff8821d67c2ee1eff7a656b52 548142c327a6790ff8821d67c2ee1eff7a656b52 C	file0	file1
+	cat >expect <<-EOF &&
+	:100644 120000 $blob0_id $slink_id T	file0
+	:100644 100644 $blob0_id $blob0_id C	file0	file1
 	EOF
 	compare_diff_raw expect current
 '
@@ -115,9 +119,9 @@ test_expect_success 'run diff with -M (#7)' '
 
 	# This should not mistake file0 as the copy source of new file1
 	# due to type differences.
-	cat >expect <<-\EOF &&
-	:100644 120000 548142c327a6790ff8821d67c2ee1eff7a656b52 67be421f88824578857624f7b3dc75e99a8a1481 T	file0
-	:100644 100644 6ff87c4664981e4397625791c8ea3bbb5f2279a3 548142c327a6790ff8821d67c2ee1eff7a656b52 M	file1
+	cat >expect <<-EOF &&
+	:100644 120000 $blob0_id $slink_id T	file0
+	:100644 100644 $blob1_id $blob0_id M	file1
 	EOF
 	compare_diff_raw expect current
 '
@@ -128,25 +132,26 @@ test_expect_success 'file1 edited to look like file0 and file0 rename-edited to
 	git checkout-index -f -u -a &&
 	sed -e "s/git/GIT/" file0 >file1 &&
 	sed -e "s/git/GET/" file0 >file2 &&
+	blob3_id=$(git hash-object file2) &&
 	rm -f file0 &&
 	git update-index --add --remove file0 file1 file2
 '
 
 test_expect_success 'run diff with -B (#8)' '
 	git diff-index -B reference >current &&
-	cat >expect <<-\EOF &&
-	:100644 000000 548142c327a6790ff8821d67c2ee1eff7a656b52 0000000000000000000000000000000000000000 D	file0
-	:100644 100644 6ff87c4664981e4397625791c8ea3bbb5f2279a3 2fbedd0b5d4b8126e4750c3bee305e8ff79f80ec M100	file1
-	:000000 100644 0000000000000000000000000000000000000000 69a939f651686f56322566e2fd76715947a24162 A	file2
+	cat >expect <<-EOF &&
+	:100644 000000 $blob0_id $ZERO_OID D	file0
+	:100644 100644 $blob1_id $blob2_id M100	file1
+	:000000 100644 $ZERO_OID $blob3_id A	file2
 	EOF
 	compare_diff_raw expect current
 '
 
 test_expect_success 'run diff with -B -C (#9)' '
 	git diff-index -B -C reference >current &&
-	cat >expect <<-\EOF &&
-	:100644 100644 548142c327a6790ff8821d67c2ee1eff7a656b52 2fbedd0b5d4b8126e4750c3bee305e8ff79f80ec C095	file0	file1
-	:100644 100644 548142c327a6790ff8821d67c2ee1eff7a656b52 69a939f651686f56322566e2fd76715947a24162 R095	file0	file2
+	cat >expect <<-EOF &&
+	:100644 100644 $blob0_id $blob2_id C095	file0	file1
+	:100644 100644 $blob0_id $blob3_id R095	file0	file2
 	EOF
 	compare_diff_raw expect current
 '
Previous: brian m. carlsonNext: brian m. carlson
Message 31 of 64 in “Hash-independent tests”
  1. 00/28 Hash-independent testsbrian m. carlson, May 16, 2018
  2. 01/28 t/test-lib: add an SHA1 prerequisitebrian m. carlson, May 16, 2018
  3. 02/28 t/test-lib: introduce ZERO_OIDbrian m. carlson, May 16, 2018
  4. 04/28 t/test-lib: introduce OID_REGEXbrian m. carlson, May 16, 2018
  5. 03/28 t: switch $_z40 to $ZERO_OIDbrian m. carlson, May 16, 2018
  6. 05/28 t: switch $_x40 to $OID_REGEXbrian m. carlson, May 16, 2018
  7. 07/28 t1007: annotate with SHA1 prerequisitebrian m. carlson, May 16, 2018
  8. Stefan BellerMay 16, 2018
  9. brian m. carlsonMay 16, 2018
  10. 09/28 t4044: skip test if not using SHA-1brian m. carlson, May 16, 2018
  11. 10/28 t: skip pack tests if not using SHA-1brian m. carlson, May 16, 2018
  12. 11/28 t2203: abstract away SHA-1-specific constantsbrian m. carlson, May 16, 2018
  13. 14/28 t3905: abstract away SHA-1-specific constantsbrian m. carlson, May 16, 2018
  14. 17/28 t4014: abstract away SHA-1-specific constantsbrian m. carlson, May 16, 2018
  15. 21/28 t4029: abstract away SHA-1-specific constantsbrian m. carlson, May 16, 2018
  16. 23/28 t/lib-diff-alternative: abstract away SHA-1-specific constantsbrian m. carlson, May 16, 2018
  17. 24/28 t4205: sort log output in a hash-independent waybrian m. carlson, May 16, 2018
  18. 26/28 t4045: abstract away SHA-1-specific constantsbrian m. carlson, May 16, 2018
  19. 27/28 t4208: abstract away SHA-1-specific constantsbrian m. carlson, May 16, 2018
  20. 28/28 t5300: abstract away SHA-1-specific constantsbrian m. carlson, May 16, 2018
  21. 22/28 t4030: abstract away SHA-1-specific constantsbrian m. carlson, May 16, 2018
  22. 25/28 t4042: abstract away SHA-1-specific constantsbrian m. carlson, May 16, 2018
  23. 18/28 t4020: abstract away SHA-1-specific constantsbrian m. carlson, May 16, 2018
  24. 20/28 t4029: fix test indentationbrian m. carlson, May 16, 2018
  25. 15/28 t4007: abstract away SHA-1-specific constantsbrian m. carlson, May 16, 2018
  26. 12/28 t3103: abstract away SHA-1-specific constantsbrian m. carlson, May 16, 2018
  27. 19/28 t4022: abstract away SHA-1-specific constantsbrian m. carlson, May 16, 2018
  28. 13/28 t3702: abstract away SHA-1-specific constantsbrian m. carlson, May 16, 2018
  29. Stefan BellerMay 16, 2018
  30. brian m. carlsonMay 16, 2018
  31. 16/28 t4008: abstract away SHA-1-specific constantsbrian m. carlson, May 16, 2018
  32. 06/28 t0000: annotate with SHA1 prerequisitebrian m. carlson, May 16, 2018
  33. 08/28 t1512: skip test if not using SHA-1brian m. carlson, May 16, 2018
  34. 00/28 Hash-independent testsbrian m. carlson, May 21, 2018
  35. 01/28 t/test-lib: add an SHA1 prerequisitebrian m. carlson, May 21, 2018
  36. 02/28 t/test-lib: introduce ZERO_OIDbrian m. carlson, May 21, 2018
  37. 03/28 t: switch $_z40 to $ZERO_OIDbrian m. carlson, May 21, 2018
  38. 04/28 t/test-lib: introduce OID_REGEXbrian m. carlson, May 21, 2018
  39. 05/28 t: switch $_x40 to $OID_REGEXbrian m. carlson, May 21, 2018
  40. 06/28 t0000: annotate with SHA1 prerequisitebrian m. carlson, May 21, 2018
  41. 07/28 t1007: annotate with SHA1 prerequisitebrian m. carlson, May 21, 2018
  42. 08/28 t1512: skip test if not using SHA-1brian m. carlson, May 21, 2018
  43. 09/28 t4044: skip test if not using SHA-1brian m. carlson, May 21, 2018
  44. 10/28 t: skip pack tests if not using SHA-1brian m. carlson, May 21, 2018
  45. 11/28 t2203: abstract away SHA-1-specific constantsbrian m. carlson, May 21, 2018
  46. 13/28 t3702: abstract away SHA-1-specific constantsbrian m. carlson, May 21, 2018
  47. 14/28 t3905: abstract away SHA-1-specific constantsbrian m. carlson, May 21, 2018
  48. 15/28 t4007: abstract away SHA-1-specific constantsbrian m. carlson, May 21, 2018
  49. 17/28 t4014: abstract away SHA-1-specific constantsbrian m. carlson, May 21, 2018
  50. 18/28 t4020: abstract away SHA-1-specific constantsbrian m. carlson, May 21, 2018
  51. 19/28 t4022: abstract away SHA-1-specific constantsbrian m. carlson, May 21, 2018
  52. 20/28 t4029: fix test indentationbrian m. carlson, May 21, 2018
  53. 21/28 t4029: abstract away SHA-1-specific constantsbrian m. carlson, May 21, 2018
  54. 16/28 t4008: abstract away SHA-1-specific constantsbrian m. carlson, May 21, 2018
  55. 23/28 t/lib-diff-alternative: abstract away SHA-1-specific constantsbrian m. carlson, May 21, 2018
  56. 25/28 t4042: abstract away SHA-1-specific constantsbrian m. carlson, May 21, 2018
  57. 24/28 t4205: sort log output in a hash-independent waybrian m. carlson, May 21, 2018
  58. 27/28 t4208: abstract away SHA-1-specific constantsbrian m. carlson, May 21, 2018
  59. 28/28 t5300: abstract away SHA-1-specific constantsbrian m. carlson, May 21, 2018
  60. 26/28 t4045: abstract away SHA-1-specific constantsbrian m. carlson, May 21, 2018
  61. 22/28 t4030: abstract away SHA-1-specific constantsbrian m. carlson, May 21, 2018
  62. 12/28 t3103: abstract away SHA-1-specific constantsbrian m. carlson, May 21, 2018
  63. Ben PeartMay 21, 2018
  64. brian m. carlsonMay 21, 2018

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.