git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] Avoid using non-portable `echo -n` in tests.
  2008-10-31  5:02 [PATCH] t4030: Don't use echo -n Brian Gernhardt
@ 2008-10-31  5:09 ` Brian Gernhardt
  2008-10-31  8:15   ` Junio C Hamano
                     ` (3 more replies)
  0 siblings, 4 replies; 15+ messages in thread
From: Brian Gernhardt @ 2008-10-31  5:09 UTC (permalink / raw)
  To: Git List; +Cc: Shawn O Pearce

Not all /bin/sh have a builtin echo that recognizes -n.  Using printf
is far more portable.

Discovered on OS X 10.5.5 in t4030-diff-textconv.sh and changed in all
the test scripts.

Signed-off-by: Brian Gernhardt <benji@silverinsanity.com>
---
 t/t2005-checkout-index-symlinks.sh |    2 +-
 t/t2102-update-index-symlinks.sh   |    4 ++--
 t/t4030-diff-textconv.sh           |    2 +-
 t/t6025-merge-symlinks.sh          |    4 ++--
 t/t9400-git-cvsserver-server.sh    |    2 +-
 5 files changed, 7 insertions(+), 7 deletions(-)

diff --git a/t/t2005-checkout-index-symlinks.sh b/t/t2005-checkout-index-symlinks.sh
index ed12c4d..9fa5610 100755
--- a/t/t2005-checkout-index-symlinks.sh
+++ b/t/t2005-checkout-index-symlinks.sh
@@ -13,7 +13,7 @@ file if core.symlinks is false.'
 test_expect_success \
 'preparation' '
 git config core.symlinks false &&
-l=$(echo -n file | git hash-object -t blob -w --stdin) &&
+l=$(printf file | git hash-object -t blob -w --stdin) &&
 echo "120000 $l	symlink" | git update-index --index-info'
 
 test_expect_success \
diff --git a/t/t2102-update-index-symlinks.sh b/t/t2102-update-index-symlinks.sh
index f195aef..1ed44ee 100755
--- a/t/t2102-update-index-symlinks.sh
+++ b/t/t2102-update-index-symlinks.sh
@@ -13,12 +13,12 @@ even if a plain file is in the working tree if core.symlinks is false.'
 test_expect_success \
 'preparation' '
 git config core.symlinks false &&
-l=$(echo -n file | git hash-object -t blob -w --stdin) &&
+l=$(printf file | git hash-object -t blob -w --stdin) &&
 echo "120000 $l	symlink" | git update-index --index-info'
 
 test_expect_success \
 'modify the symbolic link' '
-echo -n new-file > symlink &&
+printf new-file > symlink &&
 git update-index symlink'
 
 test_expect_success \
diff --git a/t/t4030-diff-textconv.sh b/t/t4030-diff-textconv.sh
index 3945731..a235955 100755
--- a/t/t4030-diff-textconv.sh
+++ b/t/t4030-diff-textconv.sh
@@ -105,7 +105,7 @@ index ad8b3d2..67be421
 EOF
 # make a symlink the hard way that works on symlink-challenged file systems
 test_expect_success 'textconv does not act on symlinks' '
-	echo -n frotz > file &&
+	printf frotz > file &&
 	git add file &&
 	git ls-files -s | sed -e s/100644/120000/ |
 		git update-index --index-info &&
diff --git a/t/t6025-merge-symlinks.sh b/t/t6025-merge-symlinks.sh
index 53892a5..433c4de 100755
--- a/t/t6025-merge-symlinks.sh
+++ b/t/t6025-merge-symlinks.sh
@@ -18,11 +18,11 @@ git add file &&
 git commit -m initial &&
 git branch b-symlink &&
 git branch b-file &&
-l=$(echo -n file | git hash-object -t blob -w --stdin) &&
+l=$(printf file | git hash-object -t blob -w --stdin) &&
 echo "120000 $l	symlink" | git update-index --index-info &&
 git commit -m master &&
 git checkout b-symlink &&
-l=$(echo -n file-different | git hash-object -t blob -w --stdin) &&
+l=$(printf file-different | git hash-object -t blob -w --stdin) &&
 echo "120000 $l	symlink" | git update-index --index-info &&
 git commit -m b-symlink &&
 git checkout b-file &&
diff --git a/t/t9400-git-cvsserver-server.sh b/t/t9400-git-cvsserver-server.sh
index c1850d2..f6a2dbd 100755
--- a/t/t9400-git-cvsserver-server.sh
+++ b/t/t9400-git-cvsserver-server.sh
@@ -424,7 +424,7 @@ cd "$WORKDIR"
 test_expect_success 'cvs update (-p)' '
     touch really-empty &&
     echo Line 1 > no-lf &&
-    echo -n Line 2 >> no-lf &&
+    printf Line 2 >> no-lf &&
     git add really-empty no-lf &&
     git commit -q -m "Update -p test" &&
     git push gitcvs.git >/dev/null &&
-- 
1.6.0.3.757.g1e5a4

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

* Re: [PATCH] Avoid using non-portable `echo -n` in tests.
  2008-10-31  5:09 ` [PATCH] Avoid using non-portable `echo -n` in tests Brian Gernhardt
