Skip to content

Commit 72f936b

Browse files
bk2204gitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 5df0f11 commit 72f936b

File tree

1 file changed

+38
-6
lines changed

1 file changed

+38
-6
lines changed

t/t4013-diff-various.sh

Lines changed: 38 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,30 @@ test_expect_success setup '
120120
+*++ [initial] Initial
121121
EOF
122122

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+
123147
V=$(git version | sed -e 's/^git version //' -e 's/\./\\./g')
124148
while read magic cmd
125149
do
@@ -158,13 +182,15 @@ do
158182
} >"$actual" &&
159183
if test -f "$expect"
160184
then
185+
process_diffs "$actual" >actual &&
186+
process_diffs "$expect" >expect &&
161187
case $cmd in
162188
*format-patch* | *-stat*)
163-
test_i18ncmp "$expect" "$actual";;
189+
test_i18ncmp expect actual;;
164190
*)
165-
test_cmp "$expect" "$actual";;
191+
test_cmp expect actual;;
166192
esac &&
167-
rm -f "$actual"
193+
rm -f "$actual" actual expect
168194
else
169195
# this is to help developing new tests.
170196
cp "$actual" "$expect"
@@ -383,16 +409,22 @@ test_expect_success 'log -S requires an argument' '
383409
test_expect_success 'diff --cached on unborn branch' '
384410
echo ref: refs/heads/unborn >.git/HEAD &&
385411
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
387415
'
388416

389417
test_expect_success 'diff --cached -- file on unborn branch' '
390418
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
392422
'
393423
test_expect_success 'diff --line-prefix with spaces' '
394424
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
396428
'
397429

398430
test_expect_success 'diff-tree --stdin with log formatting' '

0 commit comments

Comments
 (0)