All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] t/gitweb-lib: Split HTTP response with non-GNU sed
@ 2009-11-23 17:33 Brian Gernhardt
  2009-11-23 18:27 ` Junio C Hamano
  0 siblings, 1 reply; 4+ messages in thread
From: Brian Gernhardt @ 2009-11-23 17:33 UTC (permalink / raw)
  To: Git List; +Cc: Junio C Hamano

Recognizing \r in a regex is something GNU sed will do, but other sed
implementation's won't.  (Found with BSD sed on OS X.) So use a
literal carriage return instead.

Signed-off-by: Brian Gernhardt <brian@gernhardtsoftware.com>
---
 t/gitweb-lib.sh |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/t/gitweb-lib.sh b/t/gitweb-lib.sh
index 32b841d..35dda58 100644
--- a/t/gitweb-lib.sh
+++ b/t/gitweb-lib.sh
@@ -52,8 +52,8 @@ gitweb_run () {
 	rm -f gitweb.log &&
 	perl -- "$SCRIPT_NAME" \
 		>gitweb.output 2>gitweb.log &&
-	sed -e   '/^\r$/q' <gitweb.output >gitweb.headers &&
-	sed -e '1,/^\r$/d' <gitweb.output >gitweb.body    &&
+	sed -e   '/^
$/q' <gitweb.output >gitweb.headers &&
+	sed -e '1,/^
$/d' <gitweb.output >gitweb.body    &&
 	if grep '^[[]' gitweb.log >/dev/null 2>&1; then false; else true; fi
 
 	# gitweb.log is left for debugging
-- 
1.6.5.3.433.g11067

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] t/gitweb-lib: Split HTTP response with non-GNU sed
  2009-11-23 17:33 [PATCH] t/gitweb-lib: Split HTTP response with non-GNU sed Brian Gernhardt
@ 2009-11-23 18:27 ` Junio C Hamano
  2009-11-23 18:50   ` Brian Gernhardt
  2009-11-24 16:59   ` Jakub Narebski
  0 siblings, 2 replies; 4+ messages in thread
From: Junio C Hamano @ 2009-11-23 18:27 UTC (permalink / raw)
  To: Brian Gernhardt; +Cc: Git List, Jakub Narebski

Brian Gernhardt <brian@gernhardtsoftware.com> writes:

> Recognizing \r in a regex is something GNU sed will do, but other sed
> implementation's won't.  (Found with BSD sed on OS X.) So use a
> literal carriage return instead.

I'd actually prefer not having to deal with this issue.  How about doing
something like this instead?

 t/gitweb-lib.sh |   14 ++++++++++++--
 1 files changed, 12 insertions(+), 2 deletions(-)

diff --git a/t/gitweb-lib.sh b/t/gitweb-lib.sh
index 32b841d..3121950 100644
--- a/t/gitweb-lib.sh
+++ b/t/gitweb-lib.sh
@@ -52,8 +52,18 @@ gitweb_run () {
 	rm -f gitweb.log &&
 	perl -- "$SCRIPT_NAME" \
 		>gitweb.output 2>gitweb.log &&
-	sed -e   '/^\r$/q' <gitweb.output >gitweb.headers &&
-	sed -e '1,/^\r$/d' <gitweb.output >gitweb.body    &&
+	perl -w -e '
+		open O, ">gitweb.headers";
+		while (<>) {
+			print O;
+			last if (/^\r$/ || /^$/);
+		}
+		open O, ">gitweb.body";
+		while (<>) {
+			print O;
+		}
+		close O;
+	' gitweb.output &&
 	if grep '^[[]' gitweb.log >/dev/null 2>&1; then false; else true; fi
 
 	# gitweb.log is left for debugging

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] t/gitweb-lib: Split HTTP response with non-GNU sed
  2009-11-23 18:27 ` Junio C Hamano
@ 2009-11-23 18:50   ` Brian Gernhardt
  2009-11-24 16:59   ` Jakub Narebski
  1 sibling, 0 replies; 4+ messages in thread
From: Brian Gernhardt @ 2009-11-23 18:50 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: Git List, Jakub Narebski


On Nov 23, 2009, at 1:27 PM, Junio C Hamano wrote:

> Brian Gernhardt <brian@gernhardtsoftware.com> writes:
> 
>> Recognizing \r in a regex is something GNU sed will do, but other sed
>> implementation's won't.  (Found with BSD sed on OS X.) So use a
>> literal carriage return instead.
> 
> I'd actually prefer not having to deal with this issue.  How about doing
> something like this instead?

Works for me.  I just went for the obvious minimal change to make it work.  But since we're testing a perl script, we might as well just use perl to deal with it's output.

~~ Brian

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] t/gitweb-lib: Split HTTP response with non-GNU sed
  2009-11-23 18:27 ` Junio C Hamano
  2009-11-23 18:50   ` Brian Gernhardt
@ 2009-11-24 16:59   ` Jakub Narebski
  1 sibling, 0 replies; 4+ messages in thread
