From: Chris Packham <judge.packham@gmail.com>
To: git@vger.kernel.org
Cc: Jens.Lehmann@web.de, pclouds@gmail.com, gitster@pobox.com,
Chris Packham <judge.packham@gmail.com>
Subject: [RFC/PATCHv2 4/5] add test for git grep --recursive
Date: Fri, 15 Oct 2010 16:26:43 -0700 [thread overview]
Message-ID: <1287185204-843-5-git-send-email-judge.packham@gmail.com> (raw)
In-Reply-To: <1287185204-843-1-git-send-email-judge.packham@gmail.com>
Signed-off-by: Chris Packham <judge.packham@gmail.com>
---
t/t7820-grep-recursive.sh | 183 +++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 183 insertions(+), 0 deletions(-)
create mode 100644 t/t7820-grep-recursive.sh
diff --git a/t/t7820-grep-recursive.sh b/t/t7820-grep-recursive.sh
new file mode 100644
index 0000000..3c386b4
--- /dev/null
+++ b/t/t7820-grep-recursive.sh
@@ -0,0 +1,183 @@
+#!/bin/sh
+#
+# Copyright (c) 2010 Chris Packham
+#
+
+test_description='git grep --recursive test
+
+This test checks the ability of git grep to search within submodules when told
+to do so with the --recursive option'
+
+. ./test-lib.sh
+
+restore_test_defaults()
+{
+ unset GIT_SUPER_REFNAME
+}
+
+test_expect_success 'setup' '
+ cat >t <<-\EOF &&
+ one two three
+ four five six
+ seven eight nine
+ EOF
+ git add t &&
+ git commit -m "initial commit"
+'
+submodurl=$TRASH_DIRECTORY
+
+test_expect_success 'setup submodules' '
+ for mod in submodule1 submodule2 submodule3 submodule4 submodule5; do
+ git submodule add "$submodurl" $mod &&
+ git submodule init $mod
+ done &&
+ git commit -m "setup submodules for test"
+'
+
+test_expect_success 'update data in each submodule' '
+ for n in 1 2 3 4 5; do
+ (cd submodule$n &&
+ sed -i "s/^four.*/& #$n/" t &&
+ git commit -a -m"update") &&
+ git add submodule$n
+ done &&
+ git commit -m "update data in each submodule"
+'
+
+test_expect_success 'non-recursive grep in base' '
+ cat >expected <<-\EOF &&
+ t:four five six
+ EOF
+ git grep "five" >actual &&
+ test_cmp expected actual
+'
+
+test_expect_success 'submodule-ref option' '
+ cat >expected <<-\EOF &&
+ bar:t:four five six
+ EOF
+ GIT_SUPER_REFNAME=bar &&
+ export GIT_SUPER_REFNAME &&
+ git grep "five" master >actual &&
+ test_cmp expected actual &&
+ restore_test_defaults
+'
+
+test_expect_success 'non-recursive grep in submodule' '
+ (
+ cd submodule1 &&
+ cat >expected <<-\EOF &&
+ t:four five six #1
+ EOF
+ git grep "five" >actual &&
+ test_cmp expected actual
+ )
+'
+
+test_expect_success 'recursive grep' '
+ cat >expected <<-\EOF &&
+ submodule1/t:four five six #1
+ submodule2/t:four five six #2
+ submodule3/t:four five six #3
+ submodule4/t:four five six #4
+ submodule5/t:four five six #5
+ t:four five six
+ EOF
+ git grep --recursive "five" >actual &&
+ test_cmp expected actual
+'
+
+test_expect_success 'recursive grep (with -n)' '
+ cat >expected <<-\EOF &&
+ submodule1/t:2:four five six #1
+ submodule2/t:2:four five six #2
+ submodule3/t:2:four five six #3
+ submodule4/t:2:four five six #4
+ submodule5/t:2:four five six #5
+ t:2:four five six
+ EOF
+ git grep --recursive -n "five" >actual &&
+ test_cmp expected actual
+'
+
+test_expect_success 'recursive grep (with -l)' '
+ cat >expected <<-\EOF &&
+ submodule1/t
+ submodule2/t
+ submodule3/t
+ submodule4/t
+ submodule5/t
+ t
+ EOF
+ git grep --recursive -l "five" >actual &&
+ test_cmp expected actual
+'
+
+test_expect_success 'recursive grep (with --or)' '
+ cat >expected <<-\EOF &&
+ submodule1/t:one two three
+ submodule1/t:four five six #1
+ submodule2/t:one two three
+ submodule2/t:four five six #2
+ submodule3/t:one two three
+ submodule3/t:four five six #3
+ submodule4/t:one two three
+ submodule4/t:four five six #4
+ submodule5/t:one two three
+ submodule5/t:four five six #5
+ t:one two three
+ t:four five six
+ EOF
+ git grep --recursive \( -e "five" --or -e "two" \) >actual &&
+ test_cmp expected actual
+'
+
+test_expect_success 'recursive grep (with --and --not)' '
+ cat >expected <<-\EOF &&
+ submodule2/t:four five six #2
+ submodule3/t:four five six #3
+ submodule4/t:four five six #4
+ submodule5/t:four five six #5
+ t:four five six
+ EOF
+ git grep --recursive \( -e "five" --and --not -e "#1" \) >actual &&
+ test_cmp expected actual
+'
+
+test_expect_success 'recursive grep with refspec' '
+ cat >expected <<-\EOF &&
+ master:submodule1/t:four five six #1
+ master:submodule2/t:four five six #2
+ master:submodule3/t:four five six #3
+ master:submodule4/t:four five six #4
+ master:submodule5/t:four five six #5
+ master:t:four five six
+ EOF
+ git grep --recursive five master >actual &&
+ test_cmp expected actual
+'
+
+test_expect_success 'recursive grep with pathspec' '
+ cat >expected <<-\EOF &&
+ submodule2/t:four five six #2
+ EOF
+ git grep --recursive five -- submodule2 >actual &&
+ test_cmp expected actual
+'
+
+test_expect_success 'recursive grep with pathspec and refspec' '
+ cat >expected <<-\EOF &&
+ master:submodule2/t:four five six #2
+ EOF
+ git grep --recursive five master -- submodule2 >actual &&
+ test_cmp expected actual
+'
+
+test_expect_failure 'recursive grep with --max-depth' '
+ cat >expected <<-\EOF &&
+ t:four five six
+ EOF
+ git grep --recursive --max-depth=1 five >actual &&
+ test_cmp expected actual
+'
+test_done
--
1.7.3.1
next prev parent reply other threads:[~2010-10-15 23:27 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-10-15 23:26 [RGC/PATCHv2] grep: submodule support Chris Packham
2010-10-15 23:26 ` [RFC/PATCHv2 1/5] worktree: provide better prefix to go back to original cwd Chris Packham
2010-10-16 18:42 ` Jonathan Nieder
2010-10-17 2:48 ` Chris Packham
2010-10-17 10:01 ` Nguyen Thai Ngoc Duy
2010-10-18 2:05 ` Chris Packham
2010-10-15 23:26 ` [RFC/PATCHv2 2/5] grep: output the path from cwd to worktree Chris Packham
2010-10-15 23:26 ` [RFC/PATCHv2 3/5] grep_cache: check pathspec first Chris Packham
2010-10-15 23:26 ` Chris Packham [this message]
2010-10-15 23:26 ` [RFC/PATCHv2 5/5] grep: add support for grepping in submodules Chris Packham
2010-10-17 10:28 ` Nguyen Thai Ngoc Duy
2010-10-18 2:01 ` Chris Packham
2010-10-18 3:37 ` Nguyen Thai Ngoc Duy
2010-10-16 15:54 ` [RGC/PATCHv2] grep: submodule support Jens Lehmann
2010-10-17 2:13 ` Chris Packham
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=1287185204-843-5-git-send-email-judge.packham@gmail.com \
--to=judge.packham@gmail.com \
--cc=Jens.Lehmann@web.de \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=pclouds@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 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).