t/chainlint: add chainlint "one-liner" 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 90a880393a5fd7cff9842d553786949c7cafb48b
6 files changed +71
t/chainlint/negated-one-liner.expect new
+5
@@ -0,0 +1,5 @@
1 +! (foo && bar) &&
2 +! (foo && bar) >baz &&
3 +
4 +?!SEMI?!! (foo; bar) &&
5 +?!SEMI?!! (foo; bar) >baz
t/chainlint/negated-one-liner.test new
+7
@@ -0,0 +1,7 @@
1 +# LINT: top-level one-liner subshell
2 +! (foo && bar) &&
3 +! (foo && bar) >baz &&
4 +
5 +# LINT: top-level one-liner subshell missing internal "&&"
6 +! (foo; bar) &&
7 +! (foo; bar) >baz
t/chainlint/one-liner.expect new
+9
@@ -0,0 +1,9 @@
1 +(foo && bar) &&
2 +(foo && bar) |
3 +(foo && bar) >baz &&
4 +
5 +?!SEMI?!(foo; bar) &&
6 +?!SEMI?!(foo; bar) |
7 +?!SEMI?!(foo; bar) >baz
8 +
9 +(foo "bar; baz")
t/chainlint/one-liner.test new
+12
@@ -0,0 +1,12 @@
1 +# LINT: top-level one-liner subshell
2 +(foo && bar) &&
3 +(foo && bar) |
4 +(foo && bar) >baz &&
5 +
6 +# LINT: top-level one-liner subshell missing internal "&&"
7 +(foo; bar) &&
8 +(foo; bar) |
9 +(foo; bar) >baz
10 +
11 +# LINT: ";" in string not misinterpreted as broken &&-chain
12 +(foo "bar; baz")
t/chainlint/subshell-one-liner.expect new
+14
@@ -0,0 +1,14 @@
1 +(
2 + (foo && bar) &&
3 + (foo && bar) |
4 + (foo && bar) >baz &&
5 +?!SEMI?! (foo; bar) &&
6 +?!SEMI?! (foo; bar) |
7 +?!SEMI?! (foo; bar) >baz &&
8 + (foo || exit 1) &&
9 + (foo || exit 1) |
10 + (foo || exit 1) >baz &&
11 +?!AMP?! (foo && bar)
12 +?!AMP?!?!SEMI?! (foo && bar; baz)
13 + foobar
14 +>)
t/chainlint/subshell-one-liner.test new
+24
@@ -0,0 +1,24 @@
1 +(
2 +# LINT: nested one-liner subshell
3 + (foo && bar) &&
4 + (foo && bar) |
5 + (foo && bar) >baz &&
6 +
7 +# LINT: nested one-liner subshell missing internal "&&"
8 + (foo; bar) &&
9 + (foo; bar) |
10 + (foo; bar) >baz &&
11 +
12 +# LINT: nested one-liner subshell with "|| exit"
13 + (foo || exit 1) &&
14 + (foo || exit 1) |
15 + (foo || exit 1) >baz &&
16 +
17 +# LINT: nested one-liner subshell lacking ending "&&"
18 + (foo && bar)
19 +
20 +# LINT: nested one-liner subshell missing internal "&&" and lacking ending "&&"
21 + (foo && bar; baz)
22 +
23 + foobar
24 +)