# [PATCH] git-grep: Fix problems with recently added tests

2 messages from 2011-05-26 to 2011-05-26. Participants: Michał Kiedrowicz, Brian Gernhardt.
Thread: https://gitlist.dev/t/27477

## Michał Kiedrowicz, 2011-05-26 21:50

Subject: [PATCH] git-grep: Fix problems with recently added tests
Message-ID: <1306446622-12784-1-git-send-email-michal.kiedrowicz@gmail.com>
URL: https://gitlist.dev/e/1306446622-12784-1-git-send-email-michal.kiedrowicz%40gmail.com

```
Brian Gernhardt reported that test 'git grep -E -F -G a\\+b' fails on
OS X 10.6.7. This is because I assumed \+ is part of BRE, which isn't
true on all platforms.

The easiest way to make this test pass is to just update expected
output, but that would make the test pointless. Its real purpose is to
check whether 'git grep -E -F -G' is different from 'git grep -E -G -F'.
To check that, let's change pattern to "aa*b". 'git grep -F' should
return empty string and 'git grep -G' should match "aab".

I also made two small tweaks to the tests. First, I added path "ab" to
all calls to future-proof tests. Second, I updated last two tests to
better show that 'git grep -P -E' is different from 'git grep -E -P'.

Signed-off-by: Michał Kiedrowicz <michal.kiedrowicz@gmail.com>
---
 t/t7810-grep.sh |   28 ++++++++++++++--------------
 1 files changed, 14 insertions(+), 14 deletions(-)

diff --git a/t/t7810-grep.sh b/t/t7810-grep.sh
index e061108..0435740 100755
--- a/t/t7810-grep.sh
+++ b/t/t7810-grep.sh
@@ -234,13 +234,13 @@ do
 	'
 	test_expect_success "grep $L with grep.extendedRegexp=false" '
 		echo "ab:a+b" >expected &&
-		git -c grep.extendedRegexp=false grep "a+b" >actual &&
+		git -c grep.extendedRegexp=false grep "a+b" ab >actual &&
 		test_cmp expected actual
 	'
 
 	test_expect_success "grep $L with grep.extendedRegexp=true" '
 		echo "ab:aab" >expected &&
-		git -c grep.extendedRegexp=true grep "a+b" >actual &&
+		git -c grep.extendedRegexp=true grep "a+b" ab >actual &&
 		test_cmp expected actual
 	'
 done
@@ -688,37 +688,37 @@ test_expect_success LIBPCRE 'grep -P invalidpattern properly dies ' '
 
 test_expect_success 'grep -F -E -G pattern' '
 	echo ab:a+b >expected &&
-	git grep -F -E -G a+b >actual &&
+	git grep -F -E -G a+b ab >actual &&
 	test_cmp expected actual
 '
 
 test_expect_success 'grep -F -G -E pattern' '
 	echo ab:aab >expected &&
-	git grep -F -G -E a+b >actual &&
+	git grep -F -G -E a+b ab >actual &&
 	test_cmp expected actual
 '
 
 test_expect_success 'grep -E -F -G pattern' '
 	echo ab:aab >expected &&
-	git grep -E -F -G a\\+b >actual &&
+	git grep -E -F -G "aa*b" ab >actual &&
 	test_cmp expected actual
 '
 
 test_expect_success 'grep -E -G -F pattern' '
-	echo ab:a\\+b >expected &&
-	git grep -E -G -F a\\+b >actual &&
-	test_cmp expected actual
+	:>empty &&
+	test_must_fail git grep -E -G -F "aa*b" ab >actual &&
+	test_cmp empty actual
 '
 
-test_expect_success 'grep -G -F -E pattern' '
-	echo ab:a+b >expected &&
-	git grep -G -F -E a\\+b >actual &&
-	test_cmp expected actual
+test_expect_success 'grep -G -F -P -E pattern' '
+	:>empty &&
+	test_must_fail git grep -G -F -P -E "a\x{2b}b" ab >actual &&
+	test_cmp empty actual
 '
 
-test_expect_success LIBPCRE 'grep -E -G -F -P pattern' '
+test_expect_success LIBPCRE 'grep -G -F -E -P pattern' '
 	echo ab:a+b >expected &&
-	git grep -E -G -F -P a\\+b >actual &&
+	git grep -G -F -E -P "a\x{2b}b" ab >actual &&
 	test_cmp expected actual
 '
 
-- 
1.7.3.4

```

## Brian Gernhardt, 2011-05-26 21:55

Subject: Re: [PATCH] git-grep: Fix problems with recently added tests
Message-ID: <A33A9CA5-B648-44AE-9B8E-7C27AB48FE54@gernhardtsoftware.com>
URL: https://gitlist.dev/e/A33A9CA5-B648-44AE-9B8E-7C27AB48FE54%40gernhardtsoftware.com
In-Reply-To: <1306446622-12784-1-git-send-email-michal.kiedrowicz@gmail.com>

```

On May 26, 2011, at 5:50 PM, Michał Kiedrowicz wrote:

> test_expect_success 'grep -E -F -G pattern' '
> 	echo ab:aab >expected &&
> -	git grep -E -F -G a\\+b >actual &&
> +	git grep -E -F -G "aa*b" ab >actual &&
> 	test_cmp expected actual
> '

Wouldn't this also pass if -E was active instead of -G?  That's why I mentioned using a literal + in the pattern so that what -G and what -E would match would be different.

~~ Brian

```
