[PATCH v3 1/1] check-non-portable-shell.pl: Quoted `wc -l` is not portable
- From
tboegi@web.de <tboegi@web.de>
- Date
- Dec 21, 2017, 21:26 UTC
- Message-ID
- <20171221212646.24461-1-tboegi@web.de>
- In-Reply-To
- <xmqqh8t2ckgw.fsf@gitster.mtv.corp.google.com>
From: Torsten Bögershausen <tboegi@web.de>
wc -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 MakefileAnd this means that shell expressions like test "$(wc -l <expect)" = "4" don't work under Mac OS,
Commit fb3340a6 introduced test_line_count() as a portable solution.
Add a check in check-non-portable-shell.pl to find '"' between `wc -l` and '=' and hint the user about test_line_count().
Reviewed-by: Johannes Schindelin <Johannes.Schindelin@gmx.de> Signed-off-by: Torsten Bögershausen <tboegi@web.de> --- 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