t/chainlint: add chainlint "complex" 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 1f718b0b78f4fe1b6686c6bbae4ec4859d240070
8 files changed +82
t/chainlint/close-nested-and-parent-together.expect new
+4
@@ -0,0 +1,4 @@
1 +(
2 +cd foo &&
3 + (bar &&
4 +>>> baz))
t/chainlint/close-nested-and-parent-together.test new
+3
@@ -0,0 +1,3 @@
1 +(cd foo &&
2 + (bar &&
3 + baz))
t/chainlint/complex-if-in-cuddled-loop.expect new
+10
@@ -0,0 +1,10 @@
1 +(
2 +for i in a b c; do
3 + if test "$(echo $(waffle bat))" = "eleventeen" &&
4 + test "$x" = "$y"; then
5 + :
6 + else
7 + echo >file
8 + fi
9 +> done) &&
10 +test ! -f file
t/chainlint/complex-if-in-cuddled-loop.test new
+11
@@ -0,0 +1,11 @@
1 +# LINT: 'for' loop cuddled with "(" and ")" and nested 'if' with complex
2 +# LINT: multi-line condition; indented with spaces, not tabs
3 +(for i in a b c; do
4 + if test "$(echo $(waffle bat))" = "eleventeen" &&
5 + test "$x" = "$y"; then
6 + :
7 + else
8 + echo >file
9 + fi
10 + done) &&
11 +test ! -f file
t/chainlint/if-in-loop.expect new
+12
@@ -0,0 +1,12 @@
1 +(
2 + for i in a b c
3 + do
4 + if false
5 + then
6 +?!AMP?! echo "err"
7 + exit 1
8 +?!AMP?! fi
9 + foo
10 +?!AMP?! done
11 + bar
12 +>)
t/chainlint/if-in-loop.test new
+15
@@ -0,0 +1,15 @@
1 +(
2 + for i in a b c
3 + do
4 + if false
5 + then
6 +# LINT: missing "&&" on 'echo'
7 + echo "err"
8 + exit 1
9 +# LINT: missing "&&" on 'fi'
10 + fi
11 + foo
12 +# LINT: missing "&&" on 'done'
13 + done
14 + bar
15 +)
t/chainlint/loop-in-if.expect new
+12
@@ -0,0 +1,12 @@
1 +(
2 + if true
3 + then
4 + while true
5 + do
6 +?!AMP?! echo "pop"
7 + echo "glup"
8 +?!AMP?! done
9 + foo
10 +?!AMP?! fi
11 + bar
12 +>)
t/chainlint/loop-in-if.test new
+15
@@ -0,0 +1,15 @@
1 +(
2 + if true
3 + then
4 + while true
5 + do
6 +# LINT: missing "&&" on 'echo'
7 + echo "pop"
8 + echo "glup"
9 +# LINT: missing "&&" on 'done'
10 + done
11 + foo
12 +# LINT: missing "&&" on 'fi'
13 + fi
14 + bar
15 +)