Skip to contentSkip to conversation

test-bzr: Do not use unportable sed "\+"

PATCH In review Torsten Bögershausen 2 participants 13 messages Jun 15, 2016

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 test-bzr: Do not use unportable sed "\+"

Using sed -e '/[0-9]\+//' to find "one ore more" digits is not portable.
Use the Basic Regular Expression '/[0-9][0-9]*//' instead

---
 contrib/remote-helpers/test-bzr.sh | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
contrib/remote-helpers/test-bzr.sh +1 -1
index d9c32f4..5dfa070 100755
@@ -328,7 +328,7 @@ test_expect_success 'strip' '
 
   echo four >> content &&
   bzr commit -m four &&
-  bzr log --line | sed -e "s/^[0-9]\+: //" > ../expected
+  bzr log --line | sed -e "s/^[0-9][0-9]*: //" > ../expected
   ) &&
 
   (cd gitrepo &&
Signature · 1 line
1.8.2.1.614.g66d7af5
#1 lore raw

On 05/11/2013 03:25 PM, Torsten Bögershausen wrote:
Sorry, I forgot to mention that there is another test case that fails in test-bzr.sh (Both Linux and MacOS):

Cloning into 'gitrepo'...

actual 2013-05-11 20:07:21.510312073 +0000 renamed from expected 2013-05-11 20:07:17.678360248 +0000 +1 -1
@@ -1,3 +1,3 @@
-origin/HEAD
+origin
 origin/branch
 origin/trunk

not ok 11 - proper bzr repo

#2 lore raw
In reply to Torsten Bögershausen
Quoted 5 lines · Torsten Bögershausen

Using sed -e '/[0-9]\+//' to find "one ore more" digits is not portable.
Use the Basic Regular Expression '/[0-9][0-9]*//' instead

Thanks. Is there another one in t/t5551-http-fetch.sh that checks the tags?

Quoted 17 lines
---
 contrib/remote-helpers/test-bzr.sh | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
contrib/remote-helpers/test-bzr.sh +1 -1
index d9c32f4..5dfa070 100755
@@ -328,7 +328,7 @@ test_expect_success 'strip' '
 
   echo four >> content &&
   bzr commit -m four &&
-  bzr log --line | sed -e "s/^[0-9]\+: //" > ../expected
+  bzr log --line | sed -e "s/^[0-9][0-9]*: //" > ../expected
   ) &&
 
   (cd gitrepo &&
#3 lore raw
Quoted 2 lines · Junio C Hamano

Thanks. Is there another one in t/t5551-http-fetch.sh that checks the tags?

I think your sed will see the same breakage for the one in 5551 (my sed is unfortunately GNU and ".\+" does not break it). Could you test this patch with:

     GIT_TEST_LONG=YesPlease GIT_TEST_HTTPD=YesPlease \
     ./t5551-http-fetch.sh

Thanks.

 t/t5551-http-fetch.sh | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
t/t5551-http-fetch.sh +1 -1
index b23efbb..4a3184e 100755
@@ -209,7 +209,7 @@ test_expect_success EXPENSIVE 'create 50,000 tags in the repo' '
 
 	# now assign tags to all the dangling commits we created above
 	tag=$("$PERL_PATH" -e "print \"bla\" x 30") &&
-	sed -e "s/^:\(.\+\) \(.\+\)$/\2 refs\/tags\/$tag-\1/" <marks >>packed-refs
+	sed -e "s|^:\([^ ]*\) \(.*\)$|\2 refs/tags/$tag-\1|" <marks >>packed-refs
 	)
 '
 
#4 lore raw
Quoted 22 lines · Junio C Hamano
Quoted 2 lines · Junio C Hamano

Thanks. Is there another one in t/t5551-http-fetch.sh that checks the tags?

I think your sed will see the same breakage for the one in 5551 (my sed is unfortunately GNU and ".\+" does not break it). Could you test this patch with:

     GIT_TEST_LONG=YesPlease GIT_TEST_HTTPD=YesPlease \
     ./t5551-http-fetch.sh

Thanks.

 t/t5551-http-fetch.sh | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