@ 2008-10-31  8:15   ` Junio C Hamano
  2008-10-31 15:38     ` Brian Gernhardt
  2008-10-31  8:20   ` Junio C Hamano
                     ` (2 subsequent siblings)
  3 siblings, 1 reply; 15+ messages in thread
From: Junio C Hamano @ 2008-10-31  8:15 UTC (permalink / raw)
  To: Brian Gernhardt; +Cc: Git List, Shawn O Pearce

Brian Gernhardt <benji@silverinsanity.com> writes:

> Not all /bin/sh have a builtin echo that recognizes -n.  Using printf
> is far more portable.

This is much better (minor nit: we do not care if echo is built-in or
/bin/echo); the point of t4030 is to produce an incomplete line ;-).

Will queue, thanks.

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

* Re: [PATCH] Avoid using non-portable `echo -n` in tests.
  2008-10-31  5:09 ` [PATCH] Avoid using non-portable `echo -n` in tests Brian Gernhardt
  2008-10-31  8:15   ` Junio C Hamano
@ 2008-10-31  8:20   ` Junio C Hamano
  2008-10-31 14:32   ` Shawn O. Pearce
  2008-10-31 18:24   ` Jeff King
  3 siblings, 0 replies; 15+ messages in thread
From: Junio C Hamano @ 2008-10-31  8:20 UTC (permalink / raw)
  To: Brian Gernhardt; +Cc: Git List, Shawn O Pearce

Brian Gernhardt <benji@silverinsanity.com> writes:

> Not all /bin/sh have a builtin echo that recognizes -n.  Using printf
> is far more portable.
>
> Discovered on OS X 10.5.5 in t4030-diff-textconv.sh and changed in all
> the test scripts.

I had an impression that OS X was BSDish.  Wasn't "echo -n" a BSDism?

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

* Re: [PATCH] Avoid using non-portable `echo -n` in tests.
  2008-10-31  5:09 ` [PATCH] Avoid using non-portable `echo -n` in tests Brian Gernhardt
  2008-10-31  8:15   ` Junio C Hamano
  2008-10-31  8:20   ` Junio C Hamano
@ 2008-10-31 14:32   ` Shawn O. Pearce
  2008-10-31 18:24   ` Jeff King
  3 siblings, 0 replies; 15+ messages in thread
From: Shawn O. Pearce @ 2008-10-31 14:32 UTC (permalink / raw)
  To: Brian Gernhardt; +Cc: Git List

Brian Gernhardt <benji@silverinsanity.com> wrote:
> Not all /bin/sh have a builtin echo that recognizes -n.  Using printf
> is far more portable.
 
> diff --git a/t/t9400-git-cvsserver-server.sh b/t/t9400-git-cvsserver-server.sh
> index c1850d2..f6a2dbd 100755
> --- a/t/t9400-git-cvsserver-server.sh
> +++ b/t/t9400-git-cvsserver-server.sh
> @@ -424,7 +424,7 @@ cd "$WORKDIR"
>  test_expect_success 'cvs update (-p)' '
>      touch really-empty &&
>      echo Line 1 > no-lf &&
> -    echo -n Line 2 >> no-lf &&
> +    printf Line 2 >> no-lf &&

That needs to be:

	printf 'Line 2'

to have the same result.  Fortunately I don't think it matters
in this test, but it does read odd.

-- 
Shawn.

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

* Re: [PATCH] Avoid using non-portable `echo -n` in tests.
  2008-10-31  8:15   ` Junio C Hamano
@ 2008-10-31 15:38     ` Brian Gernhardt
  0 siblings, 0 replies; 15+ messages in thread
From: Brian Gernhardt @ 2008-10-31 15:38 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: Git List, Shawn O Pearce


On Oct 31, 2008, at 4:15 AM, Junio C Hamano wrote:

