Skip to content

Commit 3e370f9

Browse files
KarthikNayakgitster
authored andcommitted
t1006: add tests for git cat-file --allow-unknown-type
Signed-off-by: Karthik Nayak <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 39e4ae3 commit 3e370f9

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed

t/t1006-cat-file.sh

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,18 @@ $content"
4747
test_cmp expect actual
4848
'
4949

50+
test_expect_success "Type of $type is correct using --allow-unknown-type" '
51+
echo $type >expect &&
52+
git cat-file -t --allow-unknown-type $sha1 >actual &&
53+
test_cmp expect actual
54+
'
55+
56+
test_expect_success "Size of $type is correct using --allow-unknown-type" '
57+
echo $size >expect &&
58+
git cat-file -s --allow-unknown-type $sha1 >actual &&
59+
test_cmp expect actual
60+
'
61+
5062
test -z "$content" ||
5163
test_expect_success "Content of $type is correct" '
5264
maybe_remove_timestamp "$content" $no_ts >expect &&
@@ -296,4 +308,37 @@ test_expect_success '%(deltabase) reports packed delta bases' '
296308
}
297309
'
298310

311+
bogus_type="bogus"
312+
bogus_content="bogus"
313+
bogus_size=$(strlen "$bogus_content")
314+
bogus_sha1=$(echo_without_newline "$bogus_content" | git hash-object -t $bogus_type --literally -w --stdin)
315+
316+
test_expect_success "Type of broken object is correct" '
317+
echo $bogus_type >expect &&
318+
git cat-file -t --allow-unknown-type $bogus_sha1 >actual &&
319+
test_cmp expect actual
320+
'
321+
322+
test_expect_success "Size of broken object is correct" '
323+
echo $bogus_size >expect &&
324+
git cat-file -s --allow-unknown-type $bogus_sha1 >actual &&
325+
test_cmp expect actual
326+
'
327+
bogus_type="abcdefghijklmnopqrstuvwxyz1234679"
328+
bogus_content="bogus"
329+
bogus_size=$(strlen "$bogus_content")
330+
bogus_sha1=$(echo_without_newline "$bogus_content" | git hash-object -t $bogus_type --literally -w --stdin)
331+
332+
test_expect_success "Type of broken object is correct when type is large" '
333+
echo $bogus_type >expect &&
334+
git cat-file -t --allow-unknown-type $bogus_sha1 >actual &&
335+
test_cmp expect actual
336+
'
337+
338+
test_expect_success "Size of large broken object is correct when type is large" '
339+
echo $bogus_size >expect &&
340+
git cat-file -s --allow-unknown-type $bogus_sha1 >actual &&
341+
test_cmp expect actual
342+
'
343+
299344
test_done

0 commit comments

Comments
 (0)