From: Torsten Bögershausen <redacted>
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 <expect)" = "4" don't work under Mac OS,
A portable way to use `wc -l` is to omit the '"':
test $(wc -l <expect) = "4"
Add a check in check-non-portable-shell.pl to find '"' between
`wc -l` and '='
Signed-off-by: Torsten Bögershausen <redacted>
---
t/check-non-portable-shell.pl | 1 +
1 file changed, 1 insertion(+)
@@ -21,6 +21,7 @@ while (<>) {/^\s*declare\s+/anderr'arrays/declare not portable';/^\s*[^#]\s*which\s/anderr'which is not portable (please use type)';/\btest\s+[^=]*==/anderr'"test a == b" is not portable (please use =)';+/\bwc-l.*"\s*=/ and err '`"$(wc-l)"`isnotportable,pleaseuse`$(wc-l)`';/\bexport\s+[A-Za-z0-9_]*=/anderr'"export FOO=bar" is not portable (please use FOO=bar && export FOO)';#thisresetsour$.foreachfilecloseARGVifeof;
From: Johannes Schindelin <hidden> Date: 2017-12-10 14:04:16
Hi Torsten,
On Sun, 10 Dec 2017, tboegi@web.de wrote:
quoted hunk
From: Torsten Bögershausen <redacted>
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 <expect)" = "4" don't work under Mac OS,
A portable way to use `wc -l` is to omit the '"':
test $(wc -l <expect) = "4"
Add a check in check-non-portable-shell.pl to find '"' between
`wc -l` and '='
Signed-off-by: Torsten Bögershausen <redacted>
---
t/check-non-portable-shell.pl | 1 +
1 file changed, 1 insertion(+)
@@ -21,6 +21,7 @@ while (<>) {/^\s*declare\s+/anderr'arrays/declare not portable';/^\s*[^#]\s*which\s/anderr'which is not portable (please use type)';/\btest\s+[^=]*==/anderr'"test a == b" is not portable (please use =)';+/\bwc-l.*"\s*=/ and err '`"$(wc-l)"`isnotportable,pleaseuse`$(wc-l)`';/\bexport\s+[A-Za-z0-9_]*=/anderr'"export FOO=bar" is not portable (please use FOO=bar && export FOO)';#thisresetsour$.foreachfilecloseARGVifeof;
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
From: Torsten Bögershausen <redacted>
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 Makefile
And 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 <redacted>
Signed-off-by: Torsten Bögershausen <redacted>
---
I added Dscho as reviewer, thanks.
If there is anything more, please holler.
t/check-non-portable-shell.pl | 1 +
1 file changed, 1 insertion(+)
@@ -21,6 +21,7 @@ while (<>) {/^\s*declare\s+/anderr'arrays/declare not portable';/^\s*[^#]\s*which\s/anderr'which is not portable (please use type)';/\btest\s+[^=]*==/anderr'"test a == b" is not portable (please use =)';+/\bwc-l.*"\s*=/ and err '`"$(wc-l)"`isnotportable,pleaseusetest_line_count';/\bexport\s+[A-Za-z0-9_]*=/anderr'"export FOO=bar" is not portable (please use FOO=bar && export FOO)';#thisresetsour$.foreachfilecloseARGVifeof;
From: Eric Sunshine <hidden> Date: 2017-12-17 00:06:46
On Sat, Dec 16, 2017 at 2:52 PM, [off-list ref] wrote:
quoted hunk
[...]
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 <redacted>
Signed-off-by: Torsten Bögershausen <redacted>
---
@@ -21,6 +21,7 @@ while (<>) {/^\s*declare\s+/anderr'arrays/declare not portable';/^\s*[^#]\s*which\s/anderr'which is not portable (please use type)';/\btest\s+[^=]*==/anderr'"test a == b" is not portable (please use =)';+/\bwc-l.*"\s*=/ and err '`"$(wc-l)"`isnotportable,pleaseusetest_line_count';
Nit: Every other "please use" suggestion is parenthesized; for
consistency, this probably ought to be, as well.
/\bexport\s+[A-Za-z0-9_]*=/ and err '"export FOO=bar" is not portable (please use FOO=bar && export FOO)';
From: Torsten Bögershausen <redacted>
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 Makefile
And 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 <redacted>
Signed-off-by: Torsten Bögershausen <redacted>
---
t/check-non-portable-shell.pl | 1 +
1 file changed, 1 insertion(+)
@@ -21,6 +21,7 @@ while (<>) {/^\s*declare\s+/anderr'arrays/declare not portable';/^\s*[^#]\s*which\s/anderr'which is not portable (please use type)';/\btest\s+[^=]*==/anderr'"test a == b" is not portable (please use =)';+/\bwc-l.*"\s*=/ and err '`"$(wc-l)"`isnotportable(pleaseusetest_line_count)';/\bexport\s+[A-Za-z0-9_]*=/anderr'"export FOO=bar" is not portable (please use FOO=bar && export FOO)';#thisresetsour$.foreachfilecloseARGVifeof;