t4034: abstract away SHA-1-specific constants
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> Signed-off-by: Junio C Hamano <gitster@pobox.com>
brian m. carlson committed
Oct 28, 2019 at 00:59 UTC
0253e126a271f10dc1f1fc630193a4026ec8a7ee
1 file changed
+54
-39
t/t4034-diff-words.sh
+54
-39
@@ -19,9 +19,11 @@ cat >post.simple <<-\EOF
19
20
aeff = aeff * ( aaa )
21
EOF
22
-cat >expect.letter-runs-are-words <<-\EOF
22
+pre=$(git rev-parse --short $(git hash-object pre.simple))
23
+post=$(git rev-parse --short $(git hash-object post.simple))
24
+cat >expect.letter-runs-are-words <<-EOF
25
<BOLD>diff --git a/pre b/post<RESET>
24
- <BOLD>index 330b04f..5ed8eff 100644<RESET>
26
+ <BOLD>index $pre..$post 100644<RESET>
27
<BOLD>--- a/pre<RESET>
28
<BOLD>+++ b/post<RESET>
29
<CYAN>@@ -1,3 +1,7 @@<RESET>
@@ -33,9 +35,9 @@ cat >expect.letter-runs-are-words <<-\EOF
35
36
<GREEN>aeff = aeff * ( aaa<RESET> )
37
EOF
36
-cat >expect.non-whitespace-is-word <<-\EOF
38
+cat >expect.non-whitespace-is-word <<-EOF
39
<BOLD>diff --git a/pre b/post<RESET>
38
- <BOLD>index 330b04f..5ed8eff 100644<RESET>
40
+ <BOLD>index $pre..$post 100644<RESET>
41
<BOLD>--- a/pre<RESET>
42
<BOLD>+++ b/post<RESET>
43
<CYAN>@@ -1,3 +1,7 @@<RESET>
@@ -49,9 +51,12 @@ cat >expect.non-whitespace-is-word <<-\EOF
51
EOF
52
53
word_diff () {
54
+ pre=$(git rev-parse --short $(git hash-object pre)) &&
55
+ post=$(git rev-parse --short $(git hash-object post)) &&
56
test_must_fail git diff --no-index "$@" pre post >output &&
57
test_decode_color <output >output.decrypted &&
54
- test_cmp expect output.decrypted
58
+ sed -e "2s/index [^ ]*/index $pre..$post/" expect >expected
59
+ test_cmp expected output.decrypted
60
}
61
62
test_language_driver () {
@@ -77,9 +82,9 @@ test_expect_success 'set up pre and post with runs of whitespace' '
82
'
83
84
test_expect_success 'word diff with runs of whitespace' '
80
- cat >expect <<-\EOF &&
85
+ cat >expect <<-EOF &&
86
<BOLD>diff --git a/pre b/post<RESET>
82
- <BOLD>index 330b04f..5ed8eff 100644<RESET>
87
+ <BOLD>index $pre..$post 100644<RESET>
88
<BOLD>--- a/pre<RESET>
89
<BOLD>+++ b/post<RESET>
90
<CYAN>@@ -1,3 +1,7 @@<RESET>
@@ -97,9 +102,9 @@ test_expect_success 'word diff with runs of whitespace' '
102
'
103
104
test_expect_success '--word-diff=porcelain' '
100
- sed 's/#.*$//' >expect <<-\EOF &&
105
+ sed 's/#.*$//' >expect <<-EOF &&
106
diff --git a/pre b/post
102
- index 330b04f..5ed8eff 100644
107
+ index $pre..$post 100644
108
--- a/pre
109
+++ b/post
110
@@ -1,3 +1,7 @@
@@ -121,9 +126,9 @@ test_expect_success '--word-diff=porcelain' '
126
'
127
128
test_expect_success '--word-diff=plain' '
124
- cat >expect <<-\EOF &&
129
+ cat >expect <<-EOF &&
130
diff --git a/pre b/post
126
- index 330b04f..5ed8eff 100644
131
+ index $pre..$post 100644
132
--- a/pre
133
+++ b/post
134
@@ -1,3 +1,7 @@
@@ -140,9 +145,9 @@ test_expect_success '--word-diff=plain' '
145
'
146
147
test_expect_success '--word-diff=plain --color' '
143
- cat >expect <<-\EOF &&
148
+ cat >expect <<-EOF &&
149
<BOLD>diff --git a/pre b/post<RESET>
145
- <BOLD>index 330b04f..5ed8eff 100644<RESET>
150
+ <BOLD>index $pre..$post 100644<RESET>
151
<BOLD>--- a/pre<RESET>
152
<BOLD>+++ b/post<RESET>
153
<CYAN>@@ -1,3 +1,7 @@<RESET>
@@ -158,9 +163,9 @@ test_expect_success '--word-diff=plain --color' '
163
'
164
165
test_expect_success 'word diff without context' '
161
- cat >expect <<-\EOF &&
166
+ cat >expect <<-EOF &&
167
<BOLD>diff --git a/pre b/post<RESET>
163
- <BOLD>index 330b04f..5ed8eff 100644<RESET>
168
+ <BOLD>index $pre..$post 100644<RESET>
169
<BOLD>--- a/pre<RESET>
170
<BOLD>+++ b/post<RESET>
171
<CYAN>@@ -1 +1 @@<RESET>
@@ -207,9 +212,9 @@ test_expect_success 'command-line overrides config' '
212
'
213
214
test_expect_success 'command-line overrides config: --word-diff-regex' '
210
- cat >expect <<-\EOF &&
215
+ cat >expect <<-EOF &&
216
<BOLD>diff --git a/pre b/post<RESET>
212
- <BOLD>index 330b04f..5ed8eff 100644<RESET>
217
+ <BOLD>index $pre..$post 100644<RESET>
218
<BOLD>--- a/pre<RESET>
219
<BOLD>+++ b/post<RESET>
220
<CYAN>@@ -1,3 +1,7 @@<RESET>
@@ -234,9 +239,9 @@ test_expect_success 'setup: remove diff driver regex' '
239
'
240
241
test_expect_success 'use configured regex' '
237
- cat >expect <<-\EOF &&
242
+ cat >expect <<-EOF &&
243
<BOLD>diff --git a/pre b/post<RESET>
239
- <BOLD>index 330b04f..5ed8eff 100644<RESET>
244
+ <BOLD>index $pre..$post 100644<RESET>
245
<BOLD>--- a/pre<RESET>
246
<BOLD>+++ b/post<RESET>
247
<CYAN>@@ -1,3 +1,7 @@<RESET>
@@ -254,9 +259,11 @@ test_expect_success 'use configured regex' '
259
test_expect_success 'test parsing words for newline' '
260
echo "aaa (aaa)" >pre &&
261
echo "aaa (aaa) aaa" >post &&
257
- cat >expect <<-\EOF &&
262
+ pre=$(git rev-parse --short $(git hash-object pre)) &&
263
+ post=$(git rev-parse --short $(git hash-object post)) &&
264
+ cat >expect <<-EOF &&
265
<BOLD>diff --git a/pre b/post<RESET>
259
- <BOLD>index c29453b..be22f37 100644<RESET>
266
+ <BOLD>index $pre..$post 100644<RESET>
267
<BOLD>--- a/pre<RESET>
268
<BOLD>+++ b/post<RESET>
269
<CYAN>@@ -1 +1 @@<RESET>
@@ -268,9 +275,11 @@ test_expect_success 'test parsing words for newline' '
275
test_expect_success 'test when words are only removed at the end' '
276
echo "(:" >pre &&
277
echo "(" >post &&
271
- cat >expect <<-\EOF &&
278
+ pre=$(git rev-parse --short $(git hash-object pre)) &&
279
+ post=$(git rev-parse --short $(git hash-object post)) &&
280
+ cat >expect <<-EOF &&
281
<BOLD>diff --git a/pre b/post<RESET>
273
- <BOLD>index 289cb9d..2d06f37 100644<RESET>
282
+ <BOLD>index $pre..$post 100644<RESET>
283
<BOLD>--- a/pre<RESET>
284
<BOLD>+++ b/post<RESET>
285
<CYAN>@@ -1 +1 @@<RESET>
@@ -282,9 +291,11 @@ test_expect_success 'test when words are only removed at the end' '
291
test_expect_success '--word-diff=none' '
292
echo "(:" >pre &&
293
echo "(" >post &&
285
- cat >expect <<-\EOF &&
294
+ pre=$(git rev-parse --short $(git hash-object pre)) &&
295
+ post=$(git rev-parse --short $(git hash-object post)) &&
296
+ cat >expect <<-EOF &&
297
diff --git a/pre b/post
287
- index 289cb9d..2d06f37 100644
298
+ index $pre..$post 100644
299
--- a/pre
300
+++ b/post
301
@@ -1 +1 @@
@@ -317,16 +328,6 @@ test_language_driver ruby
328
test_language_driver tex
329
330
test_expect_success 'word-diff with diff.sbe' '
320
- cat >expect <<-\EOF &&
321
- diff --git a/pre b/post
322
- index a1a53b5..bc8fe6d 100644
323
- --- a/pre
324
- +++ b/post
325
- @@ -1,3 +1,3 @@
326
- a
327
-
328
- [-b-]{+c+}
329
- EOF
331
cat >pre <<-\EOF &&
332
a
333
@@ -337,21 +338,35 @@ test_expect_success 'word-diff with diff.sbe' '
338
339
c
340
EOF
341
+ pre=$(git rev-parse --short $(git hash-object pre)) &&
342
+ post=$(git rev-parse --short $(git hash-object post)) &&
343
+ cat >expect <<-EOF &&
344
+ diff --git a/pre b/post
345
+ index $pre..$post 100644
346
+ --- a/pre
347
+ +++ b/post
348
+ @@ -1,3 +1,3 @@
349
+ a
350
+
351
+ [-b-]{+c+}
352
+ EOF
353
test_config diff.suppress-blank-empty true &&
354
word_diff --word-diff=plain
355
'
356
357
test_expect_success 'word-diff with no newline at EOF' '
345
- cat >expect <<-\EOF &&
358
+ printf "%s" "a a a a a" >pre &&
359
+ printf "%s" "a a ab a a" >post &&
360
+ pre=$(git rev-parse --short $(git hash-object pre)) &&
361
+ post=$(git rev-parse --short $(git hash-object post)) &&
362
+ cat >expect <<-EOF &&
363
diff --git a/pre b/post
347
- index 7bf316e..3dd0303 100644
364
+ index $pre..$post 100644
365
--- a/pre
366
+++ b/post
367
@@ -1 +1 @@
368
a a [-a-]{+ab+} a a
369
EOF
353
- printf "%s" "a a a a a" >pre &&
354
- printf "%s" "a a ab a a" >post &&
370
word_diff --word-diff=plain
371
'
372