t4013: make test hash independent
This test produces a large number of diff formats and compares the output with test files that have content specific to SHA-1. Since we are more interested in the format of the diffs, and not their specific values, which are tested elsewhere, add a function which uses sed to transform these specific object IDs into generic ones of the right size, which we can then compare. Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
brian m. carlson committed
Feb 7, 2020 at 00:52 UTC
72f936b1206d807a2a252a71367a392001a83390
1 file changed
+38
-6
t/t4013-diff-various.sh
+38
-6
@@ -120,6 +120,30 @@ test_expect_success setup '
120
+*++ [initial] Initial
121
EOF
122
123
+process_diffs () {
124
+ _x04="[0-9a-f][0-9a-f][0-9a-f][0-9a-f]" &&
125
+ _x07="$_x05[0-9a-f][0-9a-f]" &&
126
+ sed -e "s/$OID_REGEX/$ZERO_OID/g" \
127
+ -e "s/From $_x40 /From $ZERO_OID /" \
128
+ -e "s/from $_x40)/from $ZERO_OID)/" \
129
+ -e "s/commit $_x40\$/commit $ZERO_OID/" \
130
+ -e "s/commit $_x40 (/commit $ZERO_OID (/" \
131
+ -e "s/$_x40 $_x40 $_x40/$ZERO_OID $ZERO_OID $ZERO_OID/" \
132
+ -e "s/$_x40 $_x40 /$ZERO_OID $ZERO_OID /" \
133
+ -e "s/^$_x40 $_x40$/$ZERO_OID $ZERO_OID/" \
134
+ -e "s/^$_x40 /$ZERO_OID /" \
135
+ -e "s/^$_x40$/$ZERO_OID/" \
136
+ -e "s/$_x07\.\.$_x07/fffffff..fffffff/g" \
137
+ -e "s/$_x07,$_x07\.\.$_x07/fffffff,fffffff..fffffff/g" \
138
+ -e "s/$_x07 $_x07 $_x07/fffffff fffffff fffffff/g" \
139
+ -e "s/$_x07 $_x07 /fffffff fffffff /g" \
140
+ -e "s/Merge: $_x07 $_x07/Merge: fffffff fffffff/g" \
141
+ -e "s/$_x07\.\.\./fffffff.../g" \
142
+ -e "s/ $_x04\.\.\./ ffff.../g" \
143
+ -e "s/ $_x04/ ffff/g" \
144
+ "$1"
145
+}
146
+
147
V=$(git version | sed -e 's/^git version //' -e 's/\./\\./g')
148
while read magic cmd
149
do
@@ -158,13 +182,15 @@ do
182
} >"$actual" &&
183
if test -f "$expect"
184
then
185
+ process_diffs "$actual" >actual &&
186
+ process_diffs "$expect" >expect &&
187
case $cmd in
188
*format-patch* | *-stat*)
163
- test_i18ncmp "$expect" "$actual";;
189
+ test_i18ncmp expect actual;;
190
*)
165
- test_cmp "$expect" "$actual";;
191
+ test_cmp expect actual;;
192
esac &&
167
- rm -f "$actual"
193
+ rm -f "$actual" actual expect
194
else
195
# this is to help developing new tests.
196
cp "$actual" "$expect"
@@ -383,16 +409,22 @@ test_expect_success 'log -S requires an argument' '
409
test_expect_success 'diff --cached on unborn branch' '
410
echo ref: refs/heads/unborn >.git/HEAD &&
411
git diff --cached >result &&
386
- test_cmp "$TEST_DIRECTORY/t4013/diff.diff_--cached" result
412
+ process_diffs result >actual &&
413
+ process_diffs "$TEST_DIRECTORY/t4013/diff.diff_--cached" >expected &&
414
+ test_cmp expected actual
415
'
416
417
test_expect_success 'diff --cached -- file on unborn branch' '
418
git diff --cached -- file0 >result &&
391
- test_cmp "$TEST_DIRECTORY/t4013/diff.diff_--cached_--_file0" result
419
+ process_diffs result >actual &&
420
+ process_diffs "$TEST_DIRECTORY/t4013/diff.diff_--cached_--_file0" >expected &&
421
+ test_cmp expected actual
422
'
423
test_expect_success 'diff --line-prefix with spaces' '
424
git diff --line-prefix="| | | " --cached -- file0 >result &&
395
- test_cmp "$TEST_DIRECTORY/t4013/diff.diff_--line-prefix_--cached_--_file0" result
425
+ process_diffs result >actual &&
426
+ process_diffs "$TEST_DIRECTORY/t4013/diff.diff_--line-prefix_--cached_--_file0" >expected &&
427
+ test_cmp expected actual
428
'
429
430
test_expect_success 'diff-tree --stdin with log formatting' '