t1006: modernize test style to use test_cmp

The tests for git-cat-file(1) are quite old and haven't ever been
updated since they were introduced. They thus tend to use old idioms
that have since grown outdated. Most importantly, many of the tests use
`test $A = $B` to compare expected and actual output. This has the
downside that it is impossible to tell what exactly is different between
both versions in case the test fails.

Refactor the tests to instead use `test_cmp`. While more verbose, it
both tends to be more readable and will result in a nice diff in case
states don't match.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Patrick Steinhardt
2023-06-06 07:19:33 +02:00
committed by Junio C Hamano
parent c7309f63c6
commit b116c77307

View File

@ -296,9 +296,11 @@ tag_size=$(strlen "$tag_content")
run_tests 'tag' $tag_sha1 $tag_size "$tag_content" "$tag_content" run_tests 'tag' $tag_sha1 $tag_size "$tag_content" "$tag_content"
test_expect_success \ test_expect_success "Reach a blob from a tag pointing to it" '
"Reach a blob from a tag pointing to it" \ echo_without_newline "$hello_content" >expect &&
"test '$hello_content' = \"\$(git cat-file blob $tag_sha1)\"" git cat-file blob $tag_sha1 >actual &&
test_cmp expect actual
'
for batch in batch batch-check batch-command for batch in batch batch-check batch-command
do do
@ -334,30 +336,47 @@ do
done done
test_expect_success "--batch-check for a non-existent named object" ' test_expect_success "--batch-check for a non-existent named object" '
test "foobar42 missing cat >expect <<-EOF &&
foobar84 missing" = \ foobar42 missing
"$( ( echo foobar42 && echo_without_newline foobar84 ) | git cat-file --batch-check)" foobar84 missing
EOF
printf "foobar42\nfoobar84" >in &&
git cat-file --batch-check <in >actual &&
test_cmp expect actual
' '
test_expect_success "--batch-check for a non-existent hash" ' test_expect_success "--batch-check for a non-existent hash" '
test "0000000000000000000000000000000000000042 missing cat >expect <<-EOF &&
0000000000000000000000000000000000000084 missing" = \ 0000000000000000000000000000000000000042 missing
"$( ( echo 0000000000000000000000000000000000000042 && 0000000000000000000000000000000000000084 missing
echo_without_newline 0000000000000000000000000000000000000084 ) | EOF
git cat-file --batch-check)"
printf "0000000000000000000000000000000000000042\n0000000000000000000000000000000000000084" >in &&
git cat-file --batch-check <in >actual &&
test_cmp expect actual
' '
test_expect_success "--batch for an existent and a non-existent hash" ' test_expect_success "--batch for an existent and a non-existent hash" '
test "$tag_sha1 tag $tag_size cat >expect <<-EOF &&
$tag_content $tag_sha1 tag $tag_size
0000000000000000000000000000000000000000 missing" = \ $tag_content
"$( ( echo $tag_sha1 && 0000000000000000000000000000000000000000 missing
echo_without_newline 0000000000000000000000000000000000000000 ) | EOF
git cat-file --batch)"
printf "$tag_sha1\n0000000000000000000000000000000000000000" >in &&
git cat-file --batch <in >actual &&
test_cmp expect actual
' '
test_expect_success "--batch-check for an empty line" ' test_expect_success "--batch-check for an empty line" '
test " missing" = "$(echo | git cat-file --batch-check)" cat >expect <<-EOF &&
missing
EOF
echo >in &&
git cat-file --batch-check <in >actual &&
test_cmp expect actual
' '
test_expect_success 'empty --batch-check notices missing object' ' test_expect_success 'empty --batch-check notices missing object' '
@ -384,7 +403,8 @@ deadbeef missing
test_expect_success '--batch with multiple sha1s gives correct format' ' test_expect_success '--batch with multiple sha1s gives correct format' '
echo "$batch_output" >expect && echo "$batch_output" >expect &&
echo_without_newline "$batch_input" | git cat-file --batch >actual && echo_without_newline "$batch_input" >in &&
git cat-file --batch <in >actual &&
test_cmp expect actual test_cmp expect actual
' '
@ -411,13 +431,17 @@ deadbeef missing
missing" missing"
test_expect_success "--batch-check with multiple sha1s gives correct format" ' test_expect_success "--batch-check with multiple sha1s gives correct format" '
test "$batch_check_output" = \ echo "$batch_check_output" >expect &&
"$(echo_without_newline "$batch_check_input" | git cat-file --batch-check)" echo_without_newline "$batch_check_input" >in &&
git cat-file --batch-check <in >actual &&
test_cmp expect actual
' '
test_expect_success "--batch-check, -z with multiple sha1s gives correct format" ' test_expect_success "--batch-check, -z with multiple sha1s gives correct format" '
echo_without_newline_nul "$batch_check_input" >in && echo "$batch_check_output" >expect &&
test "$batch_check_output" = "$(git cat-file --batch-check -z <in)" echo_without_newline_nul "$batch_check_input" >in &&
git cat-file --batch-check -z <in >actual &&
test_cmp expect actual
' '
test_expect_success FUNNYNAMES '--batch-check, -z with newline in input' ' test_expect_success FUNNYNAMES '--batch-check, -z with newline in input' '