Skip to content

Commit 5238710

Browse files
sunshinecogitster
authored andcommitted
t/chainlint: add chainlint "basic" 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 8033944 commit 5238710

16 files changed

+206
-0
lines changed
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
(
2+
foo &&
3+
bar=$((42 + 1)) &&
4+
baz
5+
>) &&
6+
(
7+
?!AMP?! bar=$((42 + 1))
8+
baz
9+
>)

t/chainlint/arithmetic-expansion.test

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
(
2+
foo &&
3+
# LINT: closing ")" of $((...)) not misinterpreted as subshell-closing ")"
4+
bar=$((42 + 1)) &&
5+
baz
6+
) &&
7+
(
8+
# LINT: missing "&&" on $((...))
9+
bar=$((42 + 1))
10+
baz
11+
)

t/chainlint/broken-chain.expect

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
(
2+
foo &&
3+
?!AMP?! bar
4+
baz &&
5+
wop
6+
>)

t/chainlint/broken-chain.test

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
(
2+
foo &&
3+
# LINT: missing "&&" from 'bar'
4+
bar
5+
baz &&
6+
# LINT: final statement before closing ")" legitimately lacks "&&"
7+
wop
8+
)

t/chainlint/close-subshell.expect

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
(
2+
foo
3+
>) &&
4+
(
5+
bar
6+
>) >out &&
7+
(
8+
baz
9+
>) 2>err &&
10+
(
11+
boo
12+
>) <input &&
13+
(
14+
bip
15+
>) | wuzzle &&
16+
(
17+
bop
18+
>) | fazz fozz &&
19+
(
20+
bup
21+
>) |
22+
fuzzle &&
23+
(
24+
yop
25+
>)

t/chainlint/close-subshell.test

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# LINT: closing ")" with various decorations ("&&", ">", "|", etc.)
2+
(
3+
foo
4+
) &&
5+
(
6+
bar
7+
) >out &&
8+
(
9+
baz
10+
) 2>err &&
11+
(
12+
boo
13+
) <input &&
14+
(
15+
bip
16+
) | wuzzle &&
17+
(
18+
bop
19+
) | fazz \
20+
fozz &&
21+
(
22+
bup
23+
) |
24+
fuzzle &&
25+
(
26+
yop
27+
)
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
(
2+
foo &&
3+
bar=$(gobble) &&
4+
baz
5+
>) &&
6+
(
7+
?!AMP?! bar=$(gobble blocks)
8+
baz
9+
>)

t/chainlint/command-substitution.test

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
(
2+
foo &&
3+
# LINT: closing ")" of $(...) not misinterpreted as subshell-closing ")"
4+
bar=$(gobble) &&
5+
baz
6+
) &&
7+
(
8+
# LINT: missing "&&" on $(...)
9+
bar=$(gobble blocks)
10+
baz
11+
)

t/chainlint/exit-subshell.expect

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
(
2+
foo || exit 1
3+
bar &&
4+
baz
5+
>)

t/chainlint/exit-subshell.test

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
(
2+
# LINT: "|| exit {n}" valid subshell escape without hurting &&-chain
3+
foo || exit 1
4+
bar &&
5+
baz
6+
)

0 commit comments

Comments
 (0)