t3206: abstract away hash size constants
The various short object IDs in the range-diff output differ between hash algorithms. Use test_oid_cache to look up values for both SHA-1 and SHA-256. Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
brian m. carlson committed
Aug 18, 2019 at 19:16 UTC
b561edd213f9a37e874e5726375d49e8f4d2037b
1 file changed
+167
-60
t/t3206-range-diff.sh
+167
-60
@@ -8,17 +8,124 @@ test_description='range-diff tests'
8
# harm than good. We need some real history.
9
10
test_expect_success 'setup' '
11
- git fast-import < "$TEST_DIRECTORY"/t3206/history.export
11
+ git fast-import < "$TEST_DIRECTORY"/t3206/history.export &&
12
+ test_oid_cache <<-EOF
13
+ # topic
14
+ t1 sha1:4de457d
15
+ t2 sha1:fccce22
16
+ t3 sha1:147e64e
17
+ t4 sha1:a63e992
18
+ t1 sha256:b89f8b9
19
+ t2 sha256:5f12aad
20
+ t3 sha256:ea8b273
21
+ t4 sha256:14b7336
22
+
23
+ # unmodified
24
+ u1 sha1:35b9b25
25
+ u2 sha1:de345ab
26
+ u3 sha1:9af6654
27
+ u4 sha1:2901f77
28
+ u1 sha256:e3731be
29
+ u2 sha256:14fadf8
30
+ u3 sha256:736c4bc
31
+ u4 sha256:673e77d
32
+
33
+ # reordered
34
+ r1 sha1:aca177a
35
+ r2 sha1:14ad629
36
+ r3 sha1:ee58208
37
+ r4 sha1:307b27a
38
+ r1 sha256:f59d3aa
39
+ r2 sha256:fb261a8
40
+ r3 sha256:cb2649b
41
+ r4 sha256:958577e
42
+
43
+ # removed (deleted)
44
+ d1 sha1:7657159
45
+ d2 sha1:43d84d3
46
+ d3 sha1:a740396
47
+ d1 sha256:e312513
48
+ d2 sha256:eb19258
49
+ d3 sha256:1ccb3c1
50
+
51
+ # added
52
+ a1 sha1:2716022
53
+ a2 sha1:b62accd
54
+ a3 sha1:df46cfa
55
+ a4 sha1:3e64548
56
+ a5 sha1:12b4063
57
+ a1 sha256:d724f4d
58
+ a2 sha256:1de7762
59
+ a3 sha256:e159431
60
+ a4 sha256:b3e483c
61
+ a5 sha256:90866a7
62
+
63
+ # rebased
64
+ b1 sha1:cc9c443
65
+ b2 sha1:c5d9641
66
+ b3 sha1:28cc2b6
67
+ b4 sha1:5628ab7
68
+ b5 sha1:a31b12e
69
+ b1 sha256:a1a8717
70
+ b2 sha256:20a5862
71
+ b3 sha256:587172a
72
+ b4 sha256:2721c5d
73
+ b5 sha256:7b57864
74
+
75
+ # changed
76
+ c1 sha1:a4b3333
77
+ c2 sha1:f51d370
78
+ c3 sha1:0559556
79
+ c4 sha1:d966c5c
80
+ c1 sha256:f8c2b9d
81
+ c2 sha256:3fb6318
82
+ c3 sha256:168ab68
83
+ c4 sha256:3526539
84
+
85
+ # changed-message
86
+ m1 sha1:f686024
87
+ m2 sha1:4ab067d
88
+ m3 sha1:b9cb956
89
+ m4 sha1:8add5f1
90
+ m1 sha256:31e6281
91
+ m2 sha256:a06bf1b
92
+ m3 sha256:82dc654
93
+ m4 sha256:48470c5
94
+
95
+ # renamed
96
+ n1 sha1:f258d75
97
+ n2 sha1:017b62d
98
+ n3 sha1:3ce7af6
99
+ n4 sha1:1e6226b
100
+ n1 sha256:ad52114
101
+ n2 sha256:3b54c8f
102
+ n3 sha256:3b0a644
103
+ n4 sha256:e461653
104
+
105
+ # added and removed
106
+ s1 sha1:096b1ba
107
+ s2 sha1:d92e698
108
+ s3 sha1:9a1db4d
109
+ s4 sha1:fea3b5c
110
+ s1 sha256:a7f9134
111
+ s2 sha256:b4c2580
112
+ s3 sha256:1d62aa2
113
+ s4 sha256:48160e8
114
+
115
+ # Empty delimiter (included so lines match neatly)
116
+ __ sha1:-------
117
+ __ sha256:-------
118
+ EOF
119
'
120
121
test_expect_success 'simple A..B A..C (unmodified)' '
122
git range-diff --no-color master..topic master..unmodified \
123
>actual &&
124
cat >expected <<-EOF &&
18
- 1: 4de457d = 1: 35b9b25 s/5/A/
19
- 2: fccce22 = 2: de345ab s/4/A/
20
- 3: 147e64e = 3: 9af6654 s/11/B/
21
- 4: a63e992 = 4: 2901f77 s/12/B/
125
+ 1: $(test_oid t1) = 1: $(test_oid u1) s/5/A/
126
+ 2: $(test_oid t2) = 2: $(test_oid u2) s/4/A/
127
+ 3: $(test_oid t3) = 3: $(test_oid u3) s/11/B/
128
+ 4: $(test_oid t4) = 4: $(test_oid u4) s/12/B/
129
EOF
130
test_cmp expected actual
131
'
@@ -38,10 +145,10 @@ test_expect_success 'simple A B C (unmodified)' '
145
test_expect_success 'trivial reordering' '
146
git range-diff --no-color master topic reordered >actual &&
147
cat >expected <<-EOF &&
41
- 1: 4de457d = 1: aca177a s/5/A/
42
- 3: 147e64e = 2: 14ad629 s/11/B/
43
- 4: a63e992 = 3: ee58208 s/12/B/
44
- 2: fccce22 = 4: 307b27a s/4/A/
148
+ 1: $(test_oid t1) = 1: $(test_oid r1) s/5/A/
149
+ 3: $(test_oid t3) = 2: $(test_oid r2) s/11/B/
150
+ 4: $(test_oid t4) = 3: $(test_oid r3) s/12/B/
151
+ 2: $(test_oid t2) = 4: $(test_oid r4) s/4/A/
152
EOF
153
test_cmp expected actual
154
'
@@ -49,10 +156,10 @@ test_expect_success 'trivial reordering' '
156
test_expect_success 'removed a commit' '
157
git range-diff --no-color master topic removed >actual &&
158
cat >expected <<-EOF &&
52
- 1: 4de457d = 1: 7657159 s/5/A/
53
- 2: fccce22 < -: ------- s/4/A/
54
- 3: 147e64e = 2: 43d84d3 s/11/B/
55
- 4: a63e992 = 3: a740396 s/12/B/
159
+ 1: $(test_oid t1) = 1: $(test_oid d1) s/5/A/
160
+ 2: $(test_oid t2) < -: $(test_oid __) s/4/A/
161
+ 3: $(test_oid t3) = 2: $(test_oid d2) s/11/B/
162
+ 4: $(test_oid t4) = 3: $(test_oid d3) s/12/B/
163
EOF
164
test_cmp expected actual
165
'
@@ -60,11 +167,11 @@ test_expect_success 'removed a commit' '
167
test_expect_success 'added a commit' '
168
git range-diff --no-color master topic added >actual &&
169
cat >expected <<-EOF &&
63
- 1: 4de457d = 1: 2716022 s/5/A/
64
- 2: fccce22 = 2: b62accd s/4/A/
65
- -: ------- > 3: df46cfa s/6/A/
66
- 3: 147e64e = 4: 3e64548 s/11/B/
67
- 4: a63e992 = 5: 12b4063 s/12/B/
170
+ 1: $(test_oid t1) = 1: $(test_oid a1) s/5/A/
171
+ 2: $(test_oid t2) = 2: $(test_oid a2) s/4/A/
172
+ -: $(test_oid __) > 3: $(test_oid a3) s/6/A/
173
+ 3: $(test_oid t3) = 4: $(test_oid a4) s/11/B/
174
+ 4: $(test_oid t4) = 5: $(test_oid a5) s/12/B/
175
EOF
176
test_cmp expected actual
177
'
@@ -72,10 +179,10 @@ test_expect_success 'added a commit' '
179
test_expect_success 'new base, A B C' '
180
git range-diff --no-color master topic rebased >actual &&
181
cat >expected <<-EOF &&
75
- 1: 4de457d = 1: cc9c443 s/5/A/
76
- 2: fccce22 = 2: c5d9641 s/4/A/
77
- 3: 147e64e = 3: 28cc2b6 s/11/B/
78
- 4: a63e992 = 4: 5628ab7 s/12/B/
182
+ 1: $(test_oid t1) = 1: $(test_oid b1) s/5/A/
183
+ 2: $(test_oid t2) = 2: $(test_oid b2) s/4/A/
184
+ 3: $(test_oid t3) = 3: $(test_oid b3) s/11/B/
185
+ 4: $(test_oid t4) = 4: $(test_oid b4) s/12/B/
186
EOF
187
test_cmp expected actual
188
'
@@ -84,11 +191,11 @@ test_expect_success 'new base, B...C' '
191
# this syntax includes the commits from master!
192
git range-diff --no-color topic...rebased >actual &&
193
cat >expected <<-EOF &&
87
- -: ------- > 1: a31b12e unrelated
88
- 1: 4de457d = 2: cc9c443 s/5/A/
89
- 2: fccce22 = 3: c5d9641 s/4/A/
90
- 3: 147e64e = 4: 28cc2b6 s/11/B/
91
- 4: a63e992 = 5: 5628ab7 s/12/B/
194
+ -: $(test_oid __) > 1: $(test_oid b5) unrelated
195
+ 1: $(test_oid t1) = 2: $(test_oid b1) s/5/A/
196
+ 2: $(test_oid t2) = 3: $(test_oid b2) s/4/A/
197
+ 3: $(test_oid t3) = 4: $(test_oid b3) s/11/B/
198
+ 4: $(test_oid t4) = 5: $(test_oid b4) s/12/B/
199
EOF
200
test_cmp expected actual
201
'
@@ -96,9 +203,9 @@ test_expect_success 'new base, B...C' '
203
test_expect_success 'changed commit' '
204
git range-diff --no-color topic...changed >actual &&
205
cat >expected <<-EOF &&
99
- 1: 4de457d = 1: a4b3333 s/5/A/
100
- 2: fccce22 = 2: f51d370 s/4/A/
101
- 3: 147e64e ! 3: 0559556 s/11/B/
206
+ 1: $(test_oid t1) = 1: $(test_oid c1) s/5/A/
207
+ 2: $(test_oid t2) = 2: $(test_oid c2) s/4/A/
208
+ 3: $(test_oid t3) ! 3: $(test_oid c3) s/11/B/
209
@@ file: A
210
9
211
10
@@ -108,7 +215,7 @@ test_expect_success 'changed commit' '
215
12
216
13
217
14
111
- 4: a63e992 ! 4: d966c5c s/12/B/
218
+ 4: $(test_oid t4) ! 4: $(test_oid c4) s/12/B/
219
@@ file
220
@@ file: A
221
9
@@ -125,10 +232,10 @@ test_expect_success 'changed commit' '
232
test_expect_success 'changed commit with --no-patch diff option' '
233
git range-diff --no-color --no-patch topic...changed >actual &&
234
cat >expected <<-EOF &&
128
- 1: 4de457d = 1: a4b3333 s/5/A/
129
- 2: fccce22 = 2: f51d370 s/4/A/
130
- 3: 147e64e ! 3: 0559556 s/11/B/
131
- 4: a63e992 ! 4: d966c5c s/12/B/
235
+ 1: $(test_oid t1) = 1: $(test_oid c1) s/5/A/
236
+ 2: $(test_oid t2) = 2: $(test_oid c2) s/4/A/
237
+ 3: $(test_oid t3) ! 3: $(test_oid c3) s/11/B/
238
+ 4: $(test_oid t4) ! 4: $(test_oid c4) s/12/B/
239
EOF
240
test_cmp expected actual
241
'
@@ -136,16 +243,16 @@ test_expect_success 'changed commit with --no-patch diff option' '
243
test_expect_success 'changed commit with --stat diff option' '
244
git range-diff --no-color --stat topic...changed >actual &&
245
cat >expected <<-EOF &&
139
- 1: 4de457d = 1: a4b3333 s/5/A/
246
+ 1: $(test_oid t1) = 1: $(test_oid c1) s/5/A/
247
a => b | 0
248
1 file changed, 0 insertions(+), 0 deletions(-)
142
- 2: fccce22 = 2: f51d370 s/4/A/
249
+ 2: $(test_oid t2) = 2: $(test_oid c2) s/4/A/
250
a => b | 0
251
1 file changed, 0 insertions(+), 0 deletions(-)
145
- 3: 147e64e ! 3: 0559556 s/11/B/
252
+ 3: $(test_oid t3) ! 3: $(test_oid c3) s/11/B/
253
a => b | 0
254
1 file changed, 0 insertions(+), 0 deletions(-)
148
- 4: a63e992 ! 4: d966c5c s/12/B/
255
+ 4: $(test_oid t4) ! 4: $(test_oid c4) s/12/B/
256
a => b | 0
257
1 file changed, 0 insertions(+), 0 deletions(-)
258
EOF
@@ -155,9 +262,9 @@ test_expect_success 'changed commit with --stat diff option' '
262
test_expect_success 'changed commit with sm config' '
263
git range-diff --no-color --submodule=log topic...changed >actual &&
264
cat >expected <<-EOF &&
158
- 1: 4de457d = 1: a4b3333 s/5/A/
159
- 2: fccce22 = 2: f51d370 s/4/A/
160
- 3: 147e64e ! 3: 0559556 s/11/B/
265
+ 1: $(test_oid t1) = 1: $(test_oid c1) s/5/A/
266
+ 2: $(test_oid t2) = 2: $(test_oid c2) s/4/A/
267
+ 3: $(test_oid t3) ! 3: $(test_oid c3) s/11/B/
268
@@ file: A
269
9
270
10
@@ -167,7 +274,7 @@ test_expect_success 'changed commit with sm config' '
274
12
275
13
276
14
170
- 4: a63e992 ! 4: d966c5c s/12/B/
277
+ 4: $(test_oid t4) ! 4: $(test_oid c4) s/12/B/
278
@@ file
279
@@ file: A
280
9
@@ -184,8 +291,8 @@ test_expect_success 'changed commit with sm config' '
291
test_expect_success 'renamed file' '
292
git range-diff --no-color --submodule=log topic...renamed-file >actual &&
293
sed s/Z/\ /g >expected <<-EOF &&
187
- 1: 4de457d = 1: f258d75 s/5/A/
188
- 2: fccce22 ! 2: 017b62d s/4/A/
294
+ 1: $(test_oid t1) = 1: $(test_oid n1) s/5/A/
295
+ 2: $(test_oid t2) ! 2: $(test_oid n2) s/4/A/
296
@@ Metadata
297
ZAuthor: Thomas Rast <trast@inf.ethz.ch>
298
Z
@@ -198,7 +305,7 @@ test_expect_success 'renamed file' '
305
Z@@
306
Z 1
307
Z 2
201
- 3: 147e64e ! 3: 3ce7af6 s/11/B/
308
+ 3: $(test_oid t3) ! 3: $(test_oid n3) s/11/B/
309
@@ Metadata
310
Z ## Commit message ##
311
Z s/11/B/
@@ -210,7 +317,7 @@ test_expect_success 'renamed file' '
317
Z 8
318
Z 9
319
Z 10
213
- 4: a63e992 ! 4: 1e6226b s/12/B/
320
+ 4: $(test_oid t4) ! 4: $(test_oid n4) s/12/B/
321
@@ Metadata
322
Z ## Commit message ##
323
Z s/12/B/
@@ -229,8 +336,8 @@ test_expect_success 'renamed file' '
336
test_expect_success 'file added and later removed' '
337
git range-diff --no-color --submodule=log topic...added-removed >actual &&
338
sed s/Z/\ /g >expected <<-EOF &&
232
- 1: 4de457d = 1: 096b1ba s/5/A/
233
- 2: fccce22 ! 2: d92e698 s/4/A/
339
+ 1: $(test_oid t1) = 1: $(test_oid s1) s/5/A/
340
+ 2: $(test_oid t2) ! 2: $(test_oid s2) s/4/A/
341
@@ Metadata
342
ZAuthor: Thomas Rast <trast@inf.ethz.ch>
343
Z
@@ -246,7 +353,7 @@ test_expect_success 'file added and later removed' '
353
Z 7
354
+
355
+ ## new-file (new) ##
249
- 3: 147e64e ! 3: 9a1db4d s/11/B/
356
+ 3: $(test_oid t3) ! 3: $(test_oid s3) s/11/B/
357
@@ Metadata
358
ZAuthor: Thomas Rast <trast@inf.ethz.ch>
359
Z
@@ -262,7 +369,7 @@ test_expect_success 'file added and later removed' '
369
Z 14
370
+
371
+ ## new-file (deleted) ##
265
- 4: a63e992 = 4: fea3b5c s/12/B/
372
+ 4: $(test_oid t4) = 4: $(test_oid s4) s/12/B/
373
EOF
374
test_cmp expected actual
375
'
@@ -275,8 +382,8 @@ test_expect_success 'no commits on one side' '
382
test_expect_success 'changed message' '
383
git range-diff --no-color topic...changed-message >actual &&
384
sed s/Z/\ /g >expected <<-EOF &&
278
- 1: 4de457d = 1: f686024 s/5/A/
279
- 2: fccce22 ! 2: 4ab067d s/4/A/
385
+ 1: $(test_oid t1) = 1: $(test_oid m1) s/5/A/
386
+ 2: $(test_oid t2) ! 2: $(test_oid m2) s/4/A/
387
@@ Metadata
388
Z ## Commit message ##
389
Z s/4/A/
@@ -286,16 +393,16 @@ test_expect_success 'changed message' '
393
Z ## file ##
394
Z@@
395
Z 1
289
- 3: 147e64e = 3: b9cb956 s/11/B/
290
- 4: a63e992 = 4: 8add5f1 s/12/B/
396
+ 3: $(test_oid t3) = 3: $(test_oid m3) s/11/B/
397
+ 4: $(test_oid t4) = 4: $(test_oid m4) s/12/B/
398
EOF
399
test_cmp expected actual
400
'
401
402
test_expect_success 'dual-coloring' '
296
- sed -e "s|^:||" >expect <<-\EOF &&
297
- :<YELLOW>1: a4b3333 = 1: f686024 s/5/A/<RESET>
298
- :<RED>2: f51d370 <RESET><YELLOW>!<RESET><GREEN> 2: 4ab067d<RESET><YELLOW> s/4/A/<RESET>
403
+ sed -e "s|^:||" >expect <<-EOF &&
404
+ :<YELLOW>1: $(test_oid c1) = 1: $(test_oid m1) s/5/A/<RESET>
405
+ :<RED>2: $(test_oid c2) <RESET><YELLOW>!<RESET><GREEN> 2: $(test_oid m2)<RESET><YELLOW> s/4/A/<RESET>
406
: <REVERSE><CYAN>@@<RESET> <RESET>Metadata<RESET>
407
: ## Commit message ##<RESET>
408
: s/4/A/<RESET>
@@ -305,7 +412,7 @@ test_expect_success 'dual-coloring' '
412
: ## file ##<RESET>
413
: <CYAN> @@<RESET>
414
: 1<RESET>
308
- :<RED>3: 0559556 <RESET><YELLOW>!<RESET><GREEN> 3: b9cb956<RESET><YELLOW> s/11/B/<RESET>
415
+ :<RED>3: $(test_oid c3) <RESET><YELLOW>!<RESET><GREEN> 3: $(test_oid m3)<RESET><YELLOW> s/11/B/<RESET>
416
: <REVERSE><CYAN>@@<RESET> <RESET>file: A<RESET>
417
: 9<RESET>
418
: 10<RESET>
@@ -315,7 +422,7 @@ test_expect_success 'dual-coloring' '
422
: 12<RESET>
423
: 13<RESET>
424
: 14<RESET>
318
- :<RED>4: d966c5c <RESET><YELLOW>!<RESET><GREEN> 4: 8add5f1<RESET><YELLOW> s/12/B/<RESET>
425
+ :<RED>4: $(test_oid c4) <RESET><YELLOW>!<RESET><GREEN> 4: $(test_oid m4)<RESET><YELLOW> s/12/B/<RESET>
426
: <REVERSE><CYAN>@@<RESET> <RESET>file<RESET>
427
: <CYAN> @@ file: A<RESET>
428
: 9<RESET>