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:
Eric Sunshine 2018-07-11 02:46:36 -04:00 коммит произвёл Junio C Hamano
Родитель 5238710eb4
Коммит 7b90679012
12 изменённых файлов: 113 добавлений и 0 удалений

Просмотреть файл

@ -0,0 +1,4 @@
(
nothing &&
something
>)

Просмотреть файл

@ -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)
)

Просмотреть файл

@ -0,0 +1,4 @@
(
nothing &&
something
>)

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
)

Просмотреть файл

@ -0,0 +1,3 @@
boodle wobba gorgo snoot wafta snurb &&
horticulture

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

Просмотреть файл

@ -0,0 +1,4 @@
line 1 line 2 line 3 line 4 &&
(
line 5 line 6 line 7 line 8
>)

Просмотреть файл

@ -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
)

Просмотреть файл

@ -0,0 +1,9 @@
(
foobar &&
?!AMP?! barfoo
flibble "not a # comment"
>) &&
(
cd foo &&
> flibble "not a # comment")

Просмотреть файл

@ -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")

Просмотреть файл

@ -0,0 +1,5 @@
(
echo wobba gorgo snoot wafta snurb &&
?!AMP?! cat >bip
echo >bop
>)

Просмотреть файл

@ -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
)