Skip to content

Commit 24c8618

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

File tree

6 files changed

+70
-0
lines changed

6 files changed

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

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

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

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

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

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

0 commit comments

Comments
 (0)