t/chainlint: add chainlint "nested subshell" test cases
The --chain-lint option uses heuristics and knowledge of shell syntax to detect broken &&-chains in subshells by pure textual inspection. The heuristics handle a range of stylistic variations in existing tests (evolved over the years), however, they are still best-guesses. As such, it is possible for future changes to accidentally break assumptions upon which the heuristics are based. Protect against this possibility by adding tests which check the linter itself for correctness. In addition to protecting against regressions, these tests help document (for humans) expected behavior, which is important since the linter's implementation language ('sed') does not necessarily lend itself to easy comprehension. Signed-off-by: Eric Sunshine <sunshine@sunshineco.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
parent
90a880393a
commit
bb4efbc5df
12
t/chainlint/block.expect
Normal file
12
t/chainlint/block.expect
Normal file
@ -0,0 +1,12 @@
|
||||
(
|
||||
foo &&
|
||||
{
|
||||
echo a
|
||||
echo b
|
||||
} &&
|
||||
bar &&
|
||||
{
|
||||
echo c
|
||||
?!AMP?! }
|
||||
baz
|
||||
>)
|
15
t/chainlint/block.test
Normal file
15
t/chainlint/block.test
Normal file
@ -0,0 +1,15 @@
|
||||
(
|
||||
# LINT: missing "&&" in block not currently detected (for consistency with
|
||||
# LINT: --chain-lint at top level and to provide escape hatch if needed)
|
||||
foo &&
|
||||
{
|
||||
echo a
|
||||
echo b
|
||||
} &&
|
||||
bar &&
|
||||
# LINT: missing "&&" at closing "}"
|
||||
{
|
||||
echo c
|
||||
}
|
||||
baz
|
||||
)
|
@ -0,0 +1,9 @@
|
||||
(
|
||||
foo &&
|
||||
x=$(
|
||||
echo bar |
|
||||
cat
|
||||
>> ) &&
|
||||
echo ok
|
||||
>) |
|
||||
sort
|
9
t/chainlint/multi-line-nested-command-substitution.test
Normal file
9
t/chainlint/multi-line-nested-command-substitution.test
Normal file
@ -0,0 +1,9 @@
|
||||
(
|
||||
foo &&
|
||||
x=$(
|
||||
echo bar |
|
||||
cat
|
||||
) &&
|
||||
echo ok
|
||||
) |
|
||||
sort
|
19
t/chainlint/nested-cuddled-subshell.expect
Normal file
19
t/chainlint/nested-cuddled-subshell.expect
Normal file
@ -0,0 +1,19 @@
|
||||
(
|
||||
(cd foo &&
|
||||
bar
|
||||
>> ) &&
|
||||
(cd foo &&
|
||||
bar
|
||||
?!AMP?!>> )
|
||||
(
|
||||
cd foo &&
|
||||
>> bar) &&
|
||||
(
|
||||
cd foo &&
|
||||
?!AMP?!>> bar)
|
||||
(cd foo &&
|
||||
>> bar) &&
|
||||
(cd foo &&
|
||||
?!AMP?!>> bar)
|
||||
foobar
|
||||
>)
|
31
t/chainlint/nested-cuddled-subshell.test
Normal file
31
t/chainlint/nested-cuddled-subshell.test
Normal file
@ -0,0 +1,31 @@
|
||||
(
|
||||
# LINT: opening "(" cuddled with first nested subshell statement
|
||||
(cd foo &&
|
||||
bar
|
||||
) &&
|
||||
|
||||
# LINT: same but "&&" missing
|
||||
(cd foo &&
|
||||
bar
|
||||
)
|
||||
|
||||
# LINT: closing ")" cuddled with final nested subshell statement
|
||||
(
|
||||
cd foo &&
|
||||
bar) &&
|
||||
|
||||
# LINT: same but "&&" missing
|
||||
(
|
||||
cd foo &&
|
||||
bar)
|
||||
|
||||
# LINT: "(" and ")" cuddled with first and final subshell statements
|
||||
(cd foo &&
|
||||
bar) &&
|
||||
|
||||
# LINT: same but "&&" missing
|
||||
(cd foo &&
|
||||
bar)
|
||||
|
||||
foobar
|
||||
)
|
5
t/chainlint/nested-here-doc.expect
Normal file
5
t/chainlint/nested-here-doc.expect
Normal file
@ -0,0 +1,5 @@
|
||||
(
|
||||
cat &&
|
||||
?!AMP?! cat
|
||||
foobar
|
||||
>)
|
23
t/chainlint/nested-here-doc.test
Normal file
23
t/chainlint/nested-here-doc.test
Normal file
@ -0,0 +1,23 @@
|
||||
(
|
||||
# LINT: inner "EOF" not misintrepreted as closing INPUT_END here-doc
|
||||
cat <<-\INPUT_END &&
|
||||
fish are mice
|
||||
but geese go slow
|
||||
data <<EOF
|
||||
perl is lerp
|
||||
and nothing else
|
||||
EOF
|
||||
toink
|
||||
INPUT_END
|
||||
|
||||
# LINT: same but missing "&&"
|
||||
cat <<-\EOT
|
||||
text goes here
|
||||
data <<EOF
|
||||
data goes here
|
||||
EOF
|
||||
more test here
|
||||
EOT
|
||||
|
||||
foobar
|
||||
)
|
11
t/chainlint/nested-subshell-comment.expect
Normal file
11
t/chainlint/nested-subshell-comment.expect
Normal file
@ -0,0 +1,11 @@
|
||||
(
|
||||
foo &&
|
||||
(
|
||||
bar &&
|
||||
# bottles wobble while fiddles gobble
|
||||
# minor numbers of cows (or do they?)
|
||||
baz &&
|
||||
snaff
|
||||
?!AMP?!>> )
|
||||
fuzzy
|
||||
>)
|
13
t/chainlint/nested-subshell-comment.test
Normal file
13
t/chainlint/nested-subshell-comment.test
Normal file
@ -0,0 +1,13 @@
|
||||
(
|
||||
foo &&
|
||||
(
|
||||
bar &&
|
||||
# LINT: ")" in comment in nested subshell not misinterpreted as closing ")"
|
||||
# bottles wobble while fiddles gobble
|
||||
# minor numbers of cows (or do they?)
|
||||
baz &&
|
||||
snaff
|
||||
# LINT: missing "&&" on ')'
|
||||
)
|
||||
fuzzy
|
||||
)
|
12
t/chainlint/nested-subshell.expect
Normal file
12
t/chainlint/nested-subshell.expect
Normal file
@ -0,0 +1,12 @@
|
||||
(
|
||||
cd foo &&
|
||||
(
|
||||
echo a &&
|
||||
echo b
|
||||
>> ) >file &&
|
||||
cd foo &&
|
||||
(
|
||||
echo a
|
||||
echo b
|
||||
>> ) >file
|
||||
>)
|
14
t/chainlint/nested-subshell.test
Normal file
14
t/chainlint/nested-subshell.test
Normal file
@ -0,0 +1,14 @@
|
||||
(
|
||||
cd foo &&
|
||||
(
|
||||
echo a &&
|
||||
echo b
|
||||
) >file &&
|
||||
|
||||
cd foo &&
|
||||
(
|
||||
# LINT: nested multi-line subshell not presently checked for missing "&&"
|
||||
echo a
|
||||
echo b
|
||||
) >file
|
||||
)
|
Loading…
Reference in New Issue
Block a user