> Brian Gernhardt <benji@silverinsanity.com> writes:
>
>> Not all /bin/sh have a builtin echo that recognizes -n.  Using printf
>> is far more portable.
>
> This is much better (minor nit: we do not care if echo is built-in or
> /bin/echo); the point of t4030 is to produce an incomplete line ;-).

Well, yes.  The reason I phrased it that way was that my /bin/echo  
recognizes -n but /bin/sh does not.

~~ Brian

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

* Re: [PATCH] Avoid using non-portable `echo -n` in tests.
  2008-10-31  5:09 ` [PATCH] Avoid using non-portable `echo -n` in tests Brian Gernhardt
                     ` (2 preceding siblings ...)
  2008-10-31 14:32   ` Shawn O. Pearce
@ 2008-10-31 18:24   ` Jeff King
  2008-10-31 18:36     ` Pierre Habouzit
  2008-11-03 16:30     ` Mike Ralphson
  3 siblings, 2 replies; 15+ messages in thread
From: Jeff King @ 2008-10-31 18:24 UTC (permalink / raw)
  To: Brian Gernhardt; +Cc: Git List, Shawn O Pearce

On Fri, Oct 31, 2008 at 01:09:13AM -0400, Brian Gernhardt wrote:

> Not all /bin/sh have a builtin echo that recognizes -n.  Using printf
> is far more portable.
> 
> Discovered on OS X 10.5.5 in t4030-diff-textconv.sh and changed in all
> the test scripts.

Hmph. I think this is a good patch, and there is precedent in the past
(20fa04ea, 2aad957, 9754563). But I am surprised this was not caught by
our recent autobuilding project.

However, it seems to work on FreeBSD (which makes it doubly weird that
it is broken on OS X). On Solaris, the /bin/sh is so horribly broken
that I have to use bash anyway. Commit 9754563 claims breakage on AIX,
but it looks like Mike is doing the AIX builds with bash.

So I guess we just need an OS X autobuild. ;)

>  t/t4030-diff-textconv.sh           |    2 +-

And of course this one was me, but I blame JSixt, whose test I just
mindlessly copied. ;)

-Peff

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

* Re: [PATCH] Avoid using non-portable `echo -n` in tests.
  2008-10-31 18:24   ` Jeff King
@ 2008-10-31 18:36     ` Pierre Habouzit
  2008-10-31 18:39       ` Jeff King
  2008-11-03 16:30     ` Mike Ralphson
  1 sibling, 1 reply; 15+ messages in thread
From: Pierre Habouzit @ 2008-10-31 18:36 UTC (permalink / raw)
  To: Jeff King; +Cc: Brian Gernhardt, Git List, Shawn O Pearce

