diff options
author | Junio C Hamano <gitster@pobox.com> | 2018-07-24 14:50:50 -0700 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2018-07-24 14:50:50 -0700 |
commit | d1cd2205c28fdf90095097e3270d0c52db90080a (patch) | |
tree | eb4cc1fb3d4e71b9a06327774faafd3ede6b7eda | |
parent | Merge branch 'wc/find-commit-with-pattern-on-detached-head' (diff) | |
parent | t/check-non-portable-shell: detect "FOO=bar shell_func" (diff) | |
download | tgif-d1cd2205c28fdf90095097e3270d0c52db90080a.tar.xz |
Merge branch 'es/test-lint-one-shot-export'
Look for broken use of "VAR=VAL shell_func" in test scripts as part
of test-lint.
* es/test-lint-one-shot-export:
t/check-non-portable-shell: detect "FOO=bar shell_func"
t/check-non-portable-shell: make error messages more compact
t/check-non-portable-shell: stop being so polite
t6046/t9833: fix use of "VAR=VAL cmd" with a shell function
-rwxr-xr-x | t/check-non-portable-shell.pl | 31 | ||||
-rwxr-xr-x | t/t6046-merge-skip-unneeded-updates.sh | 4 | ||||
-rwxr-xr-x | t/t9833-errors.sh | 4 |
3 files changed, 32 insertions, 7 deletions
diff --git a/t/check-non-portable-shell.pl b/t/check-non-portable-shell.pl index e07f028437..d5823f71d8 100755 --- a/t/check-non-portable-shell.pl +++ b/t/check-non-portable-shell.pl @@ -7,22 +7,43 @@ use strict; use warnings; my $exit_code=0; +my %func; sub err { my $msg = shift; + s/^\s+//; + s/\s+$//; + s/\s+/ /g; print "$ARGV:$.: error: $msg: $_\n"; $exit_code = 1; } +# glean names of shell functions +for my $i (@ARGV) { + open(my $f, '<', $i) or die "$0: $i: $!\n"; + while (<$f>) { + $func{$1} = 1 if /^\s*(\w+)\s*\(\)\s*{\s*$/; + } + close $f; +} + while (<>) { chomp; + # stitch together incomplete lines (those ending with "\") + while (s/\\$//) { + $_ .= readline; + chomp; + } + /\bsed\s+-i/ and err 'sed -i is not portable'; - /\becho\s+-[neE]/ and err 'echo with option is not portable (please use printf)'; + /\becho\s+-[neE]/ and err 'echo with option is not portable (use printf)'; /^\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)'; + /^\s*[^#]\s*which\s/ and err 'which is not portable (use type)'; + /\btest\s+[^=]*==/ and err '"test a == b" is not portable (use =)'; + /\bwc -l.*"\s*=/ and err '`"$(wc -l)"` is not portable (use test_line_count)'; + /\bexport\s+[A-Za-z0-9_]*=/ and err '"export FOO=bar" is not portable (use FOO=bar && export FOO)'; + /^\s*([A-Z0-9_]+=(\w+|(["']).*?\3)\s+)+(\w+)/ and exists($func{$4}) and + err '"FOO=bar shell_func" assignment extends beyond "shell_func"'; # this resets our $. for each file close ARGV if eof; } diff --git a/t/t6046-merge-skip-unneeded-updates.sh b/t/t6046-merge-skip-unneeded-updates.sh index fcefffcaec..38e24f787c 100755 --- a/t/t6046-merge-skip-unneeded-updates.sh +++ b/t/t6046-merge-skip-unneeded-updates.sh @@ -366,7 +366,9 @@ test_expect_success '2c-check: Modify b & add c VS rename b->c' ' git checkout A^0 && - GIT_MERGE_VERBOSITY=3 test_must_fail git merge -s recursive B^0 >out 2>err && + GIT_MERGE_VERBOSITY=3 && + export GIT_MERGE_VERBOSITY && + test_must_fail git merge -s recursive B^0 >out 2>err && test_i18ngrep "CONFLICT (rename/add): Rename b->c" out && test_i18ngrep ! "Skipped c" out && diff --git a/t/t9833-errors.sh b/t/t9833-errors.sh index 9ba892de7a..277d347012 100755 --- a/t/t9833-errors.sh +++ b/t/t9833-errors.sh @@ -26,7 +26,9 @@ test_expect_success 'error handling' ' ) && p4 passwd -P newpassword && ( - P4PASSWD=badpassword test_must_fail git p4 clone //depot/foo 2>errmsg && + P4PASSWD=badpassword && + export P4PASSWD && + test_must_fail git p4 clone //depot/foo 2>errmsg && grep -q "failure accessing depot.*P4PASSWD" errmsg ) ' |