From: "Carlos López via GitGitGadget" <gitgitgadget@gmail.com>
To: git@vger.kernel.org
Cc: "Martin Ågren [ ]" <martin.agren@gmail.com>,
"Paul Eggert [ ]" <eggert@cs.ucla.edu>,
"Carlos L." <00xc@protonmail.com>,
"Carlos López" <00xc@protonmail.com>
Subject: [PATCH v3 2/2] tests: add tests for grep --max-count
Date: Wed, 22 Jun 2022 17:07:08 +0000 [thread overview]
Message-ID: <525958af877c3bbd024ffd3aee0c64e469c3d6cf.1655917628.git.gitgitgadget@gmail.com> (raw)
In-Reply-To: <pull.1278.v3.git.git.1655917628.gitgitgadget@gmail.com>
From: =?UTF-8?q?Carlos=20L=C3=B3pez?= <00xc@protonmail.com>
Add tests for grep's -m / --max-count to check if the option correctly
outputs limited results, and that it interacts properly with other flags
that could likely be used in conjunction.
Signed-off-by: Carlos López 00xc@protonmail.com
---
t/t7810-grep.sh | 83 +++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 83 insertions(+)
diff --git a/t/t7810-grep.sh b/t/t7810-grep.sh
index 69356011713..7b1b8a3cd93 100755
--- a/t/t7810-grep.sh
+++ b/t/t7810-grep.sh
@@ -77,6 +77,7 @@ test_expect_success setup '
# Say hello.
function hello() {
echo "Hello world."
+ echo "Hello again."
} # hello
# Still a no-op.
@@ -595,6 +596,88 @@ test_expect_success 'grep --files-without-match --quiet' '
test_must_be_empty actual
'
+cat >expected <<EOF &&
+EOF
+
+test_expect_success 'grep --max-count 0 (must exit with non-zero)' '
+ test_must_fail git grep --max-count 0 foo >actual &&
+ test_cmp expected actual
+'
+
+cat >expected <<EOF &&
+file:foo mmap bar
+EOF
+
+test_expect_success 'grep --max-count 1' '
+ git grep --max-count 1 foo >actual &&
+ test_cmp expected actual
+'
+
+cat >expected <<EOF &&
+file:foo mmap bar
+file:foo_mmap bar
+file:foo_mmap bar mmap
+EOF
+
+test_expect_success 'grep --max-count 3' '
+ git grep --max-count 3 foo >actual &&
+ test_cmp expected actual
+'
+
+cat >expected <<EOF &&
+file:foo mmap bar
+file:foo_mmap bar
+file:foo_mmap bar mmap
+file:foo mmap bar_mmap
+file:foo_mmap bar mmap baz
+EOF
+
+test_expect_success 'grep --max-count -1 (no limit)' '
+ git grep --max-count -1 foo >actual &&
+ test_cmp expected actual
+'
+
+cat >expected <<EOF &&
+file-foo mmap bar
+file:foo_mmap bar
+file-foo_mmap bar mmap
+EOF
+
+test_expect_success 'grep --max-count 1 --context 2' '
+ git grep --max-count 1 --context 1 foo_mmap >actual &&
+ test_cmp expected actual
+'
+
+cat >expected <<EOF &&
+hello.ps1=function hello() {
+hello.ps1: echo "Hello world."
+EOF
+
+test_expect_success 'grep --max-count 1 --show-function' '
+ git grep --max-count 1 --show-function Hello hello.ps1 >actual &&
+ test_cmp expected actual
+'
+
+cat >expected <<EOF &&
+hello.ps1=function hello() {
+hello.ps1: echo "Hello world."
+hello.ps1: echo "Hello again."
+EOF
+
+test_expect_success 'grep --max-count 2 --show-function' '
+ git grep --max-count 2 --show-function Hello hello.ps1 >actual &&
+ test_cmp expected actual
+'
+
+cat >expected <<EOF &&
+hello.ps1:1
+EOF
+
+test_expect_success 'grep --max-count 1 -c' '
+ git grep --max-count 1 --count Hello hello.ps1 >actual &&
+ test_cmp expected actual
+'
+
cat >expected <<EOF
file:foo mmap bar_mmap
EOF
--
gitgitgadget
next prev parent reply other threads:[~2022-06-22 17:08 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-06-20 15:49 [PATCH] grep: add --max-count command line option Carlos L. via GitGitGadget
2022-06-20 15:57 ` Paul Eggert
2022-06-20 16:25 ` Carlos L.
2022-06-20 16:32 ` Paul Eggert
2022-06-21 5:36 ` [PATCH v2] " Carlos L. via GitGitGadget
2022-06-21 16:27 ` Junio C Hamano
2022-06-22 6:41 ` Carlos L.
2022-06-22 6:56 ` Junio C Hamano
[not found] ` <220622.86mte5knbe.gmgdl@evledraar.gmail.com>
2022-06-22 13:23 ` Carlos L.
2022-06-22 17:07 ` [PATCH v3 0/2] " Carlos L. via GitGitGadget
2022-06-22 17:07 ` [PATCH v3 1/2] " Carlos López via GitGitGadget
2022-06-22 17:07 ` Carlos López via GitGitGadget [this message]
2022-06-22 18:10 ` [PATCH v3 2/2] tests: add tests for grep --max-count Junio C Hamano
2022-06-22 19:47 ` [PATCH v4] grep: add --max-count command line option Carlos L. via GitGitGadget
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=525958af877c3bbd024ffd3aee0c64e469c3d6cf.1655917628.git.gitgitgadget@gmail.com \
--to=gitgitgadget@gmail.com \
--cc=00xc@protonmail.com \
--cc=eggert@cs.ucla.edu \
--cc=git@vger.kernel.org \
--cc=martin.agren@gmail.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.