mirror of
https://github.com/git/git.git
synced 2024-11-27 12:03:55 +08:00
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 <sunshine@sunshineco.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
parent
5238710eb4
commit
7b90679012
4
t/chainlint/blank-line.expect
Normal file
4
t/chainlint/blank-line.expect
Normal file
@ -0,0 +1,4 @@
|
||||
(
|
||||
nothing &&
|
||||
something
|
||||
>)
|
10
t/chainlint/blank-line.test
Normal file
10
t/chainlint/blank-line.test
Normal file
@ -0,0 +1,10 @@
|
||||
(
|
||||
|
||||
nothing &&
|
||||
|
||||
something
|
||||
# LINT: swallow blank lines since final _statement_ before subshell end is
|
||||
# LINT: significant to "&&"-check, not final _line_ (which might be blank)
|
||||
|
||||
|
||||
)
|
4
t/chainlint/comment.expect
Normal file
4
t/chainlint/comment.expect
Normal file
@ -0,0 +1,4 @@
|
||||
(
|
||||
nothing &&
|
||||
something
|
||||
>)
|
11
t/chainlint/comment.test
Normal file
11
t/chainlint/comment.test
Normal file
@ -0,0 +1,11 @@
|
||||
(
|
||||
# LINT: swallow comment lines
|
||||
# comment 1
|
||||
nothing &&
|
||||
# comment 2
|
||||
something
|
||||
# LINT: swallow comment lines since final _statement_ before subshell end is
|
||||
# LINT: significant to "&&"-check, not final _line_ (which might be comment)
|
||||
# comment 3
|
||||
# comment 4
|
||||
)
|
3
t/chainlint/here-doc.expect
Normal file
3
t/chainlint/here-doc.expect
Normal file
@ -0,0 +1,3 @@
|
||||
boodle wobba gorgo snoot wafta snurb &&
|
||||
|
||||
horticulture
|
16
t/chainlint/here-doc.test
Normal file
16
t/chainlint/here-doc.test
Normal file
@ -0,0 +1,16 @@
|
||||
# LINT: stitch together incomplete \-ending lines
|
||||
# LINT: swallow here-doc to avoid false positives in content
|
||||
boodle wobba \
|
||||
gorgo snoot \
|
||||
wafta snurb <<EOF &&
|
||||
quoth the raven,
|
||||
nevermore...
|
||||
EOF
|
||||
|
||||
# LINT: swallow here-doc (EOF is last line of test)
|
||||
horticulture <<\EOF
|
||||
gomez
|
||||
morticia
|
||||
wednesday
|
||||
pugsly
|
||||
EOF
|
4
t/chainlint/incomplete-line.expect
Normal file
4
t/chainlint/incomplete-line.expect
Normal file
@ -0,0 +1,4 @@
|
||||
line 1 line 2 line 3 line 4 &&
|
||||
(
|
||||
line 5 line 6 line 7 line 8
|
||||
>)
|
12
t/chainlint/incomplete-line.test
Normal file
12
t/chainlint/incomplete-line.test
Normal file
@ -0,0 +1,12 @@
|
||||
# LINT: stitch together all incomplete \-ending lines
|
||||
line 1 \
|
||||
line 2 \
|
||||
line 3 \
|
||||
line 4 &&
|
||||
(
|
||||
# LINT: stitch together all incomplete \-ending lines (subshell)
|
||||
line 5 \
|
||||
line 6 \
|
||||
line 7 \
|
||||
line 8
|
||||
)
|
9
t/chainlint/inline-comment.expect
Normal file
9
t/chainlint/inline-comment.expect
Normal file
@ -0,0 +1,9 @@
|
||||
(
|
||||
foobar &&
|
||||
?!AMP?! barfoo
|
||||
flibble "not a # comment"
|
||||
>) &&
|
||||
|
||||
(
|
||||
cd foo &&
|
||||
> flibble "not a # comment")
|
12
t/chainlint/inline-comment.test
Normal file
12
t/chainlint/inline-comment.test
Normal file
@ -0,0 +1,12 @@
|
||||
(
|
||||
# LINT: swallow inline comment (leaving command intact)
|
||||
foobar && # comment 1
|
||||
# LINT: mispositioned "&&" (correctly) swallowed with comment
|
||||
barfoo # wrong position for &&
|
||||
# LINT: "#" in string not misinterpreted as comment
|
||||
flibble "not a # comment"
|
||||
) &&
|
||||
|
||||
# LINT: "#" in string in cuddled subshell not misinterpreted as comment
|
||||
(cd foo &&
|
||||
flibble "not a # comment")
|
5
t/chainlint/subshell-here-doc.expect
Normal file
5
t/chainlint/subshell-here-doc.expect
Normal file
@ -0,0 +1,5 @@
|
||||
(
|
||||
echo wobba gorgo snoot wafta snurb &&
|
||||
?!AMP?! cat >bip
|
||||
echo >bop
|
||||
>)
|
23
t/chainlint/subshell-here-doc.test
Normal file
23
t/chainlint/subshell-here-doc.test
Normal file
@ -0,0 +1,23 @@
|
||||
(
|
||||
# LINT: stitch together incomplete \-ending lines
|
||||
# LINT: swallow here-doc to avoid false positives in content
|
||||
echo wobba \
|
||||
gorgo snoot \
|
||||
wafta snurb <<-EOF &&
|
||||
quoth the raven,
|
||||
nevermore...
|
||||
EOF
|
||||
|
||||
# LINT: missing "&&" on 'cat'
|
||||
cat <<EOF >bip
|
||||
fish fly high
|
||||
EOF
|
||||
|
||||
# LINT: swallow here-doc (EOF is last line of subshell)
|
||||
echo <<-\EOF >bop
|
||||
gomez
|
||||
morticia
|
||||
wednesday
|
||||
pugsly
|
||||
EOF
|
||||
)
|
Loading…
Reference in New Issue
Block a user