From: Eric Sunshine Date: Wed, 11 Jul 2018 06:46:38 +0000 (-0400) Subject: t/chainlint: add chainlint "nested subshell" test cases X-Git-Tag: v2.19.0-rc0~90^2~5 X-Git-Url: https://git.lorimer.id.au/gitweb.git/diff_plain/bb4efbc5df9d0c96392dd14fc3ab6164949a2f52 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 Signed-off-by: Junio C Hamano --- diff --git a/t/chainlint/block.expect b/t/chainlint/block.expect new file mode 100644 index 0000000000..fed7e89ae8 --- /dev/null +++ b/t/chainlint/block.expect @@ -0,0 +1,12 @@ +( + foo && + { + echo a + echo b + } && + bar && + { + echo c +?!AMP?! } + baz +>) diff --git a/t/chainlint/block.test b/t/chainlint/block.test new file mode 100644 index 0000000000..d859151af1 --- /dev/null +++ b/t/chainlint/block.test @@ -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 +) diff --git a/t/chainlint/multi-line-nested-command-substitution.expect b/t/chainlint/multi-line-nested-command-substitution.expect new file mode 100644 index 0000000000..19c023b1c8 --- /dev/null +++ b/t/chainlint/multi-line-nested-command-substitution.expect @@ -0,0 +1,9 @@ +( + foo && + x=$( + echo bar | + cat +>> ) && + echo ok +>) | +sort diff --git a/t/chainlint/multi-line-nested-command-substitution.test b/t/chainlint/multi-line-nested-command-substitution.test new file mode 100644 index 0000000000..ca0620ab6b --- /dev/null +++ b/t/chainlint/multi-line-nested-command-substitution.test @@ -0,0 +1,9 @@ +( + foo && + x=$( + echo bar | + cat + ) && + echo ok +) | +sort diff --git a/t/chainlint/nested-cuddled-subshell.expect b/t/chainlint/nested-cuddled-subshell.expect new file mode 100644 index 0000000000..c2a59ffc33 --- /dev/null +++ b/t/chainlint/nested-cuddled-subshell.expect @@ -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 +>) diff --git a/t/chainlint/nested-cuddled-subshell.test b/t/chainlint/nested-cuddled-subshell.test new file mode 100644 index 0000000000..8fd656c7b5 --- /dev/null +++ b/t/chainlint/nested-cuddled-subshell.test @@ -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 +) diff --git a/t/chainlint/nested-here-doc.expect b/t/chainlint/nested-here-doc.expect new file mode 100644 index 0000000000..559301e005 --- /dev/null +++ b/t/chainlint/nested-here-doc.expect @@ -0,0 +1,5 @@ +( + cat && +?!AMP?! cat + foobar +>) diff --git a/t/chainlint/nested-here-doc.test b/t/chainlint/nested-here-doc.test new file mode 100644 index 0000000000..027e0bb3ff --- /dev/null +++ b/t/chainlint/nested-here-doc.test @@ -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 <> ) + fuzzy +>) diff --git a/t/chainlint/nested-subshell-comment.test b/t/chainlint/nested-subshell-comment.test new file mode 100644 index 0000000000..0ff136ab3c --- /dev/null +++ b/t/chainlint/nested-subshell-comment.test @@ -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 +) diff --git a/t/chainlint/nested-subshell.expect b/t/chainlint/nested-subshell.expect new file mode 100644 index 0000000000..c8165ad19e --- /dev/null +++ b/t/chainlint/nested-subshell.expect @@ -0,0 +1,12 @@ +( + cd foo && + ( + echo a && + echo b +>> ) >file && + cd foo && + ( + echo a + echo b +>> ) >file +>) diff --git a/t/chainlint/nested-subshell.test b/t/chainlint/nested-subshell.test new file mode 100644 index 0000000000..998b05a47d --- /dev/null +++ b/t/chainlint/nested-subshell.test @@ -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 +)