зеркало из https://github.com/microsoft/git.git
t/chainlint: add chainlint "nested subshell" 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:
Родитель
90a880393a
Коммит
bb4efbc5df
|
@ -0,0 +1,12 @@
|
||||||
|
(
|
||||||
|
foo &&
|
||||||
|
{
|
||||||
|
echo a
|
||||||
|
echo b
|
||||||
|
} &&
|
||||||
|
bar &&
|
||||||
|
{
|
||||||
|
echo c
|
||||||
|
?!AMP?! }
|
||||||
|
baz
|
||||||
|
>)
|
|
@ -0,0 +1,15 @@
|
||||||
|
(
|
||||||
|
# LINT: missing "&&" in block not currently detected (for consistency with
|
||||||
|
# LINT: --chain-lint at top level and to provide escape hatch if needed)
|
||||||
|
foo &&
|
||||||
|
{
|
||||||
|
echo a
|
||||||
|
echo b
|
||||||
|
} &&
|
||||||
|
bar &&
|
||||||
|
# LINT: missing "&&" at closing "}"
|
||||||
|
{
|
||||||
|
echo c
|
||||||
|
}
|
||||||
|
baz
|
||||||
|
)
|
|
@ -0,0 +1,9 @@
|
||||||
|
(
|
||||||
|
foo &&
|
||||||
|
x=$(
|
||||||
|
echo bar |
|
||||||
|
cat
|
||||||
|
>> ) &&
|
||||||
|
echo ok
|
||||||
|
>) |
|
||||||
|
sort
|
|
@ -0,0 +1,9 @@
|
||||||
|
(
|
||||||
|
foo &&
|
||||||
|
x=$(
|
||||||
|
echo bar |
|
||||||
|
cat
|
||||||
|
) &&
|
||||||
|
echo ok
|
||||||
|
) |
|
||||||
|
sort
|
|
@ -0,0 +1,19 @@
|
||||||
|
(
|
||||||
|
(cd foo &&
|
||||||
|
bar
|
||||||
|
>> ) &&
|
||||||
|
(cd foo &&
|
||||||
|
bar
|
||||||
|
?!AMP?!>> )
|
||||||
|
(
|
||||||
|
cd foo &&
|
||||||
|
>> bar) &&
|
||||||
|
(
|
||||||
|
cd foo &&
|
||||||
|
?!AMP?!>> bar)
|
||||||
|
(cd foo &&
|
||||||
|
>> bar) &&
|
||||||
|
(cd foo &&
|
||||||
|
?!AMP?!>> bar)
|
||||||
|
foobar
|
||||||
|
>)
|
|
@ -0,0 +1,31 @@
|
||||||
|
(
|
||||||
|
# LINT: opening "(" cuddled with first nested subshell statement
|
||||||
|
(cd foo &&
|
||||||
|
bar
|
||||||
|
) &&
|
||||||
|
|
||||||
|
# LINT: same but "&&" missing
|
||||||
|
(cd foo &&
|
||||||
|
bar
|
||||||
|
)
|
||||||
|
|
||||||
|
# LINT: closing ")" cuddled with final nested subshell statement
|
||||||
|
(
|
||||||
|
cd foo &&
|
||||||
|
bar) &&
|
||||||
|
|
||||||
|
# LINT: same but "&&" missing
|
||||||
|
(
|
||||||
|
cd foo &&
|
||||||
|
bar)
|
||||||
|
|
||||||
|
# LINT: "(" and ")" cuddled with first and final subshell statements
|
||||||
|
(cd foo &&
|
||||||
|
bar) &&
|
||||||
|
|
||||||
|
# LINT: same but "&&" missing
|
||||||
|
(cd foo &&
|
||||||
|
bar)
|
||||||
|
|
||||||
|
foobar
|
||||||
|
)
|
|
@ -0,0 +1,5 @@
|
||||||
|
(
|
||||||
|
cat &&
|
||||||
|
?!AMP?! cat
|
||||||
|
foobar
|
||||||
|
>)
|
|
@ -0,0 +1,23 @@
|
||||||
|
(
|
||||||
|
# LINT: inner "EOF" not misintrepreted as closing INPUT_END here-doc
|
||||||
|
cat <<-\INPUT_END &&
|
||||||
|
fish are mice
|
||||||
|
but geese go slow
|
||||||
|
data <<EOF
|
||||||
|
perl is lerp
|
||||||
|
and nothing else
|
||||||
|
EOF
|
||||||
|
toink
|
||||||
|
INPUT_END
|
||||||
|
|
||||||
|
# LINT: same but missing "&&"
|
||||||
|
cat <<-\EOT
|
||||||
|
text goes here
|
||||||
|
data <<EOF
|
||||||
|
data goes here
|
||||||
|
EOF
|
||||||
|
more test here
|
||||||
|
EOT
|
||||||
|
|
||||||
|
foobar
|
||||||
|
)
|
|
@ -0,0 +1,11 @@
|
||||||
|
(
|
||||||
|
foo &&
|
||||||
|
(
|
||||||
|
bar &&
|
||||||
|
# bottles wobble while fiddles gobble
|
||||||
|
# minor numbers of cows (or do they?)
|
||||||
|
baz &&
|
||||||
|
snaff
|
||||||
|
?!AMP?!>> )
|
||||||
|
fuzzy
|
||||||
|
>)
|
|
@ -0,0 +1,13 @@
|
||||||
|
(
|
||||||
|
foo &&
|
||||||
|
(
|
||||||
|
bar &&
|
||||||
|
# LINT: ")" in comment in nested subshell not misinterpreted as closing ")"
|
||||||
|
# bottles wobble while fiddles gobble
|
||||||
|
# minor numbers of cows (or do they?)
|
||||||
|
baz &&
|
||||||
|
snaff
|
||||||
|
# LINT: missing "&&" on ')'
|
||||||
|
)
|
||||||
|
fuzzy
|
||||||
|
)
|
|
@ -0,0 +1,12 @@
|
||||||
|
(
|
||||||
|
cd foo &&
|
||||||
|
(
|
||||||
|
echo a &&
|
||||||
|
echo b
|
||||||
|
>> ) >file &&
|
||||||
|
cd foo &&
|
||||||
|
(
|
||||||
|
echo a
|
||||||
|
echo b
|
||||||
|
>> ) >file
|
||||||
|
>)
|
|
@ -0,0 +1,14 @@
|
||||||
|
(
|
||||||
|
cd foo &&
|
||||||
|
(
|
||||||
|
echo a &&
|
||||||
|
echo b
|
||||||
|
) >file &&
|
||||||
|
|
||||||
|
cd foo &&
|
||||||
|
(
|
||||||
|
# LINT: nested multi-line subshell not presently checked for missing "&&"
|
||||||
|
echo a
|
||||||
|
echo b
|
||||||
|
) >file
|
||||||
|
)
|
Загрузка…
Ссылка в новой задаче