Re: [PATCH v1 1/1] check-non-portable-shell.pl: Quoted `wc -l` is not portable

2017-12-11 Thread Junio C Hamano
tbo...@web.de writes:

> From: Torsten Bögershausen 
>
> wc -l is used to count the number if lines in test scripts.

H, "is used" -> "should not be used", probably.

Just say "Use test_line_count instead" and leave the explanation why
it is a better thing to use to fb3340a6 ("test-lib: introduce
test_line_count to measure files", 2010-10-31), perhaps?


Re: [PATCH v1 1/1] check-non-portable-shell.pl: Quoted `wc -l` is not portable

2017-12-10 Thread Johannes Schindelin
Hi Torsten,

On Sun, 10 Dec 2017, tbo...@web.de wrote:

> From: Torsten Bögershausen 
> 
> wc -l is 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  
> A portable way to use `wc -l` is to omit the '"':
> test $(wc -l  
> Add a check in check-non-portable-shell.pl to find '"' between
> `wc -l` and '='
> 
> 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 03dc9d2852..9ebf65c26f 100755
> --- 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 
> `$(wc -l)`';
>   /\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;

As noted elsewhere, this should suggest `test_line_count` instead. After
all, that function is not only guaranteed to stay portable (even if we
should ever start supporting systems *without* `wc`), but it also has a
semantically-meaningful name worthy of the current century.

Ciao,
Dscho

[PATCH v1 1/1] check-non-portable-shell.pl: Quoted `wc -l` is not portable

2017-12-10 Thread tboegi
From: Torsten Bögershausen 

wc -l is 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