t1006: modernize output comparisons

In modern tests, we typically put output into a file and compare it with test_cmp. This is nicer than just comparing via "test", and much shorter than comparing via "test" and printing a custom message. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Jeff King committed Jul 10, 2013 at 07:36 UTC 03c893cbf9ad2e9a5be43382bcabdb2af2a49a4a
1 file changed +18 -43
t/t1006-cat-file.sh
+18 -43
@@ -36,66 +36,41 @@ $content"
36 '
37
38 test_expect_success "Type of $type is correct" '
39 - test $type = "$(git cat-file -t $sha1)"
39 + echo $type >expect &&
40 + git cat-file -t $sha1 >actual &&
41 + test_cmp expect actual
42 '
43
44 test_expect_success "Size of $type is correct" '
43 - test $size = "$(git cat-file -s $sha1)"
45 + echo $size >expect &&
46 + git cat-file -s $sha1 >actual &&
47 + test_cmp expect actual
48 '
49
50 test -z "$content" ||
51 test_expect_success "Content of $type is correct" '
48 - expect="$(maybe_remove_timestamp "$content" $no_ts)"
49 - actual="$(maybe_remove_timestamp "$(git cat-file $type $sha1)" $no_ts)"
50 -
51 - if test "z$expect" = "z$actual"
52 - then
53 - : happy
54 - else
55 - echo "Oops: expected $expect"
56 - echo "but got $actual"
57 - false
58 - fi
52 + maybe_remove_timestamp "$content" $no_ts >expect &&
53 + maybe_remove_timestamp "$(git cat-file $type $sha1)" $no_ts >actual &&
54 + test_cmp expect actual
55 '
56
57 test_expect_success "Pretty content of $type is correct" '
62 - expect="$(maybe_remove_timestamp "$pretty_content" $no_ts)"
63 - actual="$(maybe_remove_timestamp "$(git cat-file -p $sha1)" $no_ts)"
64 - if test "z$expect" = "z$actual"
65 - then
66 - : happy
67 - else
68 - echo "Oops: expected $expect"
69 - echo "but got $actual"
70 - false
71 - fi
58 + maybe_remove_timestamp "$pretty_content" $no_ts >expect &&
59 + maybe_remove_timestamp "$(git cat-file -p $sha1)" $no_ts >actual &&
60 + test_cmp expect actual
61 '
62
63 test -z "$content" ||
64 test_expect_success "--batch output of $type is correct" '
76 - expect="$(maybe_remove_timestamp "$batch_output" $no_ts)"
77 - actual="$(maybe_remove_timestamp "$(echo $sha1 | git cat-file --batch)" $no_ts)"
78 - if test "z$expect" = "z$actual"
79 - then
80 - : happy
81 - else
82 - echo "Oops: expected $expect"
83 - echo "but got $actual"
84 - false
85 - fi
65 + maybe_remove_timestamp "$batch_output" $no_ts >expect &&
66 + maybe_remove_timestamp "$(echo $sha1 | git cat-file --batch)" $no_ts >actual &&
67 + test_cmp expect actual
68 '
69
70 test_expect_success "--batch-check output of $type is correct" '
89 - expect="$sha1 $type $size"
90 - actual="$(echo_without_newline $sha1 | git cat-file --batch-check)"
91 - if test "z$expect" = "z$actual"
92 - then
93 - : happy
94 - else
95 - echo "Oops: expected $expect"
96 - echo "but got $actual"
97 - false
98 - fi
71 + echo "$sha1 $type $size" >expect &&
72 + echo_without_newline $sha1 | git cat-file --batch-check >actual &&
73 + test_cmp expect actual
74 '
75 }
76