diff mbox series

[v2,01/10] cat-file tests: test for bogus type name handling

Message ID patch-01.10-5818eca45d-20210420T124428Z-avarab@gmail.com (mailing list archive)
State New
Headers show
Series object.c et al: tests, small bug fixes etc. | expand

Commit Message

Ævar Arnfjörð Bjarmason April 20, 2021, 12:50 p.m. UTC
Add a test of how "cat-file" behaves when given a bogus type in its
"git cat-file <TYPE> <OBJECT>" mode. There were existing tests (just
below this one) for "-t bogus" or "--allow-unknown-type" modes, but
none for the switch-less mode.

This test is similar to the one that exists for "git hash-object"
already, see b7994af0f92 (type_from_string_gently: make sure length
matches, 2015-04-17).

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
---
 t/t1006-cat-file.sh | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)

Comments

Junio C Hamano April 29, 2021, 4:15 a.m. UTC | #1
Ævar Arnfjörð Bjarmason  <avarab@gmail.com> writes:

> Add a test of how "cat-file" behaves when given a bogus type in its
> "git cat-file <TYPE> <OBJECT>" mode. There were existing tests (just
> below this one) for "-t bogus" or "--allow-unknown-type" modes, but
> none for the switch-less mode.
>
> This test is similar to the one that exists for "git hash-object"
> already, see b7994af0f92 (type_from_string_gently: make sure length
> matches, 2015-04-17).
>
> Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
> ---
>  t/t1006-cat-file.sh | 16 ++++++++++++++++
>  1 file changed, 16 insertions(+)
>
> diff --git a/t/t1006-cat-file.sh b/t/t1006-cat-file.sh
> index 5d2dc99b74..908797dcae 100755
> --- a/t/t1006-cat-file.sh
> +++ b/t/t1006-cat-file.sh
> @@ -315,6 +315,22 @@ test_expect_success '%(deltabase) reports packed delta bases' '
>  	}
>  '
>  
> +test_expect_success 'cat-file complains about bogus type name' '
> +	test_must_fail git cat-file co HEAD >out 2>err &&
> +	test_must_be_empty out &&
> +	cat >expected <<-\EOF &&
> +	fatal: invalid object type "co"
> +	EOF
> +	test_cmp expected err &&
> +
> +	test_must_fail git cat-file bogus HEAD >out 2>err &&
> +	test_must_be_empty out &&
> +	cat >expected <<-\EOF &&
> +	fatal: invalid object type "bogus"
> +	EOF
> +	test_cmp expected err
> +'

I am not 100% sure if it is worth testing both "co" and "bogus", but
if it were, then I'd prefer to have these two as independent test
pieces, because a convincing "we need to have both of these tested
for this reason" would very much likely say that these two kinds of
bugs can come from different/independent bug sources.

FWIW, the commit b7994af0 (type_from_string_gently: make sure length
matches, 2015-04-17) used as a model for this patch uses two
separate tests (one for truncated, the other for bogus).

>  bogus_type="bogus"
>  bogus_content="bogus"
>  bogus_size=$(strlen "$bogus_content")
diff mbox series

Patch

diff --git a/t/t1006-cat-file.sh b/t/t1006-cat-file.sh
index 5d2dc99b74..908797dcae 100755
--- a/t/t1006-cat-file.sh
+++ b/t/t1006-cat-file.sh
@@ -315,6 +315,22 @@  test_expect_success '%(deltabase) reports packed delta bases' '
 	}
 '
 
+test_expect_success 'cat-file complains about bogus type name' '
+	test_must_fail git cat-file co HEAD >out 2>err &&
+	test_must_be_empty out &&
+	cat >expected <<-\EOF &&
+	fatal: invalid object type "co"
+	EOF
+	test_cmp expected err &&
+
+	test_must_fail git cat-file bogus HEAD >out 2>err &&
+	test_must_be_empty out &&
+	cat >expected <<-\EOF &&
+	fatal: invalid object type "bogus"
+	EOF
+	test_cmp expected err
+'
+
 bogus_type="bogus"
 bogus_content="bogus"
 bogus_size=$(strlen "$bogus_content")