Re: Test failures with GNU grep 2.23

18 messages, 4 authors, 2016-06-15 · open the first message on its own page

Re: Test failures with GNU grep 2.23

From: Junio C Hamano <hidden>
Date: 2016-06-15 23:08:19

Jeff King [off-list ref] writes:
Yeah, I'd worry that "-a" is not portable. OTOH, BSD grep seems to have
it, so between that and GNU, I think most systems are covered. We could
do:

  test_lazy_prereq GREP_A '
	echo foo | grep -a foo
  '

and mark these tests with it. I'd also be happy to skip that step and
just do it if and when somebody actually complains about a system
without it (I wouldn't be surprised if most people on antique systems
end up installing GNU grep anyway).

Another option might be using "sed -ne '/^author/p'" or similar. But
that may very well just be trading one portability problem for another.
Would $PERL help, I wonder?

Re: Test failures with GNU grep 2.23

From: Jeff King <hidden>
Date: 2016-06-15 23:08:19

On Fri, Feb 19, 2016 at 09:38:17AM -0800, Junio C Hamano wrote:
Jeff King [off-list ref] writes:
quoted
Yeah, I'd worry that "-a" is not portable. OTOH, BSD grep seems to have
it, so between that and GNU, I think most systems are covered. We could
do:

  test_lazy_prereq GREP_A '
	echo foo | grep -a foo
  '

and mark these tests with it. I'd also be happy to skip that step and
just do it if and when somebody actually complains about a system
without it (I wouldn't be surprised if most people on antique systems
end up installing GNU grep anyway).

Another option might be using "sed -ne '/^author/p'" or similar. But
that may very well just be trading one portability problem for another.
Would $PERL help, I wonder?
It would, though I think you would need to call `binmode` to make it
reliable. I was hesitant to suggest it, because I seem to recall some
resistance to more perl dependencies in the test suite, but I think we
may be past the point of no return there, anyway.

-Peff

Re: Test failures with GNU grep 2.23

From: John Keeping <hidden>
Date: 2016-06-15 23:08:19

On Fri, Feb 19, 2016 at 09:38:17AM -0800, Junio C Hamano wrote:
Jeff King [off-list ref] writes:
quoted
Yeah, I'd worry that "-a" is not portable. OTOH, BSD grep seems to have
it, so between that and GNU, I think most systems are covered. We could
do:

  test_lazy_prereq GREP_A '
	echo foo | grep -a foo
  '

and mark these tests with it. I'd also be happy to skip that step and
just do it if and when somebody actually complains about a system
without it (I wouldn't be surprised if most people on antique systems
end up installing GNU grep anyway).

Another option might be using "sed -ne '/^author/p'" or similar. But
that may very well just be trading one portability problem for another.
Would $PERL help, I wonder?
I suspect that any grep that lacks "-a" also lacks binary file handling
that will break these tests.  I found a Solaris grep that doesn't
support "-a" and it treats these files as text.
From that perspective, it would be better to have a central place that
deals with figuring out how to get grep to work for us.  Perhaps we need
test_grep to get this right.  We already have test_cmp_bin() as a thin
wrapper around cmp so I don't think this is completely unprecedented.

Re: Test failures with GNU grep 2.23

From: Jeff King <hidden>
Date: 2016-06-15 23:08:19

On Fri, Feb 19, 2016 at 07:23:11PM +0000, John Keeping wrote:
I suspect that any grep that lacks "-a" also lacks binary file handling
that will break these tests.  I found a Solaris grep that doesn't
support "-a" and it treats these files as text.

From that perspective, it would be better to have a central place that
deals with figuring out how to get grep to work for us.  Perhaps we need
test_grep to get this right.  We already have test_cmp_bin() as a thin
wrapper around cmp so I don't think this is completely unprecedented.
I think 99% of the time we are using grep for ascii text. As evidenced
by the number of test failures we see with the new grep, it is a small
minority that feed binary gibberish. I'd prefer if "-a" handling didn't
need to pollute anything outside of this narrow range of tests (and as
with my prereq suggestion, I am even find just skipping this narrow
range of tests on platforms with no "-a", though falling back to running
without "-a" is fine if it works).

-Peff

[PATCH 0/2] Fix test failures with GNU grep 2.23

From: John Keeping <hidden>
Date: 2016-06-15 23:08:20