From: Jakub Narebski @ 2009-11-24 16:59 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: Brian Gernhardt, Git List

On Mon, 23 Nov 2009, Junio C Hamano wrote:
> Brian Gernhardt <brian@gernhardtsoftware.com> writes:
> 
> > Recognizing \r in a regex is something GNU sed will do, but other sed
> > implementation's won't.  (Found with BSD sed on OS X.) So use a
> > literal carriage return instead.
[...]

> > diff --git a/t/gitweb-lib.sh b/t/gitweb-lib.sh
> > index 32b841d..35dda58 100644
> > --- a/t/gitweb-lib.sh
> > +++ b/t/gitweb-lib.sh
> > @@ -52,8 +52,8 @@ gitweb_run () {
> >         rm -f gitweb.log &&
> >         perl -- "$SCRIPT_NAME" \
> >                 >gitweb.output 2>gitweb.log &&
> > -       sed -e   '/^\r$/q' <gitweb.output >gitweb.headers &&
> > -       sed -e '1,/^\r$/d' <gitweb.output >gitweb.body    &&
> > +       sed -e   '/^
> > $/q' <gitweb.output >gitweb.headers &&
> > +       sed -e '1,/^
> > $/d' <gitweb.output >gitweb.body    &&
> >         if grep '^[[]' gitweb.log >/dev/null 2>&1; then false; else
> > true; fi 
> >         # gitweb.log is left for debugging

If we were to do it this way, I would prefer to set and then use 
'cr' or 'crlf' variable (in sed expression).

> 
> I'd actually prefer not having to deal with this issue.  How about doing
> something like this instead?
> 
>  t/gitweb-lib.sh |   14 ++++++++++++--
>  1 files changed, 12 insertions(+), 2 deletions(-)
> 
> diff --git a/t/gitweb-lib.sh b/t/gitweb-lib.sh
> index 32b841d..3121950 100644
> --- a/t/gitweb-lib.sh
> +++ b/t/gitweb-lib.sh
> @@ -52,8 +52,18 @@ gitweb_run () {
>  	rm -f gitweb.log &&
>  	perl -- "$SCRIPT_NAME" \
>  		>gitweb.output 2>gitweb.log &&
> -	sed -e   '/^\r$/q' <gitweb.output >gitweb.headers &&
> -	sed -e '1,/^\r$/d' <gitweb.output >gitweb.body    &&
> +	perl -w -e '

"perl", or "$PERL", or "$PERL_PATH"?

> +		open O, ">gitweb.headers";

Well, modern Perl would use here

+		open my $fh, ">", "gitweb.headers";

But it is not that important here.

> +		while (<>) {
> +			print O;
> +			last if (/^\r$/ || /^$/);
> +		}
> +		open O, ">gitweb.body";
> +		while (<>) {
> +			print O;
> +		}
> +		close O;
> +	' gitweb.output &&
>  	if grep '^[[]' gitweb.log >/dev/null 2>&1; then false; else true; fi
>  
>  	# gitweb.log is left for debugging
> 

This is a good solution.  We test Perl script anyway (so Perl is required
for running this test), and this way we can do this portably and in one
pass (one fork).

-- 
Jakub Narebski
Poland

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2009-11-24 17:00 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-11-23 17:33 [PATCH] t/gitweb-lib: Split HTTP response with non-GNU sed Brian Gernhardt
2009-11-23 18:27 ` Junio C Hamano
2009-11-23 18:50   ` Brian Gernhardt
2009-11-24 16:59   ` Jakub Narebski

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.