t3701: don't hard code sha1 hash values
Use a filter when comparing diffs to fix the value of non-zero hashes in diff index lines so we're not hard coding sha1 hash values in the expected output. This makes it easier to change the expected output if a test is edited as we don't need to worry about the exact hash value and means the tests will work when the hash algorithm is transitioned away from sha1. Thanks-to: Junio C Hamano <gitster@pobox.com> Signed-off-by: Phillip Wood <phillip.wood@dunelm.org.uk> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Phillip Wood committed
Mar 1, 2018 at 10:50 UTC
902f414a72b29ca9c6c575faf29cc2b0b8b4fe1c
1 file changed
+23
-10
t/t3701-add-interactive.sh
+23
-10
@@ -10,6 +10,19 @@ then
10
test_done
11
fi
12
13
+diff_cmp () {
14
+ for x
15
+ do
16
+ sed -e '/^index/s/[0-9a-f]*[1-9a-f][0-9a-f]*\.\./1234567../' \
17
+ -e '/^index/s/\.\.[0-9a-f]*[1-9a-f][0-9a-f]*/..9abcdef/' \
18
+ -e '/^index/s/ 00*\.\./ 0000000../' \
19
+ -e '/^index/s/\.\.00*$/..0000000/' \
20
+ -e '/^index/s/\.\.00* /..0000000 /' \
21
+ "$x" >"$x.filtered"
22
+ done
23
+ test_cmp "$1.filtered" "$2.filtered"
24
+}
25
+
26
test_expect_success 'setup (initial)' '
27
echo content >file &&
28
git add file &&
@@ -35,7 +48,7 @@ test_expect_success 'setup expected' '
48
test_expect_success 'diff works (initial)' '
49
(echo d; echo 1) | git add -i >output &&
50
sed -ne "/new file/,/content/p" <output >diff &&
38
- test_cmp expected diff
51
+ diff_cmp expected diff
52
'
53
test_expect_success 'revert works (initial)' '
54
git add file &&
@@ -72,7 +85,7 @@ test_expect_success 'setup expected' '
85
test_expect_success 'diff works (commit)' '
86
(echo d; echo 1) | git add -i >output &&
87
sed -ne "/^index/,/content/p" <output >diff &&
75
- test_cmp expected diff
88
+ diff_cmp expected diff
89
'
90
test_expect_success 'revert works (commit)' '
91
git add file &&
@@ -91,7 +104,7 @@ test_expect_success 'dummy edit works' '
104
test_set_editor : &&
105
(echo e; echo a) | git add -p &&
106
git diff > diff &&
94
- test_cmp expected diff
107
+ diff_cmp expected diff
108
'
109
110
test_expect_success 'setup patch' '
@@ -159,7 +172,7 @@ test_expect_success 'setup expected' '
172
test_expect_success 'real edit works' '
173
(echo e; echo n; echo d) | git add -p &&
174
git diff >output &&
162
- test_cmp expected output
175
+ diff_cmp expected output
176
'
177
178
test_expect_success 'skip files similarly as commit -a' '
@@ -171,7 +184,7 @@ test_expect_success 'skip files similarly as commit -a' '
184
git reset &&
185
git commit -am commit &&
186
git diff >expected &&
174
- test_cmp expected output &&
187
+ diff_cmp expected output &&
188
git reset --hard HEAD^
189
'
190
rm -f .gitignore
@@ -248,7 +261,7 @@ test_expect_success 'add first line works' '
261
git apply patch &&
262
(echo s; echo y; echo y) | git add -p file &&
263
git diff --cached > diff &&
251
- test_cmp expected diff
264
+ diff_cmp expected diff
265
'
266
267
test_expect_success 'setup expected' '
@@ -271,7 +284,7 @@ test_expect_success 'deleting a non-empty file' '
284
rm non-empty &&
285
echo y | git add -p non-empty &&
286
git diff --cached >diff &&
274
- test_cmp expected diff
287
+ diff_cmp expected diff
288
'
289
290
test_expect_success 'setup expected' '
@@ -290,7 +303,7 @@ test_expect_success 'deleting an empty file' '
303
rm empty &&
304
echo y | git add -p empty &&
305
git diff --cached >diff &&
293
- test_cmp expected diff
306
+ diff_cmp expected diff
307
'
308
309
test_expect_success 'split hunk setup' '
@@ -355,7 +368,7 @@ test_expect_success 'patch mode ignores unmerged entries' '
368
+changed
369
EOF
370
git diff --cached >diff &&
358
- test_cmp expected diff
371
+ diff_cmp expected diff
372
'
373
374
test_expect_success TTY 'diffs can be colorized' '
@@ -384,7 +397,7 @@ test_expect_success 'patch-mode via -i prompts for files' '
397
398
echo test >expect &&
399
git diff --cached --name-only >actual &&
387
- test_cmp expect actual
400
+ diff_cmp expect actual
401
'
402
403
test_expect_success 'add -p handles globs' '