On Fri, Feb 19, 2016 at 02:33:10PM -0500, Jeff King wrote:
On Fri, Feb 19, 2016 at 07:23:11PM +0000, John Keeping wrote:
quoted
I suspect that any grep that lacks "-a" also lacks binary file handling
that will break these tests.  I found a Solaris grep that doesn't
support "-a" and it treats these files as text.

From that perspective, it would be better to have a central place that
deals with figuring out how to get grep to work for us.  Perhaps we need
test_grep to get this right.  We already have test_cmp_bin() as a thin
wrapper around cmp so I don't think this is completely unprecedented.
I think 99% of the time we are using grep for ascii text. As evidenced
by the number of test failures we see with the new grep, it is a small
minority that feed binary gibberish. I'd prefer if "-a" handling didn't
need to pollute anything outside of this narrow range of tests (and as
with my prereq suggestion, I am even find just skipping this narrow
range of tests on platforms with no "-a", though falling back to running
without "-a" is fine if it works).
I went with using sed in this series because it seems to be the simplest
and most compatible way to extract lines from the input.  We don't need
any special casing to figure out if an implementation needs "-a" or if
it doesn't support that option and all the implementation I tested
support the constructs used here.

John Keeping (2):
  t8005: avoid grep on non-ASCII data
  t9200: avoid grep on non-ASCII data

 t/t8005-blame-i18n.sh          | 16 ++++++++--------
 t/t9200-git-cvsexportcommit.sh |  2 +-
 2 files changed, 9 insertions(+), 9 deletions(-)

-- 
2.7.1.503.g3cfa3ac

[PATCH 1/2] t8005: avoid grep on non-ASCII data

From: John Keeping <hidden>
Date: 2016-06-15 23:08:20

GNU grep 2.23 detects the input used in this test as binary data so it
does not work for extracting lines from a file.  We could add the "-a"
option to force grep to treat the input as text, but not all
implementations support that.  Instead, use sed to extract the desired
lines since it will always treat its input as text.

While touching these lines, modernize the test style to avoid hiding the
exit status of "git blame" and remove a space following a redirection
operator.

Signed-off-by: John Keeping <redacted>
---
 t/t8005-blame-i18n.sh | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)
diff --git a/t/t8005-blame-i18n.sh b/t/t8005-blame-i18n.sh
index 847d098..0a86c72 100755
--- a/t/t8005-blame-i18n.sh
+++ b/t/t8005-blame-i18n.sh
@@ -35,8 +35,8 @@ EOF
 
 test_expect_success !MINGW \
 	'blame respects i18n.commitencoding' '
-	git blame --incremental file | \
-		egrep "^(author|summary) " > actual &&
+	git blame --incremental file >output &&
+	sed -ne "/^\(author\|summary\) /p" output >actual &&
 	test_cmp actual expected
 '
 
@@ -52,8 +52,8 @@ EOF
 test_expect_success !MINGW \
 	'blame respects i18n.logoutputencoding' '
 	git config i18n.logoutputencoding eucJP &&
-	git blame --incremental file | \
-		egrep "^(author|summary) " > actual &&
+	git blame --incremental file >output &&
+	sed -ne "/^\(author\|summary\) /p" output >actual &&
 	test_cmp actual expected
 '
 
@@ -68,8 +68,8 @@ EOF
 
 test_expect_success !MINGW \
 	'blame respects --encoding=UTF-8' '
-	git blame --incremental --encoding=UTF-8 file | \
-		egrep "^(author|summary) " > actual &&
+	git blame --incremental --encoding=UTF-8 file >output &&
+	sed -ne "/^\(author\|summary\) /p" output >actual &&
 	test_cmp actual expected
 '
 
@@ -84,8 +84,8 @@ EOF
 
 test_expect_success !MINGW \
 	'blame respects --encoding=none' '
-	git blame --incremental --encoding=none file | \
-		egrep "^(author|summary) " > actual &&
+	git blame --incremental --encoding=none file >output &&
+	sed -ne "/^\(author\|summary\) /p" output >actual &&
 	test_cmp actual expected
 '
 
-- 
2.7.1.503.g3cfa3ac

[PATCH 2/2] t9200: avoid grep on non-ASCII data

From: John Keeping <hidden>
Date: 2016-06-15 23:08:20

GNU grep 2.23 detects the input used in this test as binary data so it
does not work for extracting lines from a file.  We could add the "-a"
option to force grep to treat the input as text, but not all
implementations support that.  Instead, use sed to extract the desired
lines since it will always treat its input as text.