t/t5551-http-fetch.sh +0 -0
index b23efbb..4a3184e 100755

t/t5551-http-fetch.sh test_expect_success EXPENSIVE 'create 50,000 tags in the repo' ' · line 213

Quoted 6 lines
t/t5551-http-fetch.sh +1 -1
@@ -209,7 +209,7 @@ test_expect_success EXPENSIVE 'create 50,000 tags in the repo' '
 
 	# now assign tags to all the dangling commits we created above
 	tag=$("$PERL_PATH" -e "print \"bla\" x 30") &&
-	sed -e "s/^:\(.\+\) \(.\+\)$/\2 refs\/tags\/$tag-\1/" <marks >>packed-refs
+	sed -e "s|^:\([^ ]*\) \(.*\)$|\2 refs/tags/$tag-\1|" <marks >>packed-refs
 	)

I did,
the interesting thing is that the test passes with and without your patch. (After enabling GIT_TEST_LONG and GIT_TEST_HTTPD in both cases)

Side note:
I added this line in in t/check-non-portable-shell.pl
/sed[^"]+"[^"]+\\([+])/ and err "sed \\$1 is not portable)";

#5 lore raw
Quoted 3 lines · Torsten Bögershausen

I did,
the interesting thing is that the test passes with and without your patch. (After enabling GIT_TEST_LONG and GIT_TEST_HTTPD in both cases)

Strange. Do you see differences between the produced packed-refs file?

#6 lore raw
Quoted 8 lines · Junio C Hamano
Quoted 3 lines · Torsten Bögershausen

I did,
the interesting thing is that the test passes with and without your patch. (After enabling GIT_TEST_LONG and GIT_TEST_HTTPD in both cases)

Strange. Do you see differences between the produced packed-refs file?

The original version seems to look like this:
:1 666527db455708922859283c673094002092910b
:2 1e2acf73c6db881cfb1d56d67662e3d9260be2cf
[snip]

The "fixed POSIX version" follows that style:
666527db455708922859283c673094002092910b refs/tags/blablablablablablablablablablablablablablablablablablablablablablablablablablablablablabla-1 1e2acf73c6db881cfb1d56d67662e3d9260be2cf refs/tags/blablablablablablablablablablablablablablablablablablablablablablablablablablablablablabla-2 [snip]

(Just to verify the changes:)

t/t5551-http-fetch.sh +3 -0
index b23efbb..68965f0 100755
@@ -210,8 +210,11 @@ test_expect_success EXPENSIVE 'create 50,000 tags in the repo' '
        # now assign tags to all the dangling commits we created above
        tag=$("$PERL_PATH" -e "print \"bla\" x 30") &&
        sed -e "s/^:\(.\+\) \(.\+\)$/\2 refs\/tags\/$tag-\1/" <marks >>packed-refs
+       sed -e "s|^:\([^ ]*\) \(.*\)$|\2 refs/tags/$tag-\1|" <marks >packed-refs.junio
+       sed -e "s/^:\(.\+\) \(.\+\)$/\2 refs\/tags\/$tag-\1/" <marks >packed-refs.orig
        )
 '
+       exit 0
#7 lore raw
Quoted 15 lines · Torsten Bögershausen
Quoted 8 lines · Junio C Hamano
Quoted 3 lines · Torsten Bögershausen

I did,
the interesting thing is that the test passes with and without your patch. (After enabling GIT_TEST_LONG and GIT_TEST_HTTPD in both cases)

Strange. Do you see differences between the produced packed-refs file?

The original version seems to look like this:
:1 666527db455708922859283c673094002092910b
:2 1e2acf73c6db881cfb1d56d67662e3d9260be2cf
[snip]

Quoted 4 lines

The "fixed POSIX version" follows that style:
666527db455708922859283c673094002092910b refs/tags/blablablablablablablablablablablablablablablablablablablablablablablablablablablablablabla-1 1e2acf73c6db881cfb1d56d67662e3d9260be2cf refs/tags/blablablablablablablablablablablablablablablablablablablablablablablablablablablablablabla-2 [snip]

