From 34ba05c2966f9e96b74ea984251e3bda802d6a7a Mon Sep 17 00:00:00 2001 From: Eric Sunshine Date: Mon, 13 Dec 2021 01:30:57 -0500 Subject: chainlint.sed: stop throwing away here-doc tags The purpose of chainlint is to highlight problems it finds in test code by inserting annotations at the location of each problem. Arbitrarily eliding bits of the code it is checking is not helpful, yet this is exactly what chainlint.sed does by cavalierly and unnecessarily dropping the here-doc operator and tag; i.e. `cat < Signed-off-by: Junio C Hamano --- t/chainlint.sed | 24 ++++++++++++++-------- t/chainlint/for-loop.expect | 2 +- t/chainlint/here-doc-close-subshell.expect | 2 +- .../here-doc-multi-line-command-subst.expect | 2 +- t/chainlint/here-doc-multi-line-string.expect | 2 +- t/chainlint/here-doc.expect | 8 ++++---- t/chainlint/if-then-else.expect | 2 +- t/chainlint/nested-here-doc.expect | 6 +++--- t/chainlint/subshell-here-doc.expect | 10 ++++----- t/chainlint/t7900-subtree.expect | 4 ++-- t/chainlint/while-loop.expect | 2 +- 11 files changed, 35 insertions(+), 29 deletions(-) (limited to 't') diff --git a/t/chainlint.sed b/t/chainlint.sed index 2f786f890d..0e575c0c62 100644 --- a/t/chainlint.sed +++ b/t/chainlint.sed @@ -62,20 +62,20 @@ # receives similar treatment. # # Swallowing here-docs with arbitrary tags requires a bit of finesse. When a -# line such as "cat <out" is seen, the here-doc tag is moved to the front -# of the line enclosed in angle brackets as a sentinel, giving "cat >out". +# line such as "cat <cat <\n\1$/ is attempted to see if # the content inside "<...>" matches the entirety of the newly-read line. For # instance, if the next line read is "some data", when concatenated with the -# target line, it becomes "cat >out\nsome data", and a match is attempted +# target line, it becomes "cat <cat >out\nEOF", +# encountered, it is appended to the target line giving "cat <" does match the text following the # newline, thus the closing here-doc tag has been found. The closing tag line # and the "<...>" prefix on the target line are then discarded, leaving just -# the target line "cat >out". +# the target line "cat <\1<\1\2/ :hered N /^<\([^>]*\)>.*\n[ ]*\1[ ]*$/!{ @@ -238,6 +237,7 @@ s/.*\n// :cont # retrieve and print previous line x +s/?!HERE?!/<\1<\1?!HERE?!\2\3/ :hdocsub N /^<\([^>]*\)>.*\n[ ]*\1[ ]*$/!{ @@ -293,6 +292,7 @@ bfolded # found "case ... in" -- pass through untouched :case x +s/?!HERE?!/<foo && +cat <<-Arbitrary_Tag_42 >foo && -cat >boo && +cat <boo && -horticulture +horticulture <foop && +cat <foop && ( - cat && - cat ?!AMP?! + cat <<-INPUT_END && + cat <<-EOT ?!AMP?! foobar ) diff --git a/t/chainlint/subshell-here-doc.expect b/t/chainlint/subshell-here-doc.expect index b7250ca753..029d129299 100644 --- a/t/chainlint/subshell-here-doc.expect +++ b/t/chainlint/subshell-here-doc.expect @@ -1,10 +1,10 @@ ( - echo wobba gorgo snoot wafta snurb && - cat >bip ?!AMP?! - echo >bop + echo wobba gorgo snoot wafta snurb <<-EOF && + cat <bip ?!AMP?! + echo <<-EOF >bop ) && ( - cat >bup && - cat >bup3 && + cat <<-ARBITRARY >bup && + cat <<-ARBITRARY3 >bup3 && meep ) diff --git a/t/chainlint/t7900-subtree.expect b/t/chainlint/t7900-subtree.expect index 215aca01c2..1cccc7bf7e 100644 --- a/t/chainlint/t7900-subtree.expect +++ b/t/chainlint/t7900-subtree.expect @@ -1,9 +1,9 @@ ( chks="sub1sub2sub3sub4" && - chks_sub=$(cat | sed "s,^,sub dir/," + chks_sub=$(cat <