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>

Eric Sunshine committed Jul 11, 2018 at 02:46 UTC bb4efbc5df9d0c96392dd14fc3ab6164949a2f52
12 files changed +173
t/chainlint/block.expect new
+12
@@ -0,0 +1,12 @@
1 +(
2 + foo &&
3 + {
4 + echo a
5 + echo b
6 + } &&
7 + bar &&
8 + {
9 + echo c
10 +?!AMP?! }
11 + baz
12 +>)
t/chainlint/block.test new
+15
@@ -0,0 +1,15 @@
1 +(
2 +# LINT: missing "&&" in block not currently detected (for consistency with
3 +# LINT: --chain-lint at top level and to provide escape hatch if needed)
4 + foo &&
5 + {
6 + echo a
7 + echo b
8 + } &&
9 + bar &&
10 +# LINT: missing "&&" at closing "}"
11 + {
12 + echo c
13 + }
14 + baz
15 +)
t/chainlint/multi-line-nested-command-substitution.expect new
+9
@@ -0,0 +1,9 @@
1 +(
2 + foo &&
3 + x=$(
4 + echo bar |
5 + cat
6 +>> ) &&
7 + echo ok
8 +>) |
9 +sort
t/chainlint/multi-line-nested-command-substitution.test new
+9
@@ -0,0 +1,9 @@
1 +(
2 + foo &&
3 + x=$(
4 + echo bar |
5 + cat
6 + ) &&
7 + echo ok
8 +) |
9 +sort
t/chainlint/nested-cuddled-subshell.expect new
+19
@@ -0,0 +1,19 @@
1 +(
2 + (cd foo &&
3 + bar
4 +>> ) &&
5 + (cd foo &&
6 + bar
7 +?!AMP?!>> )
8 + (
9 + cd foo &&
10 +>> bar) &&
11 + (
12 + cd foo &&
13 +?!AMP?!>> bar)
14 + (cd foo &&
15 +>> bar) &&
16 + (cd foo &&
17 +?!AMP?!>> bar)
18 + foobar
19 +>)
t/chainlint/nested-cuddled-subshell.test new
+31
@@ -0,0 +1,31 @@
1 +(
2 +# LINT: opening "(" cuddled with first nested subshell statement
3 + (cd foo &&
4 + bar
5 + ) &&
6 +
7 +# LINT: same but "&&" missing
8 + (cd foo &&
9 + bar
10 + )
11 +
12 +# LINT: closing ")" cuddled with final nested subshell statement
13 + (
14 + cd foo &&
15 + bar) &&
16 +
17 +# LINT: same but "&&" missing
18 + (
19 + cd foo &&
20 + bar)
21 +
22 +# LINT: "(" and ")" cuddled with first and final subshell statements
23 + (cd foo &&
24 + bar) &&
25 +
26 +# LINT: same but "&&" missing
27 + (cd foo &&
28 + bar)
29 +
30 + foobar
31 +)
t/chainlint/nested-here-doc.expect new
+5
@@ -0,0 +1,5 @@
1 +(
2 + cat &&
3 +?!AMP?! cat
4 + foobar
5 +>)
t/chainlint/nested-here-doc.test new
+23
@@ -0,0 +1,23 @@
1 +(
2 +# LINT: inner "EOF" not misintrepreted as closing INPUT_END here-doc
3 + cat <<-\INPUT_END &&
4 + fish are mice
5 + but geese go slow
6 + data <<EOF
7 + perl is lerp
8 + and nothing else
9 + EOF
10 + toink
11 + INPUT_END
12 +
13 +# LINT: same but missing "&&"
14 + cat <<-\EOT
15 + text goes here
16 + data <<EOF
17 + data goes here
18 + EOF
19 + more test here
20 + EOT
21 +
22 + foobar
23 +)
t/chainlint/nested-subshell-comment.expect new
+11
@@ -0,0 +1,11 @@
1 +(
2 + foo &&
3 + (
4 + bar &&
5 + # bottles wobble while fiddles gobble
6 + # minor numbers of cows (or do they?)
7 + baz &&
8 + snaff
9 +?!AMP?!>> )
10 + fuzzy
11 +>)
t/chainlint/nested-subshell-comment.test new
+13
@@ -0,0 +1,13 @@
1 +(
2 + foo &&
3 + (
4 + bar &&
5 +# LINT: ")" in comment in nested subshell not misinterpreted as closing ")"
6 + # bottles wobble while fiddles gobble
7 + # minor numbers of cows (or do they?)
8 + baz &&
9 + snaff
10 +# LINT: missing "&&" on ')'
11 + )
12 + fuzzy
13 +)
t/chainlint/nested-subshell.expect new
+12
@@ -0,0 +1,12 @@
1 +(
2 + cd foo &&
3 + (
4 + echo a &&
5 + echo b
6 +>> ) >file &&
7 + cd foo &&
8 + (
9 + echo a
10 + echo b
11 +>> ) >file
12 +>)
t/chainlint/nested-subshell.test new
+14
@@ -0,0 +1,14 @@
1 +(
2 + cd foo &&
3 + (
4 + echo a &&
5 + echo b
6 + ) >file &&
7 +
8 + cd foo &&
9 + (
10 +# LINT: nested multi-line subshell not presently checked for missing "&&"
11 + echo a
12 + echo b
13 + ) >file
14 +)