Skip to contentSkip to conversation

test failure in t4014-format-patch.sh with master

BUGS Remi Vanicat 5 participants 12 messages Jun 15, 2016

lore
Share & tools
lore
#0 lore raw

Hello,

While trying to wrote a test for git, I discover that there is a test failure in master on my computer:

$ ./t4014-format-patch.sh
[....]
* FAIL 8: replay did not screw up the log message

git cat-file commit rebuild-1 | grep "^Side .* with .* backslash-n"

It seem that now, somewhere a \n has been interpreted as a newline.

Bisecting point the problem to the 2e6e3e82 commit "git-am: cope better with an empty Subject: line"

Signature · 1 line
Rémi Vanicat
#1 lore raw
Quoted 3 lines · Remi Vanicat

While trying to wrote a test for git, I discover that there is a test failure in master on my computer:

Hmm. Doesn't fail for me.

Quoted 7 lines
$ ./t4014-format-patch.sh
[....]
* FAIL 8: replay did not screw up the log message

git cat-file commit rebuild-1 | grep "^Side .* with .* backslash-n"

It seem that now, somewhere a \n has been interpreted as a newline.

I wonder if it is some shell-specific variable expansion issue. What's your /bin/sh? (I assume, from your email address, that you're using Debian, and I thought Debian used bash, but maybe that's not true).

What does

	a="hello\nhi"
	echo $a

result in?

Linus

#2 lore raw
Quoted 21 lines · Linus Torvalds
Quoted 3 lines · Remi Vanicat

While trying to wrote a test for git, I discover that there is a test failure in master on my computer:

Hmm. Doesn't fail for me.

Quoted 7 lines
$ ./t4014-format-patch.sh
[....]
* FAIL 8: replay did not screw up the log message

git cat-file commit rebuild-1 | grep "^Side .* with .* backslash-n"

It seem that now, somewhere a \n has been interpreted as a newline.

I wonder if it is some shell-specific variable expansion issue. What's your /bin/sh? (I assume, from your email address, that you're using Debian, and I thought Debian used bash, but maybe that's not true).

Quoted 6 lines

What does

	a="hello\nhi"
	echo $a

result in?

Debian has its own dash which is supposed to be a lightweight alternative to bash and "for checking POSIX compliance of scripts" (quote from the packages description). I don't happen to know off-hand whether POSIX says that echo should default to -e, but dash seems to do that:

$ dash
$ a="hello\nhi"
$ echo $a
hello
hi

Björn

#3 lore raw
Quoted 7 lines · Björn Steinbrink

Debian has its own dash which is supposed to be a lightweight alternative to bash and "for checking POSIX compliance of scripts" (quote from the packages description). I don't happen to know off-hand whether POSIX says that echo should default to -e, but dash seems to do that:

Quoted 5 lines
$ dash
$ a="hello\nhi"
$ echo $a
hello
hi

Ahh. So that "echo" should just be replaced with a 'printf "%s\n"' instead?

We have a _lot_ of "echo"s though. I suspect the only ones we'd ever catch are the ones explicitly tested for. I suspect that the dash echo is just broken.

Linus

#4 lore raw
Quoted 16 lines · Linus Torvalds
Quoted 7 lines · Björn Steinbrink

Debian has its own dash which is supposed to be a lightweight alternative to bash and "for checking POSIX compliance of scripts" (quote from the packages description). I don't happen to know off-hand whether POSIX says that echo should default to -e, but dash seems to do that:

Quoted 5 lines
$ dash
$ a="hello\nhi"
$ echo $a
hello
hi
Quoted 6 lines

Ahh. So that "echo" should just be replaced with a 'printf "%s\n"' instead?

We have a _lot_ of "echo"s though. I suspect the only ones we'd ever catch are the ones explicitly tested for. I suspect that the dash echo is just broken.

Wow, seems that "echo" in itself is "broken". According to POSIX[1] backslashes induce implementation defined behaviour, and there seem to be two historic versions of echo, one that knows about -n and one that interprets escape sequences. So echo is totally non-portable unless you avoid -n as well as backslashes. Ouch.

The POSIX docs, as well as random Google results, indeed recommend to use printf instead. But that switch seems painful as well...

Björn

[1] http://www.opengroup.org/onlinepubs/009695399/utilities/echo.html

#5 lore raw
In reply to Linus Torvalds
Quoted 6 lines · Linus Torvalds

Ahh. So that "echo" should just be replaced with a 'printf "%s\n"' instead?

