git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "brian m. carlson" <sandals@crustytoothpaste.net>
To: <git@vger.kernel.org>
Cc: Derrick Stolee <dstolee@microsoft.com>,
	Stefan Beller <stefanbeller@gmail.com>,
	Johannes Schindelin <Johannes.Schindelin@gmx.de>
Subject: [PATCH v2 10/15] t4034: abstract away SHA-1-specific constants
Date: Mon, 28 Oct 2019 00:59:02 +0000	[thread overview]
Message-ID: <20191028005907.24985-11-sandals@crustytoothpaste.net> (raw)
In-Reply-To: <20191028005907.24985-1-sandals@crustytoothpaste.net>

Adjust the test so that it computes variables for object IDs instead of
using hard-coded hashes.  Move some expected result heredocs around so
that they can use computed variables.

Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>
---
 t/t4034-diff-words.sh | 93 +++++++++++++++++++++++++------------------
 1 file changed, 54 insertions(+), 39 deletions(-)

diff --git a/t/t4034-diff-words.sh b/t/t4034-diff-words.sh
index 9a93c2a3e0..fb145aa173 100755
--- a/t/t4034-diff-words.sh
+++ b/t/t4034-diff-words.sh
@@ -19,9 +19,11 @@ cat >post.simple <<-\EOF
 
 	aeff = aeff * ( aaa )
 EOF
-cat >expect.letter-runs-are-words <<-\EOF
+pre=$(git rev-parse --short $(git hash-object pre.simple))
+post=$(git rev-parse --short $(git hash-object post.simple))
+cat >expect.letter-runs-are-words <<-EOF
 	<BOLD>diff --git a/pre b/post<RESET>
-	<BOLD>index 330b04f..5ed8eff 100644<RESET>
+	<BOLD>index $pre..$post 100644<RESET>
 	<BOLD>--- a/pre<RESET>
 	<BOLD>+++ b/post<RESET>
 	<CYAN>@@ -1,3 +1,7 @@<RESET>
@@ -33,9 +35,9 @@ cat >expect.letter-runs-are-words <<-\EOF
 
 	<GREEN>aeff = aeff * ( aaa<RESET> )
 EOF
-cat >expect.non-whitespace-is-word <<-\EOF
+cat >expect.non-whitespace-is-word <<-EOF
 	<BOLD>diff --git a/pre b/post<RESET>
-	<BOLD>index 330b04f..5ed8eff 100644<RESET>
+	<BOLD>index $pre..$post 100644<RESET>
 	<BOLD>--- a/pre<RESET>
 	<BOLD>+++ b/post<RESET>
 	<CYAN>@@ -1,3 +1,7 @@<RESET>
