git/list[1] front-page[2] threads[3] people[4] search[5] about
 

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

From
Junio C Hamano <gitster@pobox.com>
Date
Dec 22, 2017, 21:07 UTC
Message-ID
<xmqq4loiqxn4.fsf@gitster.mtv.corp.google.com>
In-Reply-To
<20171221212646.24461-1-tboegi@web.de>
tboegi@web.de writes:
>
> Reviewed-by: Johannes Schindelin <Johannes.Schindelin@gmx.de>
> Signed-off-by: Torsten Bögershausen <tboegi@web.de>
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 <file)" is padded with leading
    whitespace on the left, so
    
            test "$(wc -l <file)" = 4
    
    would not work (most notably on macosX); the users of test_line_count
    helper would not suffer from such a portability glitch.
    
    Add a check in check-non-portable-shell.pl to find '"' between
    `wc -l` and '=' and hint the user about test_line_count().
    
    Signed-off-by: Torsten Bögershausen <tboegi@web.de>
    Reviewed-by: Johannes Schindelin <Johannes.Schindelin@gmx.de>
    Helped-by: Eric Sunshine <sunshine@sunshineco.com>
    Signed-off-by: Junio C Hamano <gitster@pobox.com>
Show 12 quoted lines
> ---
>  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 ;-)
Show 8 quoted lines
> @@ -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 ;-)
Previous: tboegi@web.deNext: Torsten Bögershausen
Message 22 of 26 in “What's cooking in git.git (Dec 2017, #01; Mon, 4)”
  1. Junio C HamanoDec 4, 2017
  2. Jeff HostetlerDec 4, 2017
  3. Elijah NewrenDec 4, 2017
  4. Jonathan TanDec 4, 2017
  5. Junio C HamanoDec 5, 2017
  6. Lars SchneiderDec 6, 2017
  7. Torsten BögershausenDec 6, 2017
  8. Junio C HamanoDec 6, 2017
  9. Johannes SchindelinDec 7, 2017
  10. Todd ZullingerDec 7, 2017
  11. Junio C HamanoDec 7, 2017
  12. Lars SchneiderDec 7, 2017
  13. Junio C HamanoDec 7, 2017
  14. Jeff HostetlerDec 7, 2017
  15. Junio C HamanoDec 7, 2017
  16. 1/1 check-non-portable-shell.pl: Quoted `wc -l` is not portabletboegi@web.de, Dec 10, 2017
  17. Johannes SchindelinDec 10, 2017
  18. Junio C HamanoDec 11, 2017
  19. 1/1 check-non-portable-shell.pl: Quoted `wc -l` is not portabletboegi@web.de, Dec 16, 2017
  20. Eric SunshineDec 17, 2017
  21. 1/1 check-non-portable-shell.pl: Quoted `wc -l` is not portabletboegi@web.de, Dec 21, 2017
  22. Junio C HamanoDec 22, 2017
  23. Torsten BögershausenDec 23, 2017
  24. Todd ZullingerDec 7, 2017
  25. Torsten BögershausenDec 9, 2017
  26. Johannes SchindelinDec 10, 2017

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.