Skip to content

Commit c1c79b3

Browse files
sunshinecogitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent ab4c860 commit c1c79b3

File tree

6 files changed

+71
-0
lines changed

6 files changed

+71
-0
lines changed

t/chainlint/negated-one-liner.expect

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
)

0 commit comments

Comments
 (0)