diff options
author | Eric Sunshine <sunshine@sunshineco.com> | 2023-03-30 21:30:31 +0200 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2023-03-30 22:07:29 +0200 |
commit | 2b61c8dc8843319d09f1485fbcb3b1dc4aecb36d (patch) | |
tree | 4d820f6aa8728014591b8c0125f2d2b0c1234730 /t/chainlint/unclosed-here-doc-indent.test | |
parent | tests: replace chainlint subshell with a function (diff) | |
download | git-2b61c8dc8843319d09f1485fbcb3b1dc4aecb36d.tar.xz git-2b61c8dc8843319d09f1485fbcb3b1dc4aecb36d.zip |
tests: diagnose unclosed here-doc in chainlint.pl
An unclosed here-doc in a test is a problem, because it silently gobbles
up any remaining commands. Since 99a64e4b73c (tests: lint for run-away
here-doc, 2017-03-22) we detect this by piggy-backing on the internal
chainlint checker in test-lib.sh.
However, it would be nice to detect it in chainlint.pl, for a few
reasons:
- the output from chainlint.pl is much nicer; it can show the exact
spot of the error, rather than a vague "somewhere in this test you
broke the &&-chain or had a bad here-doc" message.
- the implementation in test-lib.sh runs for each test snippet. And
since it requires a subshell, the extra cost is small but not zero.
If chainlint.pl can reliably find the problem, we can optimize the
test-lib.sh code.
The chainlint.pl code never intended to find here-doc problems. But
since it has to parse them anyway (to avoid reporting problems inside
here-docs), most of what we need is already there. We can detect the
problem when we fail to find the missing end-tag in swallow_heredocs().
The extra change in scan_heredoc_tag() stores the location of the start
of the here-doc, which lets us mark it as the source of the error in the
output (see the new tests for examples).
[jk: added commit message and tests]
Signed-off-by: Eric Sunshine <sunshine@sunshineco.com>
Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 't/chainlint/unclosed-here-doc-indent.test')
-rw-r--r-- | t/chainlint/unclosed-here-doc-indent.test | 4 |
1 files changed, 4 insertions, 0 deletions
diff --git a/t/chainlint/unclosed-here-doc-indent.test b/t/chainlint/unclosed-here-doc-indent.test new file mode 100644 index 0000000000..5c841a9dfd --- /dev/null +++ b/t/chainlint/unclosed-here-doc-indent.test @@ -0,0 +1,4 @@ +command_which_is_run && +cat >expect <<-\EOF && +we forget to end the here-doc +command_which_is_gobbled |