From 31da22d1fd46e80c592f6b04c6cafdb983c8a903 Mon Sep 17 00:00:00 2001 From: Eric Sunshine Date: Mon, 13 Dec 2021 01:30:58 -0500 Subject: chainlint.sed: swallow comments consistently When checking for broken a &&-chain, chainlint.sed knows that the final statement in a subshell should not end with `&&`, so it takes care to make a distinction between the final line which is an actual statement and any lines which may be mere comments preceding the closing ')'. As such, it swallows comment lines so that they do not interfere with the &&-chain check. However, since `sed` does not provide any sort of real recursion, chainlint.sed only checks &&-chains in subshells one level deep; it doesn't do any checking in deeper subshells or in `{...}` blocks within subshells. Furthermore, on account of potential implementation complexity, it doesn't check &&-chains within `case` arms. Due to an oversight, it also doesn't swallow comments inside deep subshells, `{...}` blocks, or `case` statements, which makes its output inconsistent (swallowing comments in some cases but not others). Unfortunately, this inconsistency seeps into the chainlint self-test "expect" files, which potentially makes it difficult to reuse the self-tests should a more capable chainlint ever be developed. Therefore, teach chainlint.sed to consistently swallow comments in all cases. Signed-off-by: Eric Sunshine Signed-off-by: Junio C Hamano --- t/chainlint.sed | 21 +++++++++++++++++++-- t/chainlint/block-comment.expect | 6 ++++++ t/chainlint/block-comment.test | 8 ++++++++ t/chainlint/case-comment.expect | 8 ++++++++ t/chainlint/case-comment.test | 11 +++++++++++ t/chainlint/nested-subshell-comment.expect | 2 -- 6 files changed, 52 insertions(+), 4 deletions(-) create mode 100644 t/chainlint/block-comment.expect create mode 100644 t/chainlint/block-comment.test create mode 100644 t/chainlint/case-comment.expect create mode 100644 t/chainlint/case-comment.test (limited to 't') diff --git a/t/chainlint.sed b/t/chainlint.sed index 0e575c0c62..b1505ef2cd 100644 --- a/t/chainlint.sed +++ b/t/chainlint.sed @@ -294,6 +294,12 @@ bfolded x s/?!HERE?!/<