# [PATCH] Use 'grep -a' to fix some errors with non-GNU grep(1).

2 messages from 2008-03-28 to 2008-03-29. Participants: Bernd Ahlers, Jeff King.
Thread: https://gitlist.dev/t/12908

## Bernd Ahlers, 2008-03-28 22:40

Subject: [PATCH] Use 'grep -a' to fix some errors with non-GNU grep(1).
Message-ID: <20080328224011.GB5486@dengar.tuneafish.de>
URL: https://gitlist.dev/e/20080328224011.GB5486%40dengar.tuneafish.de

```
This fixes test errors on OpenBSD.

Signed-off-by: Bernd Ahlers <bernd@ba-net.org>
---
 t/t4019-diff-wserror.sh        |   28 ++++++++++++++--------------
 t/t9200-git-cvsexportcommit.sh |    2 +-
 2 files changed, 15 insertions(+), 15 deletions(-)

diff --git a/t/t4019-diff-wserror.sh b/t/t4019-diff-wserror.sh
index 0d9cbb6..275b41a 100755
--- a/t/t4019-diff-wserror.sh
+++ b/t/t4019-diff-wserror.sh
@@ -22,8 +22,8 @@ blue_grep='7;34m' ;# ESC [ 7 ; 3 4 m
 test_expect_success default '
 
 	git diff --color >output
-	grep "$blue_grep" output >error
-	grep -v "$blue_grep" output >normal
+	grep -a "$blue_grep" output >error
+	grep -a -v "$blue_grep" output >normal
 
 	grep Eight normal >/dev/null &&
 	grep HT error >/dev/null &&
@@ -37,8 +37,8 @@ test_expect_success 'without -trail' '
 
 	git config core.whitespace -trail
 	git diff --color >output
-	grep "$blue_grep" output >error
-	grep -v "$blue_grep" output >normal
+	grep -a "$blue_grep" output >error
+	grep -a -v "$blue_grep" output >normal
 
 	grep Eight normal >/dev/null &&
 	grep HT error >/dev/null &&
@@ -53,8 +53,8 @@ test_expect_success 'without -trail (attribute)' '
 	git config --unset core.whitespace
 	echo "F whitespace=-trail" >.gitattributes
 	git diff --color >output
-	grep "$blue_grep" output >error
-	grep -v "$blue_grep" output >normal
+	grep -a "$blue_grep" output >error
+	grep -a -v "$blue_grep" output >normal
 
 	grep Eight normal >/dev/null &&
 	grep HT error >/dev/null &&
@@ -69,8 +69,8 @@ test_expect_success 'without -space' '
 	rm -f .gitattributes
 	git config core.whitespace -space
 	git diff --color >output
-	grep "$blue_grep" output >error
-	grep -v "$blue_grep" output >normal
+	grep -a "$blue_grep" output >error
+	grep -a -v "$blue_grep" output >normal
 
 	grep Eight normal >/dev/null &&
 	grep HT normal >/dev/null &&
@@ -85,8 +85,8 @@ test_expect_success 'without -space (attribute)' '
 	git config --unset core.whitespace
 	echo "F whitespace=-space" >.gitattributes
 	git diff --color >output
-	grep "$blue_grep" output >error
-	grep -v "$blue_grep" output >normal
+	grep -a "$blue_grep" output >error
+	grep -a -v "$blue_grep" output >normal
 
 	grep Eight normal >/dev/null &&
 	grep HT normal >/dev/null &&
@@ -101,8 +101,8 @@ test_expect_success 'with indent-non-tab only' '
 	rm -f .gitattributes
 	git config core.whitespace indent,-trailing,-space
 	git diff --color >output
-	grep "$blue_grep" output >error
-	grep -v "$blue_grep" output >normal
+	grep -a "$blue_grep" output >error
+	grep -a -v "$blue_grep" output >normal
 
 	grep Eight error >/dev/null &&
 	grep HT normal >/dev/null &&
@@ -117,8 +117,8 @@ test_expect_success 'with indent-non-tab only (attribute)' '
 	git config --unset core.whitespace
 	echo "F whitespace=indent,-trailing,-space" >.gitattributes
 	git diff --color >output
-	grep "$blue_grep" output >error
-	grep -v "$blue_grep" output >normal
+	grep -a "$blue_grep" output >error
+	grep -a -v "$blue_grep" output >normal
 
 	grep Eight error >/dev/null &&
 	grep HT normal >/dev/null &&
diff --git a/t/t9200-git-cvsexportcommit.sh b/t/t9200-git-cvsexportcommit.sh
index 42b144b..d3bd48c 100755
--- a/t/t9200-git-cvsexportcommit.sh
+++ b/t/t9200-git-cvsexportcommit.sh
@@ -30,7 +30,7 @@ exit 1
 
 check_entries () {
 	# $1 == directory, $2 == expected
-	grep '^/' "$1/CVS/Entries" | sort | cut -d/ -f2,3,5 >actual
+	grep -a '^/' "$1/CVS/Entries" | sort | cut -d/ -f2,3,5 >actual
 	if test -z "$2"
 	then
 		>expected
-- 
1.5.4.5

```

## Jeff King, 2008-03-29 00:49

Subject: Re: [PATCH] Use 'grep -a' to fix some errors with non-GNU grep(1).
Message-ID: <20080329004908.GA9878@coredump.intra.peff.net>
URL: https://gitlist.dev/e/20080329004908.GA9878%40coredump.intra.peff.net
In-Reply-To: <20080328224011.GB5486@dengar.tuneafish.de>

```
On Fri, Mar 28, 2008 at 11:40:11PM +0100, Bernd Ahlers wrote:

> This fixes test errors on OpenBSD.

Nak. "grep -a" isn't portable. If you have binary goo to check, I think
the safest thing is to either generate it using printf (if it's short
and easy) or include the expected output in a test file (this is what I
did for t4020; see 53a5b443).

You could also potentially use git-grep for this, but I haven't looked
into how it handles "-a" (and in general, I think we try to avoid using
git tools as test infrastructure to avoid false positives; e.g., we
prefer using a system tool to compare expected output rather than
git-diff).

-Peff

```
