Eric Sunshine <sunsh...@sunshineco.com> writes: > The --chain-lint option detects broken &&-chains by forcing the test to > exit early (as the very first step) with a sentinel value. If that > sentinel is the test's overall exit code, then the &&-chain is intact; > if not, then the chain is broken. Unfortunately, this detection does not > extend to &&-chains within subshells even when the subshell itself is > properly linked into the outer &&-chain. > > Address this shortcoming by feeding the body of the test to a > lightweight "linter" which can peer inside subshells and identify broken > &&-chains by pure textual inspection. Although the linter does not > ... > Heuristics are employed to properly identify the extent of a subshell > formatted in the old-style since a number of legitimate constructs may > superficially appear to close the subshell even though they don't. For > example, it understands that neither "x=$(command)" nor "case $x in *)" > end a subshell, despite the ")" at the end of line. > > Due to limitations of the tool used ('sed') and its inherent > line-by-line processing, only subshells one level deep are handled, as > well as one-liner subshells one level below that. Subshells deeper than > that or multi-line subshells at level two are passed through as-is, thus > &&-chains in their bodies are not checked. > > Signed-off-by: Eric Sunshine <sunsh...@sunshineco.com> > ---
As with the previous "transform the script and feed the result to shell" approach, this risks to force us into writing our tests in a subset of valid shell language, which is the primary reason why I was not enthused when I saw the previous round. The worst part of it is that the subset is not strictly defined based on the shell language syntax or features (e.g. we allow this and that feature but not that other feature) but "whatever that does not cause the linter script to trigger false positives". So I dunno. I haven't spent enough time to carefully look at the actual scripts to access how serious the "problem" I perceive actually is with this series to form a firm opinion yet. Let me come back to the topic after doing so.