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>
Patrick Steinhardt committed
Jun 6, 2023 at 07:19 UTC
b116c77307853a9fa8f74d1ad16bed98a7211207
1 file changed
+47
-23
t/t1006-cat-file.sh
+47
-23
@@ -296,9 +296,11 @@ tag_size=$(strlen "$tag_content")
296
297
run_tests 'tag' $tag_sha1 $tag_size "$tag_content" "$tag_content"
298
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
+'
304
305
for batch in batch batch-check batch-command
306
do
@@ -334,30 +336,47 @@ do
336
done
337
338
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
347
'
348
349
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
358
'
359
360
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
370
'
371
372
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
380
'
381
382
test_expect_success 'empty --batch-check notices missing object' '
@@ -384,7 +403,8 @@ deadbeef missing
403
404
test_expect_success '--batch with multiple sha1s gives correct format' '
405
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 &&
408
test_cmp expect actual
409
'
410
@@ -411,13 +431,17 @@ deadbeef missing
431
missing"
432
433
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
438
'
439
440
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
445
'
446
447
test_expect_success FUNNYNAMES '--batch-check, -z with newline in input' '