From: "René Scharfe" <l.s.r@web.de>
To: Jeff King <peff@peff.net>
Cc: Eric Sunshine <sunshine@sunshineco.com>,
Git List <git@vger.kernel.org>,
Junio C Hamano <gitster@pobox.com>,
Johannes Schindelin <johannes.schindelin@gmx.de>
Subject: [PATCH 4/2] test: use test_must_contain
Date: Fri, 20 Nov 2015 21:50:19 +0100 [thread overview]
Message-ID: <564F878B.3090508@web.de> (raw)
In-Reply-To: <20151120111454.GB11198@sigill.intra.peff.net>
Some tests print a file using cat and then grep it for some pattern.
This is done to aid debugging in case the pattern is unexpectedly not
found; the file contents can easily inspected by running the test with
the option --verbose.
Replace these combinations by calls of test_must_contain. It only
shows the whole file if the pattern is not found, saving a cat call
(and thus a fork(2)) in the normal case. It also just needs a single
line and makes the intent clearer.
The flag -q in t5801 is dropped as there's no pressing reason for
hiding the matching line in this test. Consistency is more important,
and none of the remaining grep calls in that file use that flag or
redirect the results to /dev/null.
Signed-off-by: Rene Scharfe <l.s.r@web.de>
---
t/t1450-fsck.sh | 52 ++++++++++++++++-------------------------------
t/t5510-fetch.sh | 3 +--
t/t5801-remote-helpers.sh | 3 +--
t/t9810-git-p4-rcs.sh | 3 +--
4 files changed, 21 insertions(+), 40 deletions(-)
diff --git a/t/t1450-fsck.sh b/t/t1450-fsck.sh
index e66b7cb..190c97f 100755
--- a/t/t1450-fsck.sh
+++ b/t/t1450-fsck.sh
@@ -70,16 +70,14 @@ test_expect_success 'object with bad sha1' '
test_when_finished "git update-ref -d refs/heads/bogus" &&
test_must_fail git fsck 2>out &&
- cat out &&
- grep "$sha.*corrupt" out
+ test_must_contain "$sha.*corrupt" out
'
test_expect_success 'branch pointing to non-commit' '
git rev-parse HEAD^{tree} >.git/refs/heads/invalid &&
test_when_finished "git update-ref -d refs/heads/invalid" &&
test_must_fail git fsck 2>out &&
- cat out &&
- grep "not a commit" out
+ test_must_contain "not a commit" out
'
test_expect_success 'HEAD link pointing at a funny object' '
@@ -88,8 +86,7 @@ test_expect_success 'HEAD link pointing at a funny object' '
echo 0000000000000000000000000000000000000000 >.git/HEAD &&
# avoid corrupt/broken HEAD from interfering with repo discovery
test_must_fail env GIT_DIR=.git git fsck 2>out &&
- cat out &&
- grep "detached HEAD points" out
+ test_must_contain "detached HEAD points" out
'
test_expect_success 'HEAD link pointing at a funny place' '
@@ -98,8 +95,7 @@ test_expect_success 'HEAD link pointing at a funny place' '
echo "ref: refs/funny/place" >.git/HEAD &&
# avoid corrupt/broken HEAD from interfering with repo discovery
test_must_fail env GIT_DIR=.git git fsck 2>out &&
- cat out &&
- grep "HEAD points to something strange" out
+ test_must_contain "HEAD points to something strange" out
'
test_expect_success 'email without @ is okay' '
@@ -122,8 +118,7 @@ test_expect_success 'email with embedded > is not okay' '
git update-ref refs/heads/bogus "$new" &&
test_when_finished "git update-ref -d refs/heads/bogus" &&
test_must_fail git fsck 2>out &&
- cat out &&
- grep "error in commit $new" out
+ test_must_contain "error in commit $new" out
'
test_expect_success 'missing < email delimiter is reported nicely' '
@@ -134,8 +129,7 @@ test_expect_success 'missing < email delimiter is reported nicely' '
git update-ref refs/heads/bogus "$new" &&
test_when_finished "git update-ref -d refs/heads/bogus" &&
test_must_fail git fsck 2>out &&
- cat out &&
- grep "error in commit $new.* - bad name" out
+ test_must_contain "error in commit $new.* - bad name" out
'
test_expect_success 'missing email is reported nicely' '
@@ -146,8 +140,7 @@ test_expect_success 'missing email is reported nicely' '
git update-ref refs/heads/bogus "$new" &&
test_when_finished "git update-ref -d refs/heads/bogus" &&
test_must_fail git fsck 2>out &&
- cat out &&
- grep "error in commit $new.* - missing email" out
+ test_must_contain "error in commit $new.* - missing email" out
'
test_expect_success '> in name is reported' '
@@ -158,8 +151,7 @@ test_expect_success '> in name is reported' '
git update-ref refs/heads/bogus "$new" &&
test_when_finished "git update-ref -d refs/heads/bogus" &&
test_must_fail git fsck 2>out &&
- cat out &&
- grep "error in commit $new" out
+ test_must_contain "error in commit $new" out
'
# date is 2^64 + 1
@@ -172,8 +164,7 @@ test_expect_success 'integer overflow in timestamps is reported' '
git update-ref refs/heads/bogus "$new" &&
test_when_finished "git update-ref -d refs/heads/bogus" &&
test_must_fail git fsck 2>out &&
- cat out &&
- grep "error in commit $new.*integer overflow" out
+ test_must_contain "error in commit $new.*integer overflow" out
'
test_expect_success 'commit with NUL in header' '
@@ -184,8 +175,7 @@ test_expect_success 'commit with NUL in header' '
git update-ref refs/heads/bogus "$new" &&
test_when_finished "git update-ref -d refs/heads/bogus" &&
test_must_fail git fsck 2>out &&
- cat out &&
- grep "error in commit $new.*unterminated header: NUL at offset" out
+ test_must_contain "error in commit $new.*unterminated header: NUL at offset" out
'
test_expect_success 'malformatted tree object' '
@@ -205,7 +195,7 @@ test_expect_success 'malformatted tree object' '
git hash-object -w -t tree --stdin
) &&
test_must_fail git fsck 2>out &&
- grep "error in tree .*contains duplicate file entries" out
+ test_must_contain "error in tree .*contains duplicate file entries" out
'
test_expect_success 'tag pointing to nonexistent' '
@@ -223,8 +213,7 @@ test_expect_success 'tag pointing to nonexistent' '
echo $tag >.git/refs/tags/invalid &&
test_when_finished "git update-ref -d refs/tags/invalid" &&
test_must_fail git fsck --tags >out &&
- cat out &&
- grep "broken link" out
+ test_must_contain "broken link" out
'
test_expect_success 'tag pointing to something else than its type' '
@@ -285,7 +274,7 @@ test_expect_success 'tag with bad tagger' '
echo $tag >.git/refs/tags/wrong &&
test_when_finished "git update-ref -d refs/tags/wrong" &&
test_must_fail git fsck --tags 2>out &&
- grep "error in tag .*: invalid author/committer" out
+ test_must_contain "error in tag .*: invalid author/committer" out
'
test_expect_success 'tag with NUL in header' '
@@ -304,8 +293,7 @@ test_expect_success 'tag with NUL in header' '
echo $tag >.git/refs/tags/wrong &&
test_when_finished "git update-ref -d refs/tags/wrong" &&
test_must_fail git fsck --tags 2>out &&
- cat out &&
- grep "error in tag $tag.*unterminated header: NUL at offset" out
+ test_must_contain "error in tag $tag.*unterminated header: NUL at offset" out
'
test_expect_success 'cleaned up' '
@@ -335,8 +323,7 @@ test_expect_success 'rev-list --verify-objects with bad sha1' '
test_when_finished "git update-ref -d refs/heads/bogus" &&
test_might_fail git rev-list --verify-objects refs/heads/bogus >/dev/null 2>out &&
- cat out &&
- grep -q "error: sha1 mismatch 63ffffffffffffffffffffffffffffffffffffff" out
+ test_must_contain "error: sha1 mismatch 63ffffffffffffffffffffffffffffffffffffff" out
'
test_expect_success 'force fsck to ignore double author' '
@@ -360,8 +347,7 @@ test_expect_success 'fsck notices blob entry pointing to null sha1' '
sha=$(printf "100644 file$_bz$_bz20" |
git hash-object -w --stdin -t tree) &&
git fsck 2>out &&
- cat out &&
- grep "warning.*null sha1" out
+ test_must_contain "warning.*null sha1" out
)
'
@@ -371,8 +357,7 @@ test_expect_success 'fsck notices submodule entry pointing to null sha1' '
sha=$(printf "160000 submodule$_bz$_bz20" |
git hash-object -w --stdin -t tree) &&
git fsck 2>out &&
- cat out &&
- grep "warning.*null sha1" out
+ test_must_contain "warning.*null sha1" out
)
'
@@ -392,8 +377,7 @@ while read name path pretty; do
printf "$mode $type %s\t%s" "$value" "$path" >bad &&
bad_tree=$(git mktree <bad) &&
git fsck 2>out &&
- cat out &&
- grep "warning.*tree $bad_tree" out
+ test_must_contain "warning.*tree $bad_tree" out
)'
done <<-\EOF
100644 blob
diff --git a/t/t5510-fetch.sh b/t/t5510-fetch.sh
index 0ba9db0..f5023b0 100755
--- a/t/t5510-fetch.sh
+++ b/t/t5510-fetch.sh
@@ -393,8 +393,7 @@ test_expect_success 'fetch from GIT URL with a non-applying branch.<name>.merge
# the strange name is: a\!'b
test_expect_success 'quoting of a strangely named repo' '
test_must_fail git fetch "a\\!'\''b" > result 2>&1 &&
- cat result &&
- grep "fatal: '\''a\\\\!'\''b'\''" result
+ test_must_contain "fatal: '\''a\\\\!'\''b'\''" result
'
test_expect_success 'bundle should record HEAD correctly' '
diff --git a/t/t5801-remote-helpers.sh b/t/t5801-remote-helpers.sh
index 362b158..57ec852 100755
--- a/t/t5801-remote-helpers.sh
+++ b/t/t5801-remote-helpers.sh
@@ -245,8 +245,7 @@ clean_mark () {
test_expect_success 'proper failure checks for fetching' '
(cd local &&
test_must_fail env GIT_REMOTE_TESTGIT_FAILURE=1 git fetch 2>error &&
- cat error &&
- grep -q "Error while running fast-import" error
+ test_must_contain "Error while running fast-import" error
)
'
diff --git a/t/t9810-git-p4-rcs.sh b/t/t9810-git-p4-rcs.sh
index 8134ab4..e02b490 100755
--- a/t/t9810-git-p4-rcs.sh
+++ b/t/t9810-git-p4-rcs.sh
@@ -294,8 +294,7 @@ test_expect_success 'cope with rcs keyword file deletion' '
echo "\$Revision\$" >kwdelfile.c &&
p4 add -t ktext kwdelfile.c &&
p4 submit -d "Add file to be deleted" &&
- cat kwdelfile.c &&
- grep 1 kwdelfile.c
+ test_must_constain 1 kwdelfile.c
) &&
git p4 clone --dest="$git" //depot &&
(
--
2.6.3
next prev parent reply other threads:[~2015-11-20 20:50 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-11-19 16:20 [PATCH 1/2] t1450: add tests for NUL in headers of commits and tags René Scharfe
2015-11-19 16:25 ` [PATCH 2/2] fsck: treat a NUL in a tag header as an error René Scharfe
2015-11-20 11:13 ` Jeff King
2015-11-20 20:18 ` Johannes Schindelin
2015-11-19 20:33 ` [PATCH 1/2] t1450: add tests for NUL in headers of commits and tags Eric Sunshine
2015-11-19 20:54 ` René Scharfe
2015-11-20 11:14 ` Jeff King
2015-11-20 20:49 ` René Scharfe
2015-11-20 20:50 ` [PATCH 3/2] test: factor out helper function test_must_contain René Scharfe
2015-11-21 8:11 ` Johannes Sixt
2015-11-21 9:35 ` René Scharfe
2015-11-20 20:50 ` René Scharfe [this message]
2015-11-21 1:16 ` [PATCH 4/2] test: use test_must_contain SZEDER Gábor
2015-11-21 2:30 ` René Scharfe
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=564F878B.3090508@web.de \
--to=l.s.r@web.de \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=johannes.schindelin@gmx.de \
--cc=peff@peff.net \
--cc=sunshine@sunshineco.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).