t/chainlint: add chainlint "cuddled" 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 24c86180649baec2dde4d5e5b6350d048f5d6bb3
6 files changed +70
t/chainlint/cuddled-if-then-else.expect new
+7
@@ -0,0 +1,7 @@
1 +(
2 +if test -z ""; then
3 + echo empty
4 + else
5 + echo bizzy
6 +> fi) &&
7 +echo foobar
t/chainlint/cuddled-if-then-else.test new
+7
@@ -0,0 +1,7 @@
1 +# LINT: 'if' cuddled with "(" and ")"; indented with spaces, not tabs
2 +(if test -z ""; then
3 + echo empty
4 + else
5 + echo bizzy
6 + fi) &&
7 +echo foobar
t/chainlint/cuddled-loop.expect new
+5
@@ -0,0 +1,5 @@
1 +(
2 + while read x
3 + do foobar bop || exit 1
4 +> done <file ) &&
5 +outside subshell
t/chainlint/cuddled-loop.test new
+7
@@ -0,0 +1,7 @@
1 +# LINT: 'while' loop cuddled with "(" and ")", with embedded (allowed)
2 +# LINT: "|| exit {n}" to exit loop early, and using redirection "<" to feed
3 +# LINT: loop; indented with spaces, not tabs
4 +( while read x
5 + do foobar bop || exit 1
6 + done <file ) &&
7 +outside subshell
t/chainlint/cuddled.expect new
+21
@@ -0,0 +1,21 @@
1 +(
2 +cd foo &&
3 + bar
4 +>) &&
5 +
6 +(
7 +?!AMP?!cd foo
8 + bar
9 +>) &&
10 +
11 +(
12 + cd foo &&
13 +> bar) &&
14 +
15 +(
16 +cd foo &&
17 +> bar) &&
18 +
19 +(
20 +?!AMP?!cd foo
21 +> bar)
t/chainlint/cuddled.test new
+23
@@ -0,0 +1,23 @@
1 +# LINT: first subshell statement cuddled with opening "("; for implementation
2 +# LINT: simplicity, "(..." is split into two lines, "(" and "..."
3 +(cd foo &&
4 + bar
5 +) &&
6 +
7 +# LINT: same with missing "&&"
8 +(cd foo
9 + bar
10 +) &&
11 +
12 +# LINT: closing ")" cuddled with final subshell statement
13 +(
14 + cd foo &&
15 + bar) &&
16 +
17 +# LINT: "(" and ")" cuddled with first and final subshell statements
18 +(cd foo &&
19 + bar) &&
20 +
21 +# LINT: same with missing "&&"
22 +(cd foo
23 + bar)