[-- Attachment #1: Type: text/plain, Size: 1108 bytes --]

On Fri, Oct 31, 2008 at 06:24:56PM +0000, Jeff King wrote:
> On Fri, Oct 31, 2008 at 01:09:13AM -0400, Brian Gernhardt wrote:
> 
> > Not all /bin/sh have a builtin echo that recognizes -n.  Using printf
> > is far more portable.
> > 
> > Discovered on OS X 10.5.5 in t4030-diff-textconv.sh and changed in all
> > the test scripts.
> 
> Hmph. I think this is a good patch, and there is precedent in the past
> (20fa04ea, 2aad957, 9754563). But I am surprised this was not caught by
> our recent autobuilding project.

Set up a Debian autobuilder with dash as a /bin/sh (apt-get install
dash, dpkg-reconfigure -plow dash and say 'yes'). You'll see those kind
of problems arise immediately.

Dash is a POSIX compatible shell, with almost no extension added (in
particular its echo has no -n option) which helps to find those kind of
issues.

It would help detecting git shell scripts that use bashism as well.

-- 
·O·  Pierre Habouzit
··O                                                madcoder@debian.org
OOO                                                http://www.madism.org

[-- Attachment #2: Type: application/pgp-signature, Size: 197 bytes --]

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

* Re: [PATCH] Avoid using non-portable `echo -n` in tests.
  2008-10-31 18:36     ` Pierre Habouzit
@ 2008-10-31 18:39       ` Jeff King
  2008-10-31 19:35         ` Francis Galiegue
  0 siblings, 1 reply; 15+ messages in thread
From: Jeff King @ 2008-10-31 18:39 UTC (permalink / raw)
  To: Pierre Habouzit; +Cc: Brian Gernhardt, Git List, Shawn O Pearce

On Fri, Oct 31, 2008 at 07:36:01PM +0100, Pierre Habouzit wrote:

> Set up a Debian autobuilder with dash as a /bin/sh (apt-get install
> dash, dpkg-reconfigure -plow dash and say 'yes'). You'll see those kind
> of problems arise immediately.

I don't need to; my development box is Debian with dash as /bin/sh. :)

> Dash is a POSIX compatible shell, with almost no extension added (in
> particular its echo has no -n option) which helps to find those kind of
> issues.
> 
> It would help detecting git shell scripts that use bashism as well.

Agreed, and actually I found such a bashism (test ==) last week (though
of course it also broke on FreeBSD).

-Peff

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

* Re: [PATCH] Avoid using non-portable `echo -n` in tests.
  2008-10-31 18:39       ` Jeff King
@ 2008-10-31 19:35         ` Francis Galiegue
  2008-10-31 22:53           ` Johannes Schindelin
  0 siblings, 1 reply; 15+ messages in thread
From: Francis Galiegue @ 2008-10-31 19:35 UTC (permalink / raw)
  To: Git List

Le Friday 31 October 2008 19:39:33 Jeff King, vous avez écrit :
[...]
>
> Agreed, and actually I found such a bashism (test ==) last week (though
> of course it also broke on FreeBSD).
>

As for bash-isms, a hunt for $(...) also looks necessary...

$ grep -rl '\$([^)]\+)' $(find -type f)|wc -l
272

Unless I'm mistaken (and I probably am), the $(...) construct is 
bash-specific, isn't it?

-- 
Francis Galiegue
ONE2TEAM
Ingénieur système
Mob : +33 (0) 6 83 87 78 75
Tel : +33 (0) 1 78 94 55 52
fge@one2team.com
40 avenue Raymond Poincaré
75116 Paris

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

* Re: [PATCH] Avoid using non-portable `echo -n` in tests.
@ 2008-10-31 19:50 Francis Galiegue
  2008-10-31 20:10 ` Junio C Hamano
  2008-10-31 20:11 ` Ian Hilt
  0 siblings, 2 replies; 15+ messages in thread
From: Francis Galiegue @ 2008-10-31 19:50 UTC (permalink / raw)
  To: Git List

Le Friday 31 October 2008 19:39:33 Jeff King, vous avez écrit :
[...]
>
> Agreed, and actually I found such a bashism (test ==) last week (though
> of course it also broke on FreeBSD).
>

As for bash-isms, a hunt for $(...) also looks necessary...

$ grep -rl '\$([^)]\+)' $(find -type f)|wc -l
272

Unless I'm mistaken (and I probably am), the $(...) construct is 
bash-specific, isn't it?

-- 
fge

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

* Re: [PATCH] Avoid using non-portable `echo -n` in tests.
  2008-10-31 19:50 [PATCH] Avoid using non-portable `echo -n` in tests Francis Galiegue
@ 2008-10-31 20:10 ` Junio C Hamano
  2008-10-31 20:11 ` Ian Hilt
  1 sibling, 0 replies; 15+ messages in thread
From: Junio C Hamano @ 2008-10-31 20:10 UTC (permalink / raw)
  To: Francis Galiegue; +Cc: Git List

Francis Galiegue <fg@one2team.net> writes:

> Unless I'm mistaken (and I probably am), the $(...) construct is 
> bash-specific, isn't it?

You are.

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

* Re: [PATCH] Avoid using non-portable `echo -n` in tests.
  2008-10-31 19:50 [PATCH] Avoid using non-portable `echo -n` in tests Francis Galiegue
  2008-10-31 20:10 ` Junio C Hamano
@ 2008-10-31 20:11 ` Ian Hilt
  2008-10-31 20:30   ` Francis Galiegue
  1 sibling, 1 reply; 15+ messages in thread
From: Ian Hilt @ 2008-10-31 20:11 UTC (permalink / raw)
  To: Francis Galiegue; +Cc: Git List

On Fri, Oct 31, 2008 at 08:50:31PM +0100, Francis Galiegue wrote:
> Le Friday 31 October 2008 19:39:33 Jeff King, vous avez écrit :
> [...]
> >
> > Agreed, and actually I found such a bashism (test ==) last week (though
> > of course it also broke on FreeBSD).
> >
> 
> As for bash-isms, a hunt for $(...) also looks necessary...
> 
> $ grep -rl '\$([^)]\+)' $(find -type f)|wc -l
> 272
> 
> Unless I'm mistaken (and I probably am), the $(...) construct is 
> bash-specific, isn't it?

Nope.  Read section 2.6.3 Command Substitution here,

<http://www.opengroup.org/onlinepubs/009695399/utilities/xcu_chap02.html>

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

* Re: [PATCH] Avoid using non-portable `echo -n` in tests.
  2008-10-31 20:11 ` Ian Hilt
@ 2008-10-31 20:30   ` Francis Galiegue
  0 siblings, 0 replies; 15+ messages in thread
From: Francis Galiegue @ 2008-10-31 20:30 UTC (permalink / raw)
  To: Git List

Le Friday 31 October 2008 21:11:27 Ian Hilt, vous avez écrit :
[...]
> >
> > Unless I'm mistaken (and I probably am), the $(...) construct is
> > bash-specific, isn't it?
>
> Nope.  Read section 2.6.3 Command Substitution here,
>
> <http://www.opengroup.org/onlinepubs/009695399/utilities/xcu_chap02.html>

My bad, then. I'm too "old-school", I guess ;)

-- 
fge

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

* Re: [PATCH] Avoid using non-portable `echo -n` in tests.
  2008-10-31 19:35         ` Francis Galiegue
@ 2008-10-31 22:53           ` Johannes Schindelin
  0 siblings, 0 replies; 15+ messages in thread
From: Johannes Schindelin @ 2008-10-31 22:53 UTC (permalink / raw)
  To: Francis Galiegue; +Cc: Git List

Hi,

On Fri, 31 Oct 2008, Francis Galiegue wrote:

> Unless I'm mistaken (and I probably am), the $(...) construct is 
> bash-specific, isn't it?

You're mistaken,
Dscho

P.S.: 
http://www.opengroup.org/onlinepubs/000095399/utilities/xcu_chap02.html#tag_02_06_03

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

* Re: [PATCH] Avoid using non-portable `echo -n` in tests.
  2008-10-31 18:24   ` Jeff King
  2008-10-31 18:36     ` Pierre Habouzit
@ 2008-11-03 16:30     ` Mike Ralphson
  1 sibling, 0 replies; 15+ messages in thread
From: Mike Ralphson @ 2008-11-03 16:30 UTC (permalink / raw)
  To: Jeff King; +Cc: Brian Gernhardt, Git List, Shawn O Pearce

2008/10/31 Jeff King <peff@peff.net>:
> On Fri, Oct 31, 2008 at 01:09:13AM -0400, Brian Gernhardt wrote:
>
>> Not all /bin/sh have a builtin echo that recognizes -n.  Using printf
>> is far more portable.
>>
>> Discovered on OS X 10.5.5 in t4030-diff-textconv.sh and changed in all
>> the test scripts.
>
> Hmph. I think this is a good patch, and there is precedent in the past
> (20fa04ea, 2aad957, 9754563). But I am surprised this was not caught by
> our recent autobuilding project.
>
> However, it seems to work on FreeBSD (which makes it doubly weird that
> it is broken on OS X). On Solaris, the /bin/sh is so horribly broken
> that I have to use bash anyway. Commit 9754563 claims breakage on AIX,
> but it looks like Mike is doing the AIX builds with bash.

I've just retested with AIX's standard sh (ksh) instead of bash and
there were only two issues.

Oddly enough, one was with the (original) printfs in
t4030-diff-textconv.sh. AIX seems to ship with a perfectly good
printf, but if you install the GNU tools from the 'IBM toolbox for
AIX' (and prepend them to your PATH) it replaces that printf with one
which doesn't grok the "\\1\\n" syntax, but I think wants it to be
"\\01\\n".

The other problem is the 'trap exit' one discussed here:
http://thread.gmane.org/gmane.comp.version-control.git/92748/focus=92944

Mike

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

end of thread, other threads:[~2008-11-03 16:31 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-10-31 19:50 [PATCH] Avoid using non-portable `echo -n` in tests Francis Galiegue
2008-10-31 20:10 ` Junio C Hamano
2008-10-31 20:11 ` Ian Hilt
2008-10-31 20:30   ` Francis Galiegue
  -- strict thread matches above, loose matches on Subject: below --
2008-10-31  5:02 [PATCH] t4030: Don't use echo -n Brian Gernhardt
2008-10-31  5:09 ` [PATCH] Avoid using non-portable `echo -n` in tests Brian Gernhardt
2008-10-31  8:15   ` Junio C Hamano
2008-10-31 15:38     ` Brian Gernhardt
2008-10-31  8:20   ` Junio C Hamano
2008-10-31 14:32   ` Shawn O. Pearce
2008-10-31 18:24   ` Jeff King
2008-10-31 18:36     ` Pierre Habouzit
2008-10-31 18:39       ` Jeff King
2008-10-31 19:35         ` Francis Galiegue
2008-10-31 22:53           ` Johannes Schindelin
2008-11-03 16:30     ` Mike Ralphson

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).