From: Junio C Hamano <gitster@pobox.com>
To: Paul Tan <pyokagan@gmail.com>
Cc: Michael Blume <blume.mike@gmail.com>,
Git List <git@vger.kernel.org>,
Stefan Beller <sbeller@google.com>,
Johannes Schindelin <johannes.schindelin@gmx.de>
Subject: Re: [PATCH v3 1/9] t5520: fixup file contents comparisons
Date: Fri, 15 May 2015 12:22:00 -0700 [thread overview]
Message-ID: <xmqqzj55fxyf.fsf@gitster.dls.corp.google.com> (raw)
In-Reply-To: <xmqq7fs9hekc.fsf@gitster.dls.corp.google.com> (Junio C. Hamano's message of "Fri, 15 May 2015 11:37:55 -0700")
Junio C Hamano <gitster@pobox.com> writes:
> You might have noticed, while adding them, there were something
> common that we currently do with a bare 'test' only because we
> haven't identified common needs....
> ...
> in t/test-lib-functions.sh and convert them to say
>
> test_file_contents file expected_string
>
> That would be an improvement (and that is the remaining 2/3 ;-).
I haven't made up my mind on this other example, but since I started
writing it...
It may be that counting the number of lines in output, "cmd | wc -l",
is a common pattern. We already have test_line_count to check the
number of lines in a file, but having test_output_count may help.
t/test-lib-functions.sh | 11 +++++++++++
t/t0000-basic.sh | 3 +--
t/t0030-stripspace.sh | 11 +++++------
3 files changed, 17 insertions(+), 8 deletions(-)
diff --git a/t/test-lib-functions.sh b/t/test-lib-functions.sh
index 0d93e33..624a8c5 100644
--- a/t/test-lib-functions.sh
+++ b/t/test-lib-functions.sh
@@ -538,6 +538,17 @@ test_line_count () {
fi
}
+test_output_count () {
+ if test $# != 3
+ then
+ error "bug in the test script: not 3 parameters to test_output_count"
+ elif ! test $(eval "$2" | wc -l) "$1" "$3"
+ then
+ echo "test_output_count: line count for output from '$2' !$1 $3"
+ return 1
+ fi
+}
+
# This is not among top-level (test_expect_success | test_expect_failure)
# but is a prefix that can be used in the test script, like:
#
diff --git a/t/t0000-basic.sh b/t/t0000-basic.sh
index f10ba4a..bd5930d 100755
--- a/t/t0000-basic.sh
+++ b/t/t0000-basic.sh
@@ -1039,8 +1039,7 @@ test_expect_success 'update-index D/F conflict' '
mv path2 path0 &&
mv tmp path2 &&
git update-index --add --replace path2 path0/file2 &&
- numpath0=$(git ls-files path0 | wc -l) &&
- test $numpath0 = 1
+ test_output_count = "git ls-files path0" 1
'
test_expect_success 'very long name in the index handled sanely' '
diff --git a/t/t0030-stripspace.sh b/t/t0030-stripspace.sh
index 0333dd9..9502938 100755
--- a/t/t0030-stripspace.sh
+++ b/t/t0030-stripspace.sh
@@ -223,12 +223,11 @@ test_expect_success \
test_cmp expect actual
'
-test_expect_success \
- 'text without newline at end should end with newline' '
- test $(printf "$ttt" | git stripspace | wc -l) -gt 0 &&
- test $(printf "$ttt$ttt" | git stripspace | wc -l) -gt 0 &&
- test $(printf "$ttt$ttt$ttt" | git stripspace | wc -l) -gt 0 &&
- test $(printf "$ttt$ttt$ttt$ttt" | git stripspace | wc -l) -gt 0
+test_expect_success 'text without newline at end should end with newline' '
+ test_output_count -gt '\''printf "$ttt" | git stripspace'\'' 0 &&
+ test_output_count -gt '\''printf "$ttt$ttt" | git stripspace'\'' 0 &&
+ test_output_count -gt '\''printf "$ttt$ttt$ttt" | git stripspace'\'' 0 &&
+ test_output_count -gt '\''printf "$ttt$ttt$ttt$ttt" | git stripspace'\'' 0
'
# text plus spaces at the end:
next prev parent reply other threads:[~2015-05-15 19:22 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-05-13 9:08 [PATCH v3 0/9] Improve git-pull test coverage Paul Tan
2015-05-13 9:08 ` [PATCH v3 1/9] t5520: fixup file contents comparisons Paul Tan
2015-05-13 14:01 ` Junio C Hamano
2015-05-13 14:42 ` Junio C Hamano
2015-05-14 17:29 ` Michael Blume
2015-05-14 17:44 ` Junio C Hamano
2015-05-15 11:41 ` Paul Tan
2015-05-15 18:37 ` Junio C Hamano
2015-05-15 19:22 ` Junio C Hamano [this message]
2015-05-16 13:49 ` Paul Tan
2015-05-16 18:57 ` Junio C Hamano
2015-05-16 23:32 ` Junio C Hamano
2015-05-17 7:47 ` Paul Tan
2015-05-13 9:08 ` [PATCH v3 2/9] t5520: ensure origin refs are updated Paul Tan
2015-05-13 14:27 ` Junio C Hamano
2015-05-18 13:09 ` Paul Tan
2015-05-13 9:08 ` [PATCH v3 3/9] t5520: test no merge candidates cases Paul Tan
2015-05-13 9:08 ` [PATCH v3 4/9] t5520: test for failure if index has unresolved entries Paul Tan
2015-05-13 9:32 ` Matthieu Moy
2015-05-15 8:25 ` Paul Tan
2015-05-13 9:08 ` [PATCH v3 5/9] t5520: test work tree fast-forward when fetch updates head Paul Tan
2015-05-13 9:08 ` [PATCH v3 6/9] t5520: test --rebase with multiple branches Paul Tan
2015-05-13 9:08 ` [PATCH v3 7/9] t5520: test --rebase failure on unborn branch with index Paul Tan
2015-05-13 9:08 ` [PATCH v3 8/9] t5521: test --dry-run does not make any changes Paul Tan
2015-05-13 9:08 ` [PATCH v3 9/9] t5520: check reflog action in fast-forward merge Paul Tan
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=xmqqzj55fxyf.fsf@gitster.dls.corp.google.com \
--to=gitster@pobox.com \
--cc=blume.mike@gmail.com \
--cc=git@vger.kernel.org \
--cc=johannes.schindelin@gmx.de \
--cc=pyokagan@gmail.com \
--cc=sbeller@google.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.