]> git.ipfire.org Git - thirdparty/git.git/commitdiff
check-non-portable-shell.pl: `wc -l` may have leading WS
authorTorsten Bögershausen <tboegi@web.de>
Thu, 21 Dec 2017 21:26:46 +0000 (22:26 +0100)
committerJunio C Hamano <gitster@pobox.com>
Fri, 22 Dec 2017 21:00:51 +0000 (13:00 -0800)
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>
t/check-non-portable-shell.pl

index 03dc9d28525730cdf57c74d13cab22da59dcdfbd..e07f0284372ec25c91fd62f0d136c31d80263a0d 100755 (executable)
@@ -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;