Skip to content

Commit ab4c860

Browse files
sunshinecogitster
authored andcommitted
t/chainlint: add chainlint "whitespace" 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 e0ada15 commit ab4c860

12 files changed

+113
-0
lines changed

t/chainlint/blank-line.expect

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
(
2+
nothing &&
3+
something
4+
>)

t/chainlint/blank-line.test

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
(
2+
3+
nothing &&
4+
5+
something
6+
# LINT: swallow blank lines since final _statement_ before subshell end is
7+
# LINT: significant to "&&"-check, not final _line_ (which might be blank)
8+
9+
10+
)

t/chainlint/comment.expect

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
(
2+
nothing &&
3+
something
4+
>)

t/chainlint/comment.test

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
(
2+
# LINT: swallow comment lines
3+
# comment 1
4+
nothing &&
5+
# comment 2
6+
something
7+
# LINT: swallow comment lines since final _statement_ before subshell end is
8+
# LINT: significant to "&&"-check, not final _line_ (which might be comment)
9+
# comment 3
10+
# comment 4
11+
)

t/chainlint/here-doc.expect

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
boodle wobba gorgo snoot wafta snurb &&
2+
3+
horticulture

t/chainlint/here-doc.test

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# LINT: stitch together incomplete \-ending lines
2+
# LINT: swallow here-doc to avoid false positives in content
3+
boodle wobba \
4+
gorgo snoot \
5+
wafta snurb <<EOF &&
6+
quoth the raven,
7+
nevermore...
8+
EOF
9+
10+
# LINT: swallow here-doc (EOF is last line of test)
11+
horticulture <<\EOF
12+
gomez
13+
morticia
14+
wednesday
15+
pugsly
16+
EOF

t/chainlint/incomplete-line.expect

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
line 1 line 2 line 3 line 4 &&
2+
(
3+
line 5 line 6 line 7 line 8
4+
>)

t/chainlint/incomplete-line.test

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# LINT: stitch together all incomplete \-ending lines
2+
line 1 \
3+
line 2 \
4+
line 3 \
5+
line 4 &&
6+
(
7+
# LINT: stitch together all incomplete \-ending lines (subshell)
8+
line 5 \
9+
line 6 \
10+
line 7 \
11+
line 8
12+
)

t/chainlint/inline-comment.expect

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
(
2+
foobar &&
3+
?!AMP?! barfoo
4+
flibble "not a # comment"
5+
>) &&
6+
7+
(
8+
cd foo &&
9+
> flibble "not a # comment")

t/chainlint/inline-comment.test

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
(
2+
# LINT: swallow inline comment (leaving command intact)
3+
foobar && # comment 1
4+
# LINT: mispositioned "&&" (correctly) swallowed with comment
5+
barfoo # wrong position for &&
6+
# LINT: "#" in string not misinterpreted as comment
7+
flibble "not a # comment"
8+
) &&
9+
10+
# LINT: "#" in string in cuddled subshell not misinterpreted as comment
11+
(cd foo &&
12+
flibble "not a # comment")

t/chainlint/subshell-here-doc.expect

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
(
2+
echo wobba gorgo snoot wafta snurb &&
3+
?!AMP?! cat >bip
4+
echo >bop
5+
>)

t/chainlint/subshell-here-doc.test

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
(
2+
# LINT: stitch together incomplete \-ending lines
3+
# LINT: swallow here-doc to avoid false positives in content
4+
echo wobba \
5+
gorgo snoot \
6+
wafta snurb <<-EOF &&
7+
quoth the raven,
8+
nevermore...
9+
EOF
10+
11+
# LINT: missing "&&" on 'cat'
12+
cat <<EOF >bip
13+
fish fly high
14+
EOF
15+
16+
# LINT: swallow here-doc (EOF is last line of subshell)
17+
echo <<-\EOF >bop
18+
gomez
19+
morticia
20+
wednesday
21+
pugsly
22+
EOF
23+
)

0 commit comments

Comments
 (0)