Skip to content

Commit 1f718b0

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

8 files changed

+82
-0
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
(
2+
cd foo &&
3+
(bar &&
4+
>>> baz))
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
(cd foo &&
2+
(bar &&
3+
baz))
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

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

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

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

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

0 commit comments

Comments
 (0)