Skip to content

Commit b116c77

Browse files
pks-tgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent c7309f6 commit b116c77

File tree

1 file changed

+47
-23
lines changed

1 file changed

+47
-23
lines changed

t/t1006-cat-file.sh

Lines changed: 47 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -296,9 +296,11 @@ tag_size=$(strlen "$tag_content")
296296

297297
run_tests 'tag' $tag_sha1 $tag_size "$tag_content" "$tag_content"
298298

299-
test_expect_success \
300-
"Reach a blob from a tag pointing to it" \
301-
"test '$hello_content' = \"\$(git cat-file blob $tag_sha1)\""
299+
test_expect_success "Reach a blob from a tag pointing to it" '
300+
echo_without_newline "$hello_content" >expect &&
301+
git cat-file blob $tag_sha1 >actual &&
302+
test_cmp expect actual
303+
'
302304

303305
for batch in batch batch-check batch-command
304306
do
@@ -334,30 +336,47 @@ do
334336
done
335337

336338
test_expect_success "--batch-check for a non-existent named object" '
337-
test "foobar42 missing
338-
foobar84 missing" = \
339-
"$( ( echo foobar42 && echo_without_newline foobar84 ) | git cat-file --batch-check)"
339+
cat >expect <<-EOF &&
340+
foobar42 missing
341+
foobar84 missing
342+
EOF
343+
344+
printf "foobar42\nfoobar84" >in &&
345+
git cat-file --batch-check <in >actual &&
346+
test_cmp expect actual
340347
'
341348

342349
test_expect_success "--batch-check for a non-existent hash" '
343-
test "0000000000000000000000000000000000000042 missing
344-
0000000000000000000000000000000000000084 missing" = \
345-
"$( ( echo 0000000000000000000000000000000000000042 &&
346-
echo_without_newline 0000000000000000000000000000000000000084 ) |
347-
git cat-file --batch-check)"
350+
cat >expect <<-EOF &&
351+
0000000000000000000000000000000000000042 missing
352+
0000000000000000000000000000000000000084 missing
353+
EOF
354+
355+
printf "0000000000000000000000000000000000000042\n0000000000000000000000000000000000000084" >in &&
356+
git cat-file --batch-check <in >actual &&
357+
test_cmp expect actual
348358
'
349359

350360
test_expect_success "--batch for an existent and a non-existent hash" '
351-
test "$tag_sha1 tag $tag_size
352-
$tag_content
353-
0000000000000000000000000000000000000000 missing" = \
354-
"$( ( echo $tag_sha1 &&
355-
echo_without_newline 0000000000000000000000000000000000000000 ) |
356-
git cat-file --batch)"
361+
cat >expect <<-EOF &&
362+
$tag_sha1 tag $tag_size
363+
$tag_content
364+
0000000000000000000000000000000000000000 missing
365+
EOF
366+
367+
printf "$tag_sha1\n0000000000000000000000000000000000000000" >in &&
368+
git cat-file --batch <in >actual &&
369+
test_cmp expect actual
357370
'
358371

359372
test_expect_success "--batch-check for an empty line" '
360-
test " missing" = "$(echo | git cat-file --batch-check)"
373+
cat >expect <<-EOF &&
374+
missing
375+
EOF
376+
377+
echo >in &&
378+
git cat-file --batch-check <in >actual &&
379+
test_cmp expect actual
361380
'
362381

363382
test_expect_success 'empty --batch-check notices missing object' '
@@ -384,7 +403,8 @@ deadbeef missing
384403

385404
test_expect_success '--batch with multiple sha1s gives correct format' '
386405
echo "$batch_output" >expect &&
387-
echo_without_newline "$batch_input" | git cat-file --batch >actual &&
406+
echo_without_newline "$batch_input" >in &&
407+
git cat-file --batch <in >actual &&
388408
test_cmp expect actual
389409
'
390410

@@ -411,13 +431,17 @@ deadbeef missing
411431
missing"
412432

413433
test_expect_success "--batch-check with multiple sha1s gives correct format" '
414-
test "$batch_check_output" = \
415-
"$(echo_without_newline "$batch_check_input" | git cat-file --batch-check)"
434+
echo "$batch_check_output" >expect &&
435+
echo_without_newline "$batch_check_input" >in &&
436+
git cat-file --batch-check <in >actual &&
437+
test_cmp expect actual
416438
'
417439

418440
test_expect_success "--batch-check, -z with multiple sha1s gives correct format" '
419-
echo_without_newline_nul "$batch_check_input" >in &&
420-
test "$batch_check_output" = "$(git cat-file --batch-check -z <in)"
441+
echo "$batch_check_output" >expect &&
442+
echo_without_newline_nul "$batch_check_input" >in &&
443+
git cat-file --batch-check -z <in >actual &&
444+
test_cmp expect actual
421445
'
422446

423447
test_expect_success FUNNYNAMES '--batch-check, -z with newline in input' '

0 commit comments

Comments
 (0)