{"thread":{"id":"32514","subject":"[PATCH V2] test: Add check-non-portable-shell.pl","startedAt":"2013-01-02T23:20:19Z","lastAt":"2013-01-02T23:20:19Z","messageCount":1,"participants":["Torsten Bögershausen"],"isPatch":true,"patchVersion":2,"patchTotal":null},"messages":[{"id":"205897","messageId":"201301030020.31307.tboegi@web.de","threadId":"32514","inReplyTo":null,"subject":"[PATCH V2] test: Add check-non-portable-shell.pl","fromName":"Torsten Bögershausen","fromEmail":"tboegi@web.de","sentAt":"2013-01-02T23:20:19Z","receivedAt":"2013-01-02T23:20:19Z","isPatch":true,"sender":{"key":"tboegi@web.de","avatar":"https://avatars.githubusercontent.com/u/7138363?v=4"},"body":"Add the perl script \"check-non-portable-shell.pl\" to detect non-portable\nshell syntax\n\n\"echo -n\" is an example of a shell command working on Linux,\nbut not on Mac OS X.\n\nThese shell commands are checked and reported as error:\n- \"echo -n\" (printf should be used)\n- \"sed -i\" (Use a temp file)\n- arrays in shell scripts (declare statement)\n- \"which\" (type should be used)\n- \"==\" (bash style for =)\n\n\"make test-lint-shell-syntax\" can be used to run only the check.\n\n\"make\" will run check-non-portable-shell.pl followed by t0000.sh -- t9999.sh\n\n\"TEST_LINT= make\" will only run t0000.sh -- t9999.sh\n\nHelped-By: Jeff King <peff@peff.net>\nSigned-off-by: Torsten Bögershausen <tboegi@web.de>\n---\n\nThanks for reviewing & suggestions\nChanges since v1:\n\nMakefile:\n- \"$TEST_LINT= make\" will disable the check\ncheck-non-portable-shell.pl:\n- Much more perl style (instead of C-Code in perl language)\nHopefuly better commit message\n\n t/Makefile                    |  6 +++++-\n t/check-non-portable-shell.pl | 27 +++++++++++++++++++++++++++\n 2 files changed, 32 insertions(+), 1 deletion(-)\n create mode 100755 t/check-non-portable-shell.pl\n\ndiff --git a/t/Makefile b/t/Makefile\nindex 88e289f..fd239cb 100644\n--- a/t/Makefile\n+++ b/t/Makefile\n@@ -13,6 +13,7 @@ TAR ?= $(TAR)\n RM ?= rm -f\n PROVE ?= prove\n DEFAULT_TEST_TARGET ?= test\n+TEST_LINT ?= test-lint-shell-syntax\n \n # Shell quote;\n SHELL_PATH_SQ = $(subst ','\\'',$(SHELL_PATH))\n@@ -43,7 +44,7 @@ clean-except-prove-cache:\n clean: clean-except-prove-cache\n \t$(RM) .prove\n \n-test-lint: test-lint-duplicates test-lint-executable\n+test-lint: test-lint-duplicates test-lint-executable test-lint-shell-syntax\n \n test-lint-duplicates:\n \t@dups=`echo $(T) | tr ' ' '\\n' | sed 's/-.*//' | sort | uniq -d` && \\\n@@ -55,6 +56,9 @@ test-lint-executable:\n \t\ttest -z \"$$bad\" || { \\\n \t\techo >&2 \"non-executable tests:\" $$bad; exit 1; }\n \n+test-lint-shell-syntax:\n+\t$(PERL_PATH) check-non-portable-shell.pl $(T)\n+\n aggregate-results-and-cleanup: $(T)\n \t$(MAKE) aggregate-results\n \t$(MAKE) clean\ndiff --git a/t/check-non-portable-shell.pl b/t/check-non-portable-shell.pl\nnew file mode 100755\nindex 0000000..49d7291\n--- /dev/null\n+++ b/t/check-non-portable-shell.pl\n@@ -0,0 +1,27 @@\n+#!/usr/bin/perl\n+\n+# Test t0000..t9999.sh for non portable shell scripts\n+# This script can be called with one or more filenames as parameters\n+\n+use strict;\n+use warnings;\n+\n+my $exit_code=0;\n+\n+sub err {\n+\tmy $msg = shift;\n+\tprint \"$ARGV:$.: error: $msg: $_\\n\";\n+\t$exit_code = 1;\n+}\n+\n+while (<>) {\n+\tchomp;\n+\t/^\\s*sed\\s+-i/ and err 'sed -i is not portable';\n+\t/^\\s*echo\\s+-n/ and err 'echo -n is not portable (please use printf)';\n+\t/^\\s*declare\\s+/ and err 'arrays/declare not portable';\n+\t/^\\s*[^#]\\s*which\\s/ and err 'which is not portable (please use type)';\n+\t/test\\s+[^=]*==/ and err '== is not portable (please use =)';\n+\t# this resets our $. for each file\n+\tclose ARGV if eof;\n+}\n+exit $exit_code;\n-- \n1.8.0.197.g5a90748\n"}]}