Re: [PATCH v3 1/1] check-non-portable-shell.pl: Quoted `wc -l` is not portable
On Fri, Dec 22, 2017 at 01:07:59PM -0800, Junio C Hamano wrote: > tbo...@web.de writes: > > > > > Reviewed-by: Johannes Schindelin> > Signed-off-by: Torsten Bögershausen > > I'll flip these and add a helped-by to credit Eric. ... > Don't try to apply this patch to your tree yourself ;-) Thanks so much for cleaning up my mess.
Re: [PATCH v3 1/1] check-non-portable-shell.pl: Quoted `wc -l` is not portable
tbo...@web.de writes: > > Reviewed-by: Johannes Schindelin> Signed-off-by: Torsten Bögershausen I'll flip these and add a helped-by to credit Eric. check-non-portable-shell.pl: `wc -l` may have leading WS Test scripts count number of lines in an output and check it againt its expectation. fb3340a6 ("test-lib: introduce test_line_count to measure files", 2010-10-31) introduced a helper to show a failure in such a test in a more readable way than comparing `wc -l` output with a number. Besides, on some platforms, "$(wc -l Reviewed-by: Johannes Schindelin Helped-by: Eric Sunshine Signed-off-by: Junio C Hamano > --- > t/check-non-portable-shell.pl | 1 + > 1 file changed, 1 insertion(+) > > diff --git a/t/check-non-portable-shell.pl b/t/check-non-portable-shell.pl > index 03dc9d285..e07f02843 100755 > > Use () around the hint. > Thanks to Eric for the sharp eyes. > > --- a/t/check-non-portable-shell.pl > +++ b/t/check-non-portable-shell.pl Don't try to apply this patch to your tree yourself ;-) > @@ -21,6 +21,7 @@ while (<>) { > /^\s*declare\s+/ and err 'arrays/declare not portable'; > /^\s*[^#]\s*which\s/ and err 'which is not portable (please use type)'; > /\btest\s+[^=]*==/ and err '"test a == b" is not portable (please use > =)'; > + /\bwc -l.*"\s*=/ and err '`"$(wc -l)"` is not portable (please use > test_line_count)'; > /\bexport\s+[A-Za-z0-9_]*=/ and err '"export FOO=bar" is not portable > (please use FOO=bar && export FOO)'; > # this resets our $. for each file > close ARGV if eof; Thanks. The dq before \s*= is rather cute ;-)
[PATCH v3 1/1] check-non-portable-shell.pl: Quoted `wc -l` is not portable
From: Torsten Bögershausenwc -l was used to count the number if lines in test scripts. $ wc -l Makefile gives a line like this: 105 Makefile while Mac OS has 4 leading spaces: 105 Makefile And this means that shell expressions like test "$(wc -l Signed-off-by: Torsten Bögershausen --- t/check-non-portable-shell.pl | 1 + 1 file changed, 1 insertion(+) diff --git a/t/check-non-portable-shell.pl b/t/check-non-portable-shell.pl index 03dc9d285..e07f02843 100755 Use () around the hint. Thanks to Eric for the sharp eyes. --- a/t/check-non-portable-shell.pl +++ b/t/check-non-portable-shell.pl @@ -21,6 +21,7 @@ while (<>) { /^\s*declare\s+/ and err 'arrays/declare not portable'; /^\s*[^#]\s*which\s/ and err 'which is not portable (please use type)'; /\btest\s+[^=]*==/ and err '"test a == b" is not portable (please use =)'; + /\bwc -l.*"\s*=/ and err '`"$(wc -l)"` is not portable (please use test_line_count)'; /\bexport\s+[A-Za-z0-9_]*=/ and err '"export FOO=bar" is not portable (please use FOO=bar && export FOO)'; # this resets our $. for each file close ARGV if eof; -- 2.15.1.271.g1a4e40aa5d