We have a _lot_ of "echo"s though. I suspect the only ones we'd ever catch are the ones explicitly tested for. I suspect that the dash echo is just broken.

As Bjorn mentioned, it's POSIX. Junio and I already hunted down quite a few of these, so I think we are OK in general, and this is just a new one that got introduced.

-Peff

#7 lore raw
In reply to Linus Torvalds

2008/4/17, Linus Torvalds <[email protected]>:

Quoted 3 lines · Remi Vanicat

[...]

Quoted 5 lines
Quoted 3 lines
$ ./t4014-format-patch.sh
[....]
* FAIL 8: replay did not screw up the log message

Hmm. Doesn't fail for me.

[...]

Quoted 3 lines

I wonder if it is some shell-specific variable expansion issue. What's your /bin/sh? (I assume, from your email address, that you're using Debian, and I thought Debian used bash, but maybe that's not true).

Debian used bash, but I use dash as /bin/sh

Quoted 6 lines

What does

        a="hello\nhi"
        echo $a

result in?

here is the problem:

$/bin/sh

$ a="hello\nhi"
$ echo $a
hello
hi

Mmm, I Wonder what posix said about this, but it look like a bug with dash

#8 lore raw
Quoted 10 lines · Rémi Vanicat

2008/4/17, Linus Torvalds <[email protected]>:

Quoted 2 lines · Remi Vanicat

[...]

Quoted 5 lines
Quoted 3 lines
$ ./t4014-format-patch.sh
[....]
* FAIL 8: replay did not screw up the log message

Hmm. Doesn't fail for me.

Quoted 14 lines

[...]

Quoted 3 lines

I wonder if it is some shell-specific variable expansion issue. What's your /bin/sh? (I assume, from your email address, that you're using Debian, and I thought Debian used bash, but maybe that's not true).

Debian used bash, but I use dash as /bin/sh

Quoted 6 lines

What does

        a="hello\nhi"
        echo $a

result in?

So perhaps this one is the troublemaker?

 git-am.sh |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
git-am.sh +1 -1
index 646dc45..5b20bbd 100755
@@ -330,7 +330,7 @@ do
 		SUBJECT="$(sed -n '/^Subject/ s/Subject: //p' "$dotest/info")"
 		case "$keep_subject" in -k)  SUBJECT="[PATCH] $SUBJECT" ;; esac
 
-		(echo "$SUBJECT" ; echo ; cat "$dotest/msg") |
+		(printf '%s\n' "$SUBJECT" ; echo ; cat "$dotest/msg") |
 			git stripspace > "$dotest/msg-clean"
 		;;
 	esac
#9 lore raw

git-am.sh do · line 333

Quoted 3 lines · Junio C Hamano
git-am.sh +1 -1
-		(echo "$SUBJECT" ; echo ; cat "$dotest/msg") |
+		(printf '%s\n' "$SUBJECT" ; echo ; cat "$dotest/msg") |

Well, get rid of the superfluous second 'echo' then too, replacing it with another '\n'. IOW:

	( printf '%s\n\n' "$SUBJECT" ; cat "$dotest/msg" ) | 

instead.

Linus

#10 lore raw

2008/4/18, Linus Torvalds <[email protected]>:

Quoted 8 lines · Junio C Hamano

git-am.sh do · line 333

Quoted 3 lines
git-am.sh +1 -1
-             (echo "$SUBJECT" ; echo ; cat "$dotest/msg") |
+             (printf '%s\n' "$SUBJECT" ; echo ; cat "$dotest/msg") |
Quoted 6 lines

Well, get rid of the superfluous second 'echo' then too, replacing it
with another '\n'. IOW:

        ( printf '%s\n\n' "$SUBJECT" ; cat "$dotest/msg" ) |

instead.

This work for me: no more test failure on my computer

#11 lore raw
Quoted 9 lines · Rémi Vanicat

2008/4/18, Linus Torvalds <[email protected]>:

Quoted 8 lines · Junio C Hamano
Quoted 3 lines
git-am.sh +1 -1
-             (echo "$SUBJECT" ; echo ; cat "$dotest/msg") |
+             (printf '%s\n' "$SUBJECT" ; echo ; cat "$dotest/msg") |
Quoted 8 lines
Quoted 6 lines

Well, get rid of the superfluous second 'echo' then too, replacing it
with another '\n'. IOW:

        ( printf '%s\n\n' "$SUBJECT" ; cat "$dotest/msg" ) |

instead.

This work for me: no more test failure on my computer

Thanks for confirmation. I reproduced the breakage and the fix myself with "make SHELL_PATH=/bin/dash" myself, too.