That means whatever the test that comes after that set-up step to populate the packed-refs file does not need the packed-refs file.

In fact, the test only sees if "clone" succeeds, without checking what refs are present in the resulting repository. The original repository lacks these 50000 tags due to the non-portable sed construct (it has a corrupt packed-refs file) and it may or may not have other refs, but because cloning an empty repository does not error out these days, the test just passes.

Sloppy.

#8 lore raw

PATCH 1/1 t5551: do not use unportable sed '\+'

The set-up step to prepare a repository with 50000 tags used a non-porable '\+' to match one-or-more.

The error was not caught because the next test that uses that repository did not even bother to check if these expected tags were actually cloned to the resulting repository.

Fix the sed construct to use BRE and update the "clone" test that wanted to test cloning from such a repository with many refs to check the resulting repository.

---
 t/t5551-http-fetch.sh | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
t/t5551-http-fetch.sh +6 -2
index 47eb769..fe6637b 100755
@@ -184,13 +184,17 @@ test_expect_success EXPENSIVE 'create 50,000 tags in the repo' '
 
 	# now assign tags to all the dangling commits we created above
 	tag=$("$PERL_PATH" -e "print \"bla\" x 30") &&
-	sed -e "s/^:\(.\+\) \(.\+\)$/\2 refs\/tags\/$tag-\1/" <marks >>packed-refs
+	sed -e "s|^:\([^ ]*\) \(.*\)$|\2 refs/tags/$tag-\1|" <marks >>packed-refs
 	)
 '
 
 test_expect_success EXPENSIVE 'clone the 50,000 tag repo to check OS command line overflow' '
 	git clone $HTTPD_URL/smart/repo.git too-many-refs 2>err &&
-	test_line_count = 0 err
+	test_line_count = 0 err &&
+	(
+		cd too-many-refs &&
+		test $(git for-each-ref refs/tags | wc -l) = 50000
+	)
 '
 
 stop_httpd
Signature · 1 line
1.8.3-rc1-278-g19c008b
#9 lore raw

Re: [PATCH] t5551: do not use unportable sed '\+'

Quoted 5 lines · Junio C Hamano
---
 t/t5551-http-fetch.sh | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

Thanks, works like a charm, tested on Mac OS.
/torsten

#10 lore raw

Re: [PATCH] t5551: do not use unportable sed '\+'

Quoted 8 lines · Torsten Bögershausen
Quoted 5 lines · Junio C Hamano
---
 t/t5551-http-fetch.sh | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

Thanks, works like a charm, tested on Mac OS.
/torsten

Thanks; I take it that you reverted the "sed fix" part and saw the updated "clone" check fail with the platform "sed"?

#11 lore raw

Re: [PATCH] t5551: do not use unportable sed '\+'

Quoted 8 lines · Junio C Hamano
Quoted 6 lines · Torsten Bögershausen
Quoted 5 lines · Junio C Hamano
---
 t/t5551-http-fetch.sh | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
Quoted 5 lines
Quoted 2 lines

Thanks, works like a charm, tested on Mac OS.
/torsten

Thanks; I take it that you reverted the "sed fix" part and saw the updated "clone" check fail with the platform "sed"?

In my first test with the fix the test case passed.
Then the sed expression was only manipulated to verify that the TC failes. And now I took even the original expression and have verfied it is failing.

The short version: Yes

#12 lore raw

Re: [PATCH] t5551: do not use unportable sed '\+'

Quoted 12 lines · Torsten Bögershausen
Quoted 11 lines · Junio C Hamano
Quoted 8 lines · Torsten Bögershausen
Quoted 5 lines · Junio C Hamano
---
 t/t5551-http-fetch.sh | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

Thanks, works like a charm, tested on Mac OS.
/torsten

Quoted 7 lines
Quoted 2 lines

Thanks; I take it that you reverted the "sed fix" part and saw the updated "clone" check fail with the platform "sed"?

In my first test with the fix the test case passed.
Then the sed expression was only manipulated to verify that the TC failes. And now I took even the original expression and have verfied it is failing.

The short version: Yes

Thanks.