Skip to content

Commit 902f414

Browse files
phillipwoodgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Phillip Wood <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 11489a6 commit 902f414

File tree

1 file changed

+23
-10
lines changed

1 file changed

+23
-10
lines changed

t/t3701-add-interactive.sh

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,19 @@ then
1010
test_done
1111
fi
1212

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+
1326
test_expect_success 'setup (initial)' '
1427
echo content >file &&
1528
git add file &&
@@ -35,7 +48,7 @@ test_expect_success 'setup expected' '
3548
test_expect_success 'diff works (initial)' '
3649
(echo d; echo 1) | git add -i >output &&
3750
sed -ne "/new file/,/content/p" <output >diff &&
38-
test_cmp expected diff
51+
diff_cmp expected diff
3952
'
4053
test_expect_success 'revert works (initial)' '
4154
git add file &&
@@ -72,7 +85,7 @@ test_expect_success 'setup expected' '
7285
test_expect_success 'diff works (commit)' '
7386
(echo d; echo 1) | git add -i >output &&
7487
sed -ne "/^index/,/content/p" <output >diff &&
75-
test_cmp expected diff
88+
diff_cmp expected diff
7689
'
7790
test_expect_success 'revert works (commit)' '
7891
git add file &&
@@ -91,7 +104,7 @@ test_expect_success 'dummy edit works' '
91104
test_set_editor : &&
92105
(echo e; echo a) | git add -p &&
93106
git diff > diff &&
94-
test_cmp expected diff
107+
diff_cmp expected diff
95108
'
96109

97110
test_expect_success 'setup patch' '
@@ -159,7 +172,7 @@ test_expect_success 'setup expected' '
159172
test_expect_success 'real edit works' '
160173
(echo e; echo n; echo d) | git add -p &&
161174
git diff >output &&
162-
test_cmp expected output
175+
diff_cmp expected output
163176
'
164177

165178
test_expect_success 'skip files similarly as commit -a' '
@@ -171,7 +184,7 @@ test_expect_success 'skip files similarly as commit -a' '
171184
git reset &&
172185
git commit -am commit &&
173186
git diff >expected &&
174-
test_cmp expected output &&
187+
diff_cmp expected output &&
175188
git reset --hard HEAD^
176189
'
177190
rm -f .gitignore
@@ -248,7 +261,7 @@ test_expect_success 'add first line works' '
248261
git apply patch &&
249262
(echo s; echo y; echo y) | git add -p file &&
250263
git diff --cached > diff &&
251-
test_cmp expected diff
264+
diff_cmp expected diff
252265
'
253266

254267
test_expect_success 'setup expected' '
@@ -271,7 +284,7 @@ test_expect_success 'deleting a non-empty file' '
271284
rm non-empty &&
272285
echo y | git add -p non-empty &&
273286
git diff --cached >diff &&
274-
test_cmp expected diff
287+
diff_cmp expected diff
275288
'
276289

277290
test_expect_success 'setup expected' '
@@ -290,7 +303,7 @@ test_expect_success 'deleting an empty file' '
290303
rm empty &&
291304
echo y | git add -p empty &&
292305
git diff --cached >diff &&
293-
test_cmp expected diff
306+
diff_cmp expected diff
294307
'
295308

296309
test_expect_success 'split hunk setup' '
@@ -355,7 +368,7 @@ test_expect_success 'patch mode ignores unmerged entries' '
355368
+changed
356369
EOF
357370
git diff --cached >diff &&
358-
test_cmp expected diff
371+
diff_cmp expected diff
359372
'
360373

361374
test_expect_success TTY 'diffs can be colorized' '
@@ -384,7 +397,7 @@ test_expect_success 'patch-mode via -i prompts for files' '
384397
385398
echo test >expect &&
386399
git diff --cached --name-only >actual &&
387-
test_cmp expect actual
400+
diff_cmp expect actual
388401
'
389402

390403
test_expect_success 'add -p handles globs' '

0 commit comments

Comments
 (0)