Skip to content

Commit e0a646e

Browse files
bk2204gitster
authored andcommitted
t9700: make hash size independent
The Perl test script for t9700 was matching on exactly 40 hex characters. With SHA-256, we'll have 64 hex-character object IDs. Create a variable with a regex which matches exactly 40 or 64 hex characters and use that to match the output. Note that both of the uses of this can be anchored, which makes the code simpler, so do that as well. Signed-off-by: brian m. carlson <[email protected]> Reviewed-by: Eric Sunshine <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 6ff6a67 commit e0a646e

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

t/t9700/test.pl

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ sub adjust_dirsep {
2323
return $path;
2424
}
2525

26+
my $oid_re = qr/^[0-9a-fA-F]{40}(?:[0-9a-fA-F]{24})?$/;
27+
2628
BEGIN { use_ok('Git') }
2729

2830
# set up
@@ -93,7 +95,7 @@ sub adjust_dirsep {
9395
open TEMPFILE, ">$tmpfile" or die "Can't open $tmpfile: $!";
9496
print TEMPFILE my $test_text = "test blob, to be inserted\n";
9597
close TEMPFILE or die "Failed writing to $tmpfile: $!";
96-
like(our $newhash = $r->hash_and_insert_object($tmpfile), qr/[0-9a-fA-F]{40}/,
98+
like(our $newhash = $r->hash_and_insert_object($tmpfile), $oid_re,
9799
"hash_and_insert_object: returns hash");
98100
open TEMPFILE, "+>$tmpfile" or die "Can't open $tmpfile: $!";
99101
is($r->cat_blob($newhash, \*TEMPFILE), length $test_text, "cat_blob: roundtrip size");
@@ -119,7 +121,7 @@ sub adjust_dirsep {
119121

120122
# commands in sub directory
121123
my $last_commit = $r2->command_oneline(qw(rev-parse --verify HEAD));
122-
like($last_commit, qr/^[0-9a-fA-F]{40}$/, 'rev-parse returned hash');
124+
like($last_commit, $oid_re, 'rev-parse returned hash');
123125
my $dir_commit = $r2->command_oneline('log', '-n1', '--pretty=format:%H', '.');
124126
isnt($last_commit, $dir_commit, 'log . does not show last commit');
125127

0 commit comments

Comments
 (0)