From: Ramkumar Ramachandra <artagnon@gmail.com>
To: Jonathan Nieder <jrnieder@mgmail.com>
Cc: Junio C Hamano <gitster@pobox.com>,
Matthieu Moy <Matthieu.Moy@grenoble-inp.fr>,
Git List <git@vger.kernel.org>
Subject: [PATCH 3/6] t1006 (cat-file): use test_cmp
Date: Fri, 9 Dec 2011 16:59:15 +0530 [thread overview]
Message-ID: <1323430158-14885-4-git-send-email-artagnon@gmail.com> (raw)
In-Reply-To: <1323430158-14885-1-git-send-email-artagnon@gmail.com>
In testing, a common paradigm involves checking the expected output
with the actual output: test-lib provides a test_cmp to show the diff
between the two outputs. So, use this function in preference to
calling a human over to compare command outputs by eye.
Helped-by: Jonathan Nieder <jrnieder@gmail.com>
Signed-off-by: Ramkumar Ramachandra <artagnon@gmail.com>
---
t/t1006-cat-file.sh | 119 ++++++++++++++++++++++++---------------------------
1 files changed, 56 insertions(+), 63 deletions(-)
diff --git a/t/t1006-cat-file.sh b/t/t1006-cat-file.sh
index d8b7f2f..5be3ce9 100755
--- a/t/t1006-cat-file.sh
+++ b/t/t1006-cat-file.sh
@@ -36,66 +36,41 @@ $content"
'
test_expect_success "Type of $type is correct" '
- test $type = "$(git cat-file -t $sha1)"
+ echo $type >expect &&
+ git cat-file -t $sha1 >actual &&
+ test_cmp expect actual
'
test_expect_success "Size of $type is correct" '
- test $size = "$(git cat-file -s $sha1)"
+ echo $size >expect &&
+ git cat-file -s $sha1 >actual &&
+ test_cmp expect actual
'
test -z "$content" ||
test_expect_success "Content of $type is correct" '
- expect="$(maybe_remove_timestamp "$content" $no_ts)"
- actual="$(maybe_remove_timestamp "$(git cat-file $type $sha1)" $no_ts)"
-
- if test "z$expect" = "z$actual"
- then
- : happy
- else
- echo "Oops: expected $expect"
- echo "but got $actual"
- false
- fi
+ maybe_remove_timestamp "$content" $no_ts >expect &&
+ maybe_remove_timestamp "$(git cat-file $type $sha1)" $no_ts >actual &&
+ test_cmp expect actual
'
test_expect_success "Pretty content of $type is correct" '
- expect="$(maybe_remove_timestamp "$pretty_content" $no_ts)"
- actual="$(maybe_remove_timestamp "$(git cat-file -p $sha1)" $no_ts)"
- if test "z$expect" = "z$actual"
- then
- : happy
- else
- echo "Oops: expected $expect"
- echo "but got $actual"
- false
- fi
+ maybe_remove_timestamp "$pretty_content" $no_ts >expect &&
+ maybe_remove_timestamp "$(git cat-file -p $sha1)" $no_ts >actual &&
+ test_cmp expect actual
'
test -z "$content" ||
test_expect_success "--batch output of $type is correct" '
- expect="$(maybe_remove_timestamp "$batch_output" $no_ts)"
- actual="$(maybe_remove_timestamp "$(echo $sha1 | git cat-file --batch)" $no_ts)"
- if test "z$expect" = "z$actual"
- then
- : happy
- else
- echo "Oops: expected $expect"
- echo "but got $actual"
- false
- fi
+ maybe_remove_timestamp "$batch_output" $no_ts >expect &&
+ maybe_remove_timestamp "$(echo $sha1 | git cat-file --batch)" $no_ts >actual &&
+ test_cmp expect actual
'
test_expect_success "--batch-check output of $type is correct" '
- expect="$sha1 $type $size"
- actual="$(echo_without_newline $sha1 | git cat-file --batch-check)"
- if test "z$expect" = "z$actual"
- then
- : happy
- else
- echo "Oops: expected $expect"
- echo "but got $actual"
- false
- fi
+ echo "$sha1 $type $size" >expect &&
+ echo_without_newline $sha1 | git cat-file --batch-check >actual &&
+ test_cmp expect actual
'
}
@@ -144,10 +119,13 @@ tag_size=$(strlen "$tag_content")
run_tests 'tag' $tag_sha1 $tag_size "$tag_content" "$tag_pretty_content" 1
-test_expect_success \
- "Reach a blob from a tag pointing to it" \
- "test '$hello_content' = \"\$(git cat-file blob $tag_sha1)\""
+test_expect_success "Reach a blob from a tag pointing to it" '
+ echo_without_newline "$hello_content" >expect &&
+ git cat-file blob "$tag_sha1" >actual &&
+ test_cmp expect actual
+'
+test_done
for batch in batch batch-check
do
for opt in t s e p
@@ -175,30 +153,41 @@ do
done
test_expect_success "--batch-check for a non-existent named object" '
- test "foobar42 missing
-foobar84 missing" = \
- "$( ( echo foobar42; echo_without_newline foobar84; ) | git cat-file --batch-check)"
+ cat >expect <<\-EOF &&
+foobar42 missing
+foobar84 missing
+EOF
+ echo foobar42; echo_without_newline foobar84 | \
+ git cat-file --batch-check >actual &&
+ test_cmp expect actual
'
test_expect_success "--batch-check for a non-existent hash" '
- test "0000000000000000000000000000000000000042 missing
-0000000000000000000000000000000000000084 missing" = \
- "$( ( echo 0000000000000000000000000000000000000042;
- echo_without_newline 0000000000000000000000000000000000000084; ) \
- | git cat-file --batch-check)"
+ cat >expect <<\-EOF &&
+0000000000000000000000000000000000000042 missing
+0000000000000000000000000000000000000084 missing
+EOF
+ echo 0000000000000000000000000000000000000042;
+ echo_without_newline 0000000000000000000000000000000000000084 | \
+ git cat-file --batch-check >actual &&
+ test_cmp expect actual
'
test_expect_success "--batch for an existent and a non-existent hash" '
- test "$tag_sha1 tag $tag_size
+ cat >expect <<\-EOF &&
+tag_sha1 tag $tag_size
$tag_content
-0000000000000000000000000000000000000000 missing" = \
- "$( ( echo $tag_sha1;
- echo_without_newline 0000000000000000000000000000000000000000; ) \
- | git cat-file --batch)"
+0000000000000000000000000000000000000000 missing
+EOF
+ echo $tag_sha1; echo_without_newline 0000000000000000000000000000000000000000 | \
+ git cat-file --batch >actual &&
+ test_cmp expect_actual
'
test_expect_success "--batch-check for an emtpy line" '
- test " missing" = "$(echo | git cat-file --batch-check)"
+ echo " missing" >expect &&
+ echo | git cat-file --batch-check >actual &&
+ test_cmp expect actual
'
batch_input="$hello_sha1
@@ -218,7 +207,10 @@ deadbeef missing
missing"
test_expect_success '--batch with multiple sha1s gives correct format' '
- test "$(maybe_remove_timestamp "$batch_output" 1)" = "$(maybe_remove_timestamp "$(echo_without_newline "$batch_input" | git cat-file --batch)" 1)"
+ maybe_remove_timestamp "$batch_output" 1 >expect &&
+ maybe_remove_timestamp "echo_without_newline "$batch_input" | \
+ git cat-file --batch" 1 >actual &&
+ test_cmp expect actual
'
batch_check_input="$hello_sha1
@@ -237,8 +229,9 @@ deadbeef missing
missing"
test_expect_success "--batch-check with multiple sha1s gives correct format" '
- test "$batch_check_output" = \
- "$(echo_without_newline "$batch_check_input" | git cat-file --batch-check)"
+ echo "$batch_check_output" >expect &&
+ echo_without_newline "$batch_check_input" | git cat-file --batch-check >actual &&
+ test_cmp expect actual
'
test_done
--
1.7.7.3
next prev parent reply other threads:[~2011-12-09 11:30 UTC|newest]
Thread overview: 50+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-12-08 13:10 [PATCH v2 0/6] Fix '&&' chaining in tests Ramkumar Ramachandra
2011-12-08 13:10 ` [PATCH 1/2] parse-options: introduce OPT_SUBCOMMAND Ramkumar Ramachandra
2011-12-08 16:30 ` Jonathan Nieder
2011-12-08 16:43 ` Ramkumar Ramachandra
2011-12-08 13:10 ` [PATCH 1/6] t3040 (subprojects-basic): modernize style Ramkumar Ramachandra
2011-12-08 16:34 ` Jonathan Nieder
2011-12-09 7:56 ` Ramkumar Ramachandra
2011-12-09 18:26 ` Junio C Hamano
2011-12-09 18:32 ` Ramkumar Ramachandra
2011-12-08 13:10 ` [PATCH 2/2] bundle: rewrite builtin to use parse-options Ramkumar Ramachandra
2011-12-08 16:39 ` Jonathan Nieder
2011-12-08 16:47 ` Ramkumar Ramachandra
2011-12-08 17:03 ` Jonathan Nieder
2011-12-08 17:38 ` Ramkumar Ramachandra
2011-12-08 17:59 ` Jonathan Nieder
2011-12-08 19:39 ` Ramkumar Ramachandra
2011-12-08 23:48 ` Junio C Hamano
2011-12-09 13:33 ` Jakub Narebski
2011-12-09 18:24 ` Junio C Hamano
2011-12-15 16:45 ` [PATCH 0/2] Improve git-bundle builtin Ramkumar Ramachandra
2011-12-15 16:45 ` [PATCH 1/2] t5704 (bundle): rewrite for larger coverage Ramkumar Ramachandra
2011-12-15 21:16 ` Jonathan Nieder
2011-12-15 16:45 ` [PATCH 2/2] bundle: rewrite builtin to use parse-options Ramkumar Ramachandra
2011-12-15 21:29 ` Jonathan Nieder
2011-12-15 20:54 ` [PATCH 0/2] Improve git-bundle builtin Jonathan Nieder
2011-12-15 21:30 ` Junio C Hamano
2011-12-08 13:10 ` [PATCH 2/6] t3030 (merge-recursive): use test_expect_code Ramkumar Ramachandra
2011-12-08 13:10 ` [PATCH 3/6] t1006 (cat-file): use test_cmp Ramkumar Ramachandra
2011-12-08 13:28 ` Matthieu Moy
2011-12-08 13:33 ` Ramkumar Ramachandra
2011-12-08 13:41 ` Matthieu Moy
2011-12-08 16:55 ` Jonathan Nieder
2011-12-08 13:10 ` [PATCH 4/6] t3200 (branch): fix '&&' chaining Ramkumar Ramachandra
2011-12-08 17:07 ` Jonathan Nieder
2011-12-08 13:10 ` [PATCH 5/6] t1510 (worktree): " Ramkumar Ramachandra
2011-12-08 17:12 ` Jonathan Nieder
2011-12-09 0:00 ` Junio C Hamano
2011-12-08 13:10 ` [PATCH 6/6] test: " Ramkumar Ramachandra
2011-12-08 17:18 ` Jonathan Nieder
2011-12-08 19:55 ` [PATCH v2 0/6] Fix '&&' chaining in tests Junio C Hamano
2011-12-09 5:23 ` Ramkumar Ramachandra
2011-12-09 11:29 ` [PATCH v3 " Ramkumar Ramachandra
2011-12-09 11:29 ` [PATCH 1/6] t3040 (subprojects-basic): fix '&&' chaining, modernize style Ramkumar Ramachandra
2011-12-09 11:29 ` [PATCH 2/6] t3030 (merge-recursive): use test_expect_code Ramkumar Ramachandra
2011-12-09 11:29 ` Ramkumar Ramachandra [this message]
2011-12-09 18:43 ` [PATCH 3/6] t1006 (cat-file): use test_cmp Junio C Hamano
2011-12-09 18:47 ` Ramkumar Ramachandra
2011-12-09 11:29 ` [PATCH 4/6] t3200 (branch): fix '&&' chaining Ramkumar Ramachandra
2011-12-09 11:29 ` [PATCH 5/6] t1510 (worktree): " Ramkumar Ramachandra
2011-12-09 11:29 ` [PATCH 6/6] tests: " Ramkumar Ramachandra
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1323430158-14885-4-git-send-email-artagnon@gmail.com \
--to=artagnon@gmail.com \
--cc=Matthieu.Moy@grenoble-inp.fr \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=jrnieder@mgmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).