Browse Source

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>
maint
Eric Sunshine 6 years ago committed by Junio C Hamano
parent
commit
bb4efbc5df
  1. 12
      t/chainlint/block.expect
  2. 15
      t/chainlint/block.test
  3. 9
      t/chainlint/multi-line-nested-command-substitution.expect
  4. 9
      t/chainlint/multi-line-nested-command-substitution.test
  5. 19
      t/chainlint/nested-cuddled-subshell.expect
  6. 31
      t/chainlint/nested-cuddled-subshell.test
  7. 5
      t/chainlint/nested-here-doc.expect
  8. 23
      t/chainlint/nested-here-doc.test
  9. 11
      t/chainlint/nested-subshell-comment.expect
  10. 13
      t/chainlint/nested-subshell-comment.test
  11. 12
      t/chainlint/nested-subshell.expect
  12. 14
      t/chainlint/nested-subshell.test

12
t/chainlint/block.expect

@ -0,0 +1,12 @@ @@ -0,0 +1,12 @@
(
foo &&
{
echo a
echo b
} &&
bar &&
{
echo c
?!AMP?! }
baz
>)

15
t/chainlint/block.test

@ -0,0 +1,15 @@ @@ -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
)

9
t/chainlint/multi-line-nested-command-substitution.expect

@ -0,0 +1,9 @@ @@ -0,0 +1,9 @@
(
foo &&
x=$(
echo bar |
cat
>> ) &&
echo ok
>) |
sort

9
t/chainlint/multi-line-nested-command-substitution.test

@ -0,0 +1,9 @@ @@ -0,0 +1,9 @@
(
foo &&
x=$(
echo bar |
cat
) &&
echo ok
) |
sort

19
t/chainlint/nested-cuddled-subshell.expect

@ -0,0 +1,19 @@ @@ -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

@ -0,0 +1,31 @@ @@ -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

@ -0,0 +1,5 @@ @@ -0,0 +1,5 @@
(
cat &&
?!AMP?! cat
foobar
>)

23
t/chainlint/nested-here-doc.test

@ -0,0 +1,23 @@ @@ -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

@ -0,0 +1,11 @@ @@ -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

@ -0,0 +1,13 @@ @@ -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

@ -0,0 +1,12 @@ @@ -0,0 +1,12 @@
(
cd foo &&
(
echo a &&
echo b
>> ) >file &&
cd foo &&
(
echo a
echo b
>> ) >file
>)

14
t/chainlint/nested-subshell.test

@ -0,0 +1,14 @@ @@ -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…
Cancel
Save