@@ -49,9 +51,12 @@ cat >expect.non-whitespace-is-word <<-\EOF
 EOF
 
 word_diff () {
+	pre=$(git rev-parse --short $(git hash-object pre)) &&
+	post=$(git rev-parse --short $(git hash-object post)) &&
 	test_must_fail git diff --no-index "$@" pre post >output &&
 	test_decode_color <output >output.decrypted &&
-	test_cmp expect output.decrypted
+	sed -e "2s/index [^ ]*/index $pre..$post/" expect >expected
+	test_cmp expected output.decrypted
 }
 
 test_language_driver () {
@@ -77,9 +82,9 @@ test_expect_success 'set up pre and post with runs of whitespace' '
 '
 
 test_expect_success 'word diff with runs of whitespace' '
-	cat >expect <<-\EOF &&
+	cat >expect <<-EOF &&
 		<BOLD>diff --git a/pre b/post<RESET>
-		<BOLD>index 330b04f..5ed8eff 100644<RESET>
+		<BOLD>index $pre..$post 100644<RESET>
 		<BOLD>--- a/pre<RESET>
 		<BOLD>+++ b/post<RESET>
 		<CYAN>@@ -1,3 +1,7 @@<RESET>
@@ -97,9 +102,9 @@ test_expect_success 'word diff with runs of whitespace' '
 '
 
 test_expect_success '--word-diff=porcelain' '
-	sed 's/#.*$//' >expect <<-\EOF &&
+	sed 's/#.*$//' >expect <<-EOF &&
 		diff --git a/pre b/post
-		index 330b04f..5ed8eff 100644
+		index $pre..$post 100644
 		--- a/pre
 		+++ b/post
 		@@ -1,3 +1,7 @@
@@ -121,9 +126,9 @@ test_expect_success '--word-diff=porcelain' '
 '
 
 test_expect_success '--word-diff=plain' '
-	cat >expect <<-\EOF &&
+	cat >expect <<-EOF &&
 		diff --git a/pre b/post
-		index 330b04f..5ed8eff 100644
+		index $pre..$post 100644
 		--- a/pre
 		+++ b/post
 		@@ -1,3 +1,7 @@
@@ -140,9 +145,9 @@ test_expect_success '--word-diff=plain' '
 '
 
 test_expect_success '--word-diff=plain --color' '
-	cat >expect <<-\EOF &&
+	cat >expect <<-EOF &&
 		<BOLD>diff --git a/pre b/post<RESET>
-		<BOLD>index 330b04f..5ed8eff 100644<RESET>
+		<BOLD>index $pre..$post 100644<RESET>
 		<BOLD>--- a/pre<RESET>
 		<BOLD>+++ b/post<RESET>
 		<CYAN>@@ -1,3 +1,7 @@<RESET>
@@ -158,9 +163,9 @@ test_expect_success '--word-diff=plain --color' '
 '
 
 test_expect_success 'word diff without context' '
-	cat >expect <<-\EOF &&
+	cat >expect <<-EOF &&
 		<BOLD>diff --git a/pre b/post<RESET>
-		<BOLD>index 330b04f..5ed8eff 100644<RESET>
+		<BOLD>index $pre..$post 100644<RESET>
 		<BOLD>--- a/pre<RESET>
 		<BOLD>+++ b/post<RESET>
 		<CYAN>@@ -1 +1 @@<RESET>
@@ -207,9 +212,9 @@ test_expect_success 'command-line overrides config' '
 '
 
 test_expect_success 'command-line overrides config: --word-diff-regex' '
-	cat >expect <<-\EOF &&
+	cat >expect <<-EOF &&
 		<BOLD>diff --git a/pre b/post<RESET>
-		<BOLD>index 330b04f..5ed8eff 100644<RESET>
+		<BOLD>index $pre..$post 100644<RESET>
 		<BOLD>--- a/pre<RESET>
 		<BOLD>+++ b/post<RESET>
 		<CYAN>@@ -1,3 +1,7 @@<RESET>
@@ -234,9 +239,9 @@ test_expect_success 'setup: remove diff driver regex' '
 '
 
 test_expect_success 'use configured regex' '
-	cat >expect <<-\EOF &&
+	cat >expect <<-EOF &&
 		<BOLD>diff --git a/pre b/post<RESET>
-		<BOLD>index 330b04f..5ed8eff 100644<RESET>
+		<BOLD>index $pre..$post 100644<RESET>
 		<BOLD>--- a/pre<RESET>
 		<BOLD>+++ b/post<RESET>
 		<CYAN>@@ -1,3 +1,7 @@<RESET>
@@ -254,9 +259,11 @@ test_expect_success 'use configured regex' '
 test_expect_success 'test parsing words for newline' '
 	echo "aaa (aaa)" >pre &&
 	echo "aaa (aaa) aaa" >post &&
-	cat >expect <<-\EOF &&
+	pre=$(git rev-parse --short $(git hash-object pre)) &&
+	post=$(git rev-parse --short $(git hash-object post)) &&
+	cat >expect <<-EOF &&
 		<BOLD>diff --git a/pre b/post<RESET>
-		<BOLD>index c29453b..be22f37 100644<RESET>
+		<BOLD>index $pre..$post 100644<RESET>
 		<BOLD>--- a/pre<RESET>
 		<BOLD>+++ b/post<RESET>
 		<CYAN>@@ -1 +1 @@<RESET>
@@ -268,9 +275,11 @@ test_expect_success 'test parsing words for newline' '
 test_expect_success 'test when words are only removed at the end' '
 	echo "(:" >pre &&
 	echo "(" >post &&
-	cat >expect <<-\EOF &&
+	pre=$(git rev-parse --short $(git hash-object pre)) &&
+	post=$(git rev-parse --short $(git hash-object post)) &&
+	cat >expect <<-EOF &&
 		<BOLD>diff --git a/pre b/post<RESET>
-		<BOLD>index 289cb9d..2d06f37 100644<RESET>
+		<BOLD>index $pre..$post 100644<RESET>
 		<BOLD>--- a/pre<RESET>
 		<BOLD>+++ b/post<RESET>
 		<CYAN>@@ -1 +1 @@<RESET>
@@ -282,9 +291,11 @@ test_expect_success 'test when words are only removed at the end' '
 test_expect_success '--word-diff=none' '
 	echo "(:" >pre &&
 	echo "(" >post &&
-	cat >expect <<-\EOF &&
+	pre=$(git rev-parse --short $(git hash-object pre)) &&
+	post=$(git rev-parse --short $(git hash-object post)) &&
+	cat >expect <<-EOF &&
 		diff --git a/pre b/post
-		index 289cb9d..2d06f37 100644
+		index $pre..$post 100644
 		--- a/pre
 		+++ b/post
 		@@ -1 +1 @@
@@ -317,16 +328,6 @@ test_language_driver ruby
 test_language_driver tex
 
 test_expect_success 'word-diff with diff.sbe' '
-	cat >expect <<-\EOF &&
-	diff --git a/pre b/post
-	index a1a53b5..bc8fe6d 100644
-	--- a/pre
-	+++ b/post
-	@@ -1,3 +1,3 @@
-	a
-
-	[-b-]{+c+}
-	EOF
 	cat >pre <<-\EOF &&
 	a
 
@@ -337,21 +338,35 @@ test_expect_success 'word-diff with diff.sbe' '
 
 	c
 	EOF
+	pre=$(git rev-parse --short $(git hash-object pre)) &&
+	post=$(git rev-parse --short $(git hash-object post)) &&
+	cat >expect <<-EOF &&
+	diff --git a/pre b/post
+	index $pre..$post 100644
+	--- a/pre
+	+++ b/post
+	@@ -1,3 +1,3 @@
+	a
+
+	[-b-]{+c+}
+	EOF
 	test_config diff.suppress-blank-empty true &&
 	word_diff --word-diff=plain
 '
 
 test_expect_success 'word-diff with no newline at EOF' '
-	cat >expect <<-\EOF &&
+	printf "%s" "a a a a a" >pre &&
+	printf "%s" "a a ab a a" >post &&
+	pre=$(git rev-parse --short $(git hash-object pre)) &&
+	post=$(git rev-parse --short $(git hash-object post)) &&
+	cat >expect <<-EOF &&
 	diff --git a/pre b/post
-	index 7bf316e..3dd0303 100644
+	index $pre..$post 100644
 	--- a/pre
 	+++ b/post
 	@@ -1 +1 @@
 	a a [-a-]{+ab+} a a
 	EOF
-	printf "%s" "a a a a a" >pre &&
-	printf "%s" "a a ab a a" >post &&
 	word_diff --word-diff=plain
 '
 

  parent reply	other threads:[~2019-10-28  0:59 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-10-28  0:58 [PATCH v2 00/15] SHA-256 test fixes, part 6 brian m. carlson
2019-10-28  0:58 ` [PATCH v2 01/15] t/oid-info: allow looking up hash algorithm name brian m. carlson
2019-10-28  0:58 ` [PATCH v2 02/15] t/oid-info: add empty tree and empty blob values brian m. carlson
2019-10-28  0:58 ` [PATCH v2 03/15] rev-parse: add a --show-object-format option brian m. carlson
2019-10-28  0:58 ` [PATCH v2 04/15] t1305: avoid comparing extensions brian m. carlson
2019-10-28  0:58 ` [PATCH v2 05/15] t3429: remove SHA1 annotation brian m. carlson
2019-10-28  0:58 ` [PATCH v2 06/15] t4010: abstract away SHA-1-specific constants brian m. carlson
2019-10-28  0:58 ` [PATCH v2 07/15] t4011: " brian m. carlson
2019-10-28  2:56   ` Junio C Hamano
2019-10-28 23:59     ` brian m. carlson
2019-10-28  0:59 ` [PATCH v2 08/15] t4015: " brian m. carlson
2019-10-28  0:59 ` [PATCH v2 09/15] t4027: make hash-size independent brian m. carlson
2019-10-28  0:59 ` brian m. carlson [this message]
2019-10-28  0:59 ` [PATCH v2 11/15] t4038: abstract away SHA-1 specific constants brian m. carlson
2019-10-28  0:59 ` [PATCH v2 12/15] t4039: abstract away SHA-1-specific constants brian m. carlson
2019-10-28  0:59 ` [PATCH v2 13/15] t4044: update test to work with SHA-256 brian m. carlson
2019-10-28  0:59 ` [PATCH v2 14/15] t4045: make hash-size independent brian m. carlson
2019-10-28  0:59 ` [PATCH v2 15/15] t4048: abstract away SHA-1-specific constants brian m. carlson
2019-10-29  2:26 ` [PATCH v2 00/15] SHA-256 test fixes, part 6 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

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20191028005907.24985-11-sandals@crustytoothpaste.net \
    --to=sandals@crustytoothpaste.net \
    --cc=Johannes.Schindelin@gmx.de \
    --cc=dstolee@microsoft.com \
    --cc=git@vger.kernel.org \
    --cc=stefanbeller@gmail.com \
    /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.
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 NNTP newsgroup(s).