Signed-off-by: John Keeping <redacted>
---
 t/t9200-git-cvsexportcommit.sh | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/t/t9200-git-cvsexportcommit.sh b/t/t9200-git-cvsexportcommit.sh
index 812c9cd..0765d52 100755
--- a/t/t9200-git-cvsexportcommit.sh
+++ b/t/t9200-git-cvsexportcommit.sh
@@ -35,7 +35,7 @@ exit 1
 
 check_entries () {
 	# $1 == directory, $2 == expected
-	grep '^/' "$1/CVS/Entries" | sort | cut -d/ -f2,3,5 >actual
+	sed -ne '\!^/!p' "$1/CVS/Entries" | sort | cut -d/ -f2,3,5 >actual
 	if test -z "$2"
 	then
 		>expected
-- 
2.7.1.503.g3cfa3ac

Re: [PATCH 1/2] t8005: avoid grep on non-ASCII data

From: Eric Sunshine <hidden>
Date: 2016-06-15 23:08:20

On Sun, Feb 21, 2016 at 12:32 PM, John Keeping [off-list ref] wrote:
quoted hunk
GNU grep 2.23 detects the input used in this test as binary data so it
does not work for extracting lines from a file.  We could add the "-a"
option to force grep to treat the input as text, but not all
implementations support that.  Instead, use sed to extract the desired
lines since it will always treat its input as text.

While touching these lines, modernize the test style to avoid hiding the
exit status of "git blame" and remove a space following a redirection
operator.

Signed-off-by: John Keeping <redacted>
---
diff --git a/t/t8005-blame-i18n.sh b/t/t8005-blame-i18n.sh
@@ -35,8 +35,8 @@ EOF
 test_expect_success !MINGW \
        'blame respects i18n.commitencoding' '
-       git blame --incremental file | \
-               egrep "^(author|summary) " > actual &&
+       git blame --incremental file >output &&
+       sed -ne "/^\(author\|summary\) /p" output >actual &&
These tests all crash and burn with BSD sed (including Mac OS X) since
you're not restricting yourself to BRE (basic regular expressions).
You _could_ request extended regular expressions, which do work on
those platforms, as well as with GNU sed:

    sed -nEe "/^(author|summary) /p" ...
quoted hunk
        test_cmp actual expected
 '
@@ -52,8 +52,8 @@ EOF
 test_expect_success !MINGW \
        'blame respects i18n.logoutputencoding' '
        git config i18n.logoutputencoding eucJP &&
-       git blame --incremental file | \
-               egrep "^(author|summary) " > actual &&
+       git blame --incremental file >output &&
+       sed -ne "/^\(author\|summary\) /p" output >actual &&
        test_cmp actual expected
 '
@@ -68,8 +68,8 @@ EOF

 test_expect_success !MINGW \
        'blame respects --encoding=UTF-8' '
-       git blame --incremental --encoding=UTF-8 file | \
-               egrep "^(author|summary) " > actual &&
+       git blame --incremental --encoding=UTF-8 file >output &&
+       sed -ne "/^\(author\|summary\) /p" output >actual &&
        test_cmp actual expected
 '
@@ -84,8 +84,8 @@ EOF

 test_expect_success !MINGW \
        'blame respects --encoding=none' '
-       git blame --incremental --encoding=none file | \
-               egrep "^(author|summary) " > actual &&
+       git blame --incremental --encoding=none file >output &&
+       sed -ne "/^\(author\|summary\) /p" output >actual &&
        test_cmp actual expected
 '

Re: [PATCH 2/2] t9200: avoid grep on non-ASCII data

From: Eric Sunshine <hidden>
Date: 2016-06-15 23:08:20

On Sun, Feb 21, 2016 at 12:32 PM, John Keeping [off-list ref] wrote:
quoted hunk
GNU grep 2.23 detects the input used in this test as binary data so it
does not work for extracting lines from a file.  We could add the "-a"
option to force grep to treat the input as text, but not all
implementations support that.  Instead, use sed to extract the desired
lines since it will always treat its input as text.

Signed-off-by: John Keeping <redacted>
---
diff --git a/t/t9200-git-cvsexportcommit.sh b/t/t9200-git-cvsexportcommit.sh
@@ -35,7 +35,7 @@ exit 1
 check_entries () {
        # $1 == directory, $2 == expected
-       grep '^/' "$1/CVS/Entries" | sort | cut -d/ -f2,3,5 >actual
+       sed -ne '\!^/!p' "$1/CVS/Entries" | sort | cut -d/ -f2,3,5 >actual
This works with BSD sed, but double negatives are confusing. Have you
considered this instead?

    sed -ne '/^\//p' ...
        if test -z "$2"
        then
                >expected

Re: [PATCH 1/2] t8005: avoid grep on non-ASCII data

From: Jeff King <hidden>
Date: 2016-06-15 23:08:20

On Sun, Feb 21, 2016 at 04:01:27PM -0500, Eric Sunshine wrote:
On Sun, Feb 21, 2016 at 12:32 PM, John Keeping [off-list ref] wrote:
quoted
GNU grep 2.23 detects the input used in this test as binary data so it
does not work for extracting lines from a file.  We could add the "-a"
option to force grep to treat the input as text, but not all
implementations support that.  Instead, use sed to extract the desired
lines since it will always treat its input as text.

While touching these lines, modernize the test style to avoid hiding the
exit status of "git blame" and remove a space following a redirection
operator.

Signed-off-by: John Keeping <redacted>
---
diff --git a/t/t8005-blame-i18n.sh b/t/t8005-blame-i18n.sh
@@ -35,8 +35,8 @@ EOF
 test_expect_success !MINGW \
        'blame respects i18n.commitencoding' '
-       git blame --incremental file | \
-               egrep "^(author|summary) " > actual &&
+       git blame --incremental file >output &&
+       sed -ne "/^\(author\|summary\) /p" output >actual &&
These tests all crash and burn with BSD sed (including Mac OS X) since
you're not restricting yourself to BRE (basic regular expressions).
You _could_ request extended regular expressions, which do work on
those platforms, as well as with GNU sed:

    sed -nEe "/^(author|summary) /p" ...
At that point, I think we may as well use grep, because obscure
platforms are probably broken either way.

I'm tempted to just go the perl route. We already depend on at least a
baisc version of perl5 being installed for many of the other tests, so
it's not really introducing a new dependency.

Something like the patch below works for me. I think we could make it
shorter by using $PERLIO to get the raw behavior, but using binmode will
work even on ancient versions of perl.

John, if you agree on the direction, feel free to combine it with your
patch.
diff --git a/t/t8005-blame-i18n.sh b/t/t8005-blame-i18n.sh
index 847d098..f7a02d8 100755
--- a/t/t8005-blame-i18n.sh
+++ b/t/t8005-blame-i18n.sh
@@ -33,10 +33,20 @@ author $SJIS_NAME
 summary $SJIS_MSG
 EOF
 
+filter_blame () {
+	perl -e '
+		binmode STDIN;
+		binmode STDOUT;
+		while (<>) {
+			print if /^(author|summary) /;
+		}
+	'
+}
+
 test_expect_success !MINGW \
 	'blame respects i18n.commitencoding' '
 	git blame --incremental file | \
-		egrep "^(author|summary) " > actual &&
+		filter_blame >actual &&
 	test_cmp actual expected
 '
 
@@ -53,7 +63,7 @@ test_expect_success !MINGW \
 	'blame respects i18n.logoutputencoding' '
 	git config i18n.logoutputencoding eucJP &&
 	git blame --incremental file | \
-		egrep "^(author|summary) " > actual &&
+		filter_blame > actual &&
 	test_cmp actual expected
 '
 
@@ -69,7 +79,7 @@ EOF
 test_expect_success !MINGW \
 	'blame respects --encoding=UTF-8' '
 	git blame --incremental --encoding=UTF-8 file | \
-		egrep "^(author|summary) " > actual &&
+		filter_blame >actual &&
 	test_cmp actual expected
 '
 
@@ -85,7 +95,7 @@ EOF
 test_expect_success !MINGW \
 	'blame respects --encoding=none' '
 	git blame --incremental --encoding=none file | \
-		egrep "^(author|summary) " > actual &&
+		filter_blame >actual &&
 	test_cmp actual expected
 '
 

Re: [PATCH 1/2] t8005: avoid grep on non-ASCII data

From: Eric Sunshine <hidden>
Date: 2016-06-15 23:08:20

On Sun, Feb 21, 2016 at 6:19 PM, Jeff King [off-list ref] wrote:
On Sun, Feb 21, 2016 at 04:01:27PM -0500, Eric Sunshine wrote:
quoted
On Sun, Feb 21, 2016 at 12:32 PM, John Keeping [off-list ref] wrote:
quoted
-       git blame --incremental file | \
-               egrep "^(author|summary) " > actual &&
+       git blame --incremental file >output &&
+       sed -ne "/^\(author\|summary\) /p" output >actual &&
These tests all crash and burn with BSD sed (including Mac OS X) since
you're not restricting yourself to BRE (basic regular expressions).
You _could_ request extended regular expressions, which do work on
those platforms, as well as with GNU sed:

    sed -nEe "/^(author|summary) /p" ...
At that point, I think we may as well use grep, because obscure
platforms are probably broken either way.
I came to the same conclusion but forgot to say so at the end of my message.
I'm tempted to just go the perl route. We already depend on at least a
baisc version of perl5 being installed for many of the other tests, so
it's not really introducing a new dependency.

Something like the patch below works for me. I think we could make it
shorter by using $PERLIO to get the raw behavior, but using binmode will
work even on ancient versions of perl.

+filter_blame () {
+       perl -e '
+               binmode STDIN;
+               binmode STDOUT;
I was worried about binmode() due to some vague recollection from
years and years ago of it being problematic on Windows, but I see
these tests are all protected by !MINGW anyhow...
quoted hunk
+               while (<>) {
+                       print if /^(author|summary) /;
+               }
+       '
+}
+
 test_expect_success !MINGW \
        'blame respects i18n.commitencoding' '
        git blame --incremental file | \
-               egrep "^(author|summary) " > actual &&
+               filter_blame >actual &&
        test_cmp actual expected
 '
@@ -53,7 +63,7 @@ test_expect_success !MINGW \
        'blame respects i18n.logoutputencoding' '
        git config i18n.logoutputencoding eucJP &&
        git blame --incremental file | \
-               egrep "^(author|summary) " > actual &&
+               filter_blame > actual &&
        test_cmp actual expected
 '
@@ -69,7 +79,7 @@ EOF
 test_expect_success !MINGW \
        'blame respects --encoding=UTF-8' '
        git blame --incremental --encoding=UTF-8 file | \
-               egrep "^(author|summary) " > actual &&
+               filter_blame >actual &&
        test_cmp actual expected
 '
@@ -85,7 +95,7 @@ EOF
 test_expect_success !MINGW \
        'blame respects --encoding=none' '
        git blame --incremental --encoding=none file | \
-               egrep "^(author|summary) " > actual &&
+               filter_blame >actual &&
        test_cmp actual expected
 '

Re: [PATCH 1/2] t8005: avoid grep on non-ASCII data

From: Jeff King <hidden>
Date: 2016-06-15 23:08:20

On Sun, Feb 21, 2016 at 06:31:08PM -0500, Eric Sunshine wrote:
quoted
Something like the patch below works for me. I think we could make it
shorter by using $PERLIO to get the raw behavior, but using binmode will
work even on ancient versions of perl.

+filter_blame () {
+       perl -e '
+               binmode STDIN;
+               binmode STDOUT;
I was worried about binmode() due to some vague recollection from
years and years ago of it being problematic on Windows, but I see
these tests are all protected by !MINGW anyhow...
Thanks for mentioning that. I meant to put a note on that at the end of
_my_ message, but forgot. :)

It does mean we won't do CRLF processing. We could get around that with
some explicit `chomp`-ing, I think. Or just leave it as-is and assume
these will lose the !MINGW prereq.

I see Junio just mentioned elsewhere that we can simply avoid the
extended regular expressions by using two sed commands. That would be
fine with me, too.

-Peff

Re: [PATCH 1/2] t8005: avoid grep on non-ASCII data

From: John Keeping <hidden>
Date: 2016-06-15 23:08:20

On Sun, Feb 21, 2016 at 06:19:14PM -0500, Jeff King wrote:
On Sun, Feb 21, 2016 at 04:01:27PM -0500, Eric Sunshine wrote:
quoted
On Sun, Feb 21, 2016 at 12:32 PM, John Keeping [off-list ref] wrote:
quoted
GNU grep 2.23 detects the input used in this test as binary data so it
does not work for extracting lines from a file.  We could add the "-a"
option to force grep to treat the input as text, but not all
implementations support that.  Instead, use sed to extract the desired
lines since it will always treat its input as text.

While touching these lines, modernize the test style to avoid hiding the
exit status of "git blame" and remove a space following a redirection
operator.

Signed-off-by: John Keeping <redacted>
---
diff --git a/t/t8005-blame-i18n.sh b/t/t8005-blame-i18n.sh
@@ -35,8 +35,8 @@ EOF
 test_expect_success !MINGW \
        'blame respects i18n.commitencoding' '
-       git blame --incremental file | \
-               egrep "^(author|summary) " > actual &&
+       git blame --incremental file >output &&
+       sed -ne "/^\(author\|summary\) /p" output >actual &&
These tests all crash and burn with BSD sed (including Mac OS X) since
you're not restricting yourself to BRE (basic regular expressions).
You _could_ request extended regular expressions, which do work on
those platforms, as well as with GNU sed:

    sed -nEe "/^(author|summary) /p" ...
At that point, I think we may as well use grep, because obscure
platforms are probably broken either way.
Also GNU sed doesn't understand "-E", it uses "-r" for --regexp-extended.
I'm tempted to just go the perl route. We already depend on at least a
baisc version of perl5 being installed for many of the other tests, so
it's not really introducing a new dependency.

Something like the patch below works for me. I think we could make it
shorter by using $PERLIO to get the raw behavior, but using binmode will
work even on ancient versions of perl.

John, if you agree on the direction, feel free to combine it with your
patch.
My original sed version was:

	sed -ne "/^author /p" -e "/^summary /p"

which I think will work on all platforms (we already use it in
t0000-basic.sh) but then I decided to be too clever :-(

I still think sed is simpler than introducing a new function to wrap a
perl script.

Re: [PATCH 2/2] t9200: avoid grep on non-ASCII data

From: John Keeping <hidden>
Date: 2016-06-15 23:08:20

On Sun, Feb 21, 2016 at 04:15:31PM -0500, Eric Sunshine wrote:
On Sun, Feb 21, 2016 at 12:32 PM, John Keeping [off-list ref] wrote:
quoted
GNU grep 2.23 detects the input used in this test as binary data so it
does not work for extracting lines from a file.  We could add the "-a"
option to force grep to treat the input as text, but not all
implementations support that.  Instead, use sed to extract the desired
lines since it will always treat its input as text.

Signed-off-by: John Keeping <redacted>
---
diff --git a/t/t9200-git-cvsexportcommit.sh b/t/t9200-git-cvsexportcommit.sh
@@ -35,7 +35,7 @@ exit 1
 check_entries () {
        # $1 == directory, $2 == expected
-       grep '^/' "$1/CVS/Entries" | sort | cut -d/ -f2,3,5 >actual
+       sed -ne '\!^/!p' "$1/CVS/Entries" | sort | cut -d/ -f2,3,5 >actual
This works with BSD sed, but double negatives are confusing. Have you
considered this instead?

    sed -ne '/^\//p' ...
What do you mean double negatives?  Do you mean using "!" as an
alternative delimiter?  I find changing delimters is normally simpler
than following multiple levels of quoting for escaping slashes, although
in this case it's simple enough that it doesn't make much difference.

Re: [PATCH 1/2] t8005: avoid grep on non-ASCII data

From: Eric Sunshine <hidden>
Date: 2016-06-15 23:08:20

On Sun, Feb 21, 2016 at 6:41 PM, John Keeping [off-list ref] wrote:
On Sun, Feb 21, 2016 at 06:19:14PM -0500, Jeff King wrote:
quoted
On Sun, Feb 21, 2016 at 04:01:27PM -0500, Eric Sunshine wrote:
quoted
These tests all crash and burn with BSD sed (including Mac OS X) since
you're not restricting yourself to BRE (basic regular expressions).
You _could_ request extended regular expressions, which do work on
those platforms, as well as with GNU sed:

    sed -nEe "/^(author|summary) /p" ...
At that point, I think we may as well use grep, because obscure
platforms are probably broken either way.
Also GNU sed doesn't understand "-E", it uses "-r" for --regexp-extended.
It actually does recognize -E in all the versions I've tested,
however, apparently it's undocumented (thus probably should be
avoided).
My original sed version was:

        sed -ne "/^author /p" -e "/^summary /p"

which I think will work on all platforms (we already use it in
t0000-basic.sh) but then I decided to be too clever :-(
The unclever version seems fine.

Re: [PATCH 2/2] t9200: avoid grep on non-ASCII data

From: Eric Sunshine <hidden>
Date: 2016-06-15 23:08:20

On Sun, Feb 21, 2016 at 6:43 PM, John Keeping [off-list ref] wrote:
On Sun, Feb 21, 2016 at 04:15:31PM -0500, Eric Sunshine wrote:
quoted
On Sun, Feb 21, 2016 at 12:32 PM, John Keeping [off-list ref] wrote:
quoted
GNU grep 2.23 detects the input used in this test as binary data so it
does not work for extracting lines from a file.  We could add the "-a"
option to force grep to treat the input as text, but not all
implementations support that.  Instead, use sed to extract the desired
lines since it will always treat its input as text.

Signed-off-by: John Keeping <redacted>
---
diff --git a/t/t9200-git-cvsexportcommit.sh b/t/t9200-git-cvsexportcommit.sh
@@ -35,7 +35,7 @@ exit 1
 check_entries () {
        # $1 == directory, $2 == expected
-       grep '^/' "$1/CVS/Entries" | sort | cut -d/ -f2,3,5 >actual
+       sed -ne '\!^/!p' "$1/CVS/Entries" | sort | cut -d/ -f2,3,5 >actual
This works with BSD sed, but double negatives are confusing. Have you
considered this instead?

    sed -ne '/^\//p' ...
What do you mean double negatives?  Do you mean using "!" as an
alternative delimiter?  I find changing delimters is normally simpler
than following multiple levels of quoting for escaping slashes, although
in this case it's simple enough that it doesn't make much difference.
Nice, I learned something new today. If I recall correctly, historic
sed did not allow the delimiter to be changed (or it wasn't documented
or I simply forgot about the capability). So, feel free to ignore me.

Re: [PATCH 1/2] t8005: avoid grep on non-ASCII data

From: Jeff King <hidden>
Date: 2016-06-15 23:08:21

On Sun, Feb 21, 2016 at 11:41:35PM +0000, John Keeping wrote:
My original sed version was:

	sed -ne "/^author /p" -e "/^summary /p"

which I think will work on all platforms (we already use it in
t0000-basic.sh) but then I decided to be too clever :-(

I still think sed is simpler than introducing a new function to wrap a
perl script.
Yeah, I think that is good (personally I'd use a function anyway, but I
think it is short enough that we could go either way).

-Peff

Re: [PATCH 2/2] t9200: avoid grep on non-ASCII data

From: Jeff King <hidden>
Date: 2016-06-15 23:08:21

On Sun, Feb 21, 2016 at 11:43:45PM +0000, John Keeping wrote:
On Sun, Feb 21, 2016 at 04:15:31PM -0500, Eric Sunshine wrote:
quoted
On Sun, Feb 21, 2016 at 12:32 PM, John Keeping [off-list ref] wrote:
quoted
GNU grep 2.23 detects the input used in this test as binary data so it
does not work for extracting lines from a file.  We could add the "-a"
option to force grep to treat the input as text, but not all
implementations support that.  Instead, use sed to extract the desired
lines since it will always treat its input as text.

Signed-off-by: John Keeping <redacted>
---
diff --git a/t/t9200-git-cvsexportcommit.sh b/t/t9200-git-cvsexportcommit.sh
@@ -35,7 +35,7 @@ exit 1
 check_entries () {
        # $1 == directory, $2 == expected
-       grep '^/' "$1/CVS/Entries" | sort | cut -d/ -f2,3,5 >actual
+       sed -ne '\!^/!p' "$1/CVS/Entries" | sort | cut -d/ -f2,3,5 >actual
This works with BSD sed, but double negatives are confusing. Have you
considered this instead?

    sed -ne '/^\//p' ...
What do you mean double negatives?  Do you mean using "!" as an
alternative delimiter?  I find changing delimters is normally simpler
than following multiple levels of quoting for escaping slashes, although
in this case it's simple enough that it doesn't make much difference.
I agree that changing delimiters is much nicer than backslashes. But I
wonder if using "!" is more confusing than it needs to be, given its
other meanings.

I dunno. I admit that the backslash threw me off, too (since it needs
escaped in interactive shells, I first assumed that's what was going
on). Using backslash to select the delimiter was new to me. I've usually
seen:

  s!/foo/!/bar/!

which is arguably a little more clear. Too bad we cannot do:

  m!/foo!

which I think reads better. Oh well. Maybe:

  sed -ne '\#^/#p'

would be more readable, but I'm just bikeshedding at this point.  The
grep invocation really was the most clear. :-/

-Peff
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help