Skip to content

Commit d1cd220

Browse files
committed
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
2 parents 53cae9e + a0a6301 commit d1cd220

File tree

3 files changed

+32
-7
lines changed

3 files changed

+32
-7
lines changed

t/check-non-portable-shell.pl

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,22 +7,43 @@
77
use warnings;
88

99
my $exit_code=0;
10+
my %func;
1011

1112
sub err {
1213
my $msg = shift;
14+
s/^\s+//;
15+
s/\s+$//;
16+
s/\s+/ /g;
1317
print "$ARGV:$.: error: $msg: $_\n";
1418
$exit_code = 1;
1519
}
1620

21+
# glean names of shell functions
22+
for my $i (@ARGV) {
23+
open(my $f, '<', $i) or die "$0: $i: $!\n";
24+
while (<$f>) {
25+
$func{$1} = 1 if /^\s*(\w+)\s*\(\)\s*{\s*$/;
26+
}
27+
close $f;
28+
}
29+
1730
while (<>) {
1831
chomp;
32+
# stitch together incomplete lines (those ending with "\")
33+
while (s/\\$//) {
34+
$_ .= readline;
35+
chomp;
36+
}
37+
1938
/\bsed\s+-i/ and err 'sed -i is not portable';
20-
/\becho\s+-[neE]/ and err 'echo with option is not portable (please use printf)';
39+
/\becho\s+-[neE]/ and err 'echo with option is not portable (use printf)';
2140
/^\s*declare\s+/ and err 'arrays/declare not portable';
22-
/^\s*[^#]\s*which\s/ and err 'which is not portable (please use type)';
23-
/\btest\s+[^=]*==/ and err '"test a == b" is not portable (please use =)';
24-
/\bwc -l.*"\s*=/ and err '`"$(wc -l)"` is not portable (please use test_line_count)';
25-
/\bexport\s+[A-Za-z0-9_]*=/ and err '"export FOO=bar" is not portable (please use FOO=bar && export FOO)';
41+
/^\s*[^#]\s*which\s/ and err 'which is not portable (use type)';
42+
/\btest\s+[^=]*==/ and err '"test a == b" is not portable (use =)';
43+
/\bwc -l.*"\s*=/ and err '`"$(wc -l)"` is not portable (use test_line_count)';
44+
/\bexport\s+[A-Za-z0-9_]*=/ and err '"export FOO=bar" is not portable (use FOO=bar && export FOO)';
45+
/^\s*([A-Z0-9_]+=(\w+|(["']).*?\3)\s+)+(\w+)/ and exists($func{$4}) and
46+
err '"FOO=bar shell_func" assignment extends beyond "shell_func"';
2647
# this resets our $. for each file
2748
close ARGV if eof;
2849
}

t/t6046-merge-skip-unneeded-updates.sh

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -366,7 +366,9 @@ test_expect_success '2c-check: Modify b & add c VS rename b->c' '
366366
367367
git checkout A^0 &&
368368
369-
GIT_MERGE_VERBOSITY=3 test_must_fail git merge -s recursive B^0 >out 2>err &&
369+
GIT_MERGE_VERBOSITY=3 &&
370+
export GIT_MERGE_VERBOSITY &&
371+
test_must_fail git merge -s recursive B^0 >out 2>err &&
370372
371373
test_i18ngrep "CONFLICT (rename/add): Rename b->c" out &&
372374
test_i18ngrep ! "Skipped c" out &&

t/t9833-errors.sh

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,9 @@ test_expect_success 'error handling' '
2626
) &&
2727
p4 passwd -P newpassword &&
2828
(
29-
P4PASSWD=badpassword test_must_fail git p4 clone //depot/foo 2>errmsg &&
29+
P4PASSWD=badpassword &&
30+
export P4PASSWD &&
31+
test_must_fail git p4 clone //depot/foo 2>errmsg &&
3032
grep -q "failure accessing depot.*P4PASSWD" errmsg
3133
)
3234
'

0 commit comments

Comments
 (0)