]> git.ipfire.org Git - thirdparty/git.git/commitdiff
chainlint.sed: stop throwing away here-doc tags
authorEric Sunshine <sunshine@sunshineco.com>
Mon, 13 Dec 2021 06:30:57 +0000 (01:30 -0500)
committerJunio C Hamano <gitster@pobox.com>
Mon, 13 Dec 2021 22:15:29 +0000 (14:15 -0800)
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 <<TAG` becomes simply `cat` in
the output. This behavior can make it more difficult for the test writer
to align the annotated output of chainlint.sed with the original test
code. Address this by retaining here-doc tags.

Signed-off-by: Eric Sunshine <sunshine@sunshineco.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
t/chainlint.sed
t/chainlint/for-loop.expect
t/chainlint/here-doc-close-subshell.expect
t/chainlint/here-doc-multi-line-command-subst.expect
t/chainlint/here-doc-multi-line-string.expect
t/chainlint/here-doc.expect
t/chainlint/if-then-else.expect
t/chainlint/nested-here-doc.expect
t/chainlint/subshell-here-doc.expect
t/chainlint/t7900-subtree.expect
t/chainlint/while-loop.expect

index 2f786f890df82ff9b82cd7904de2663337fff5b5..0e575c0c624003292951c22915495eecd756159d 100644 (file)
 # receives similar treatment.
 #
 # Swallowing here-docs with arbitrary tags requires a bit of finesse. When a
-# line such as "cat <<EOF >out" is seen, the here-doc tag is moved to the front
-# of the line enclosed in angle brackets as a sentinel, giving "<EOF>cat >out".
+# line such as "cat <<EOF" is seen, the here-doc tag is copied to the front of
+# the line enclosed in angle brackets as a sentinel, giving "<EOF>cat <<EOF".
 # As each subsequent line is read, it is appended to the target line and a
 # (whitespace-loose) back-reference match /^<(.*)>\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 "<EOF>cat >out\nsome data", and a match is attempted
+# target line, it becomes "<EOF>cat <<EOF\nsome data", and a match is attempted
 # to see if "EOF" matches "some data". Since it doesn't, the next line is
 # attempted. When a line consisting of only "EOF" (and possible whitespace) is
-# encountered, it is appended to the target line giving "<EOF>cat >out\nEOF",
+# encountered, it is appended to the target line giving "<EOF>cat <<EOF\nEOF",
 # in which case the "EOF" inside "<...>" 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 <<EOF".
 #------------------------------------------------------------------------------
 
 # incomplete line -- slurp up next line
@@ -90,8 +90,7 @@
 # command to which it was attached)
 /<<-*[         ]*[\\'"]*[A-Za-z0-9_]/ {
        /"[^"]*<<[^"]*"/bnotdoc
-       s/^\(.*\)<<-*[  ]*[\\'"]*\([A-Za-z0-9_][A-Za-z0-9_]*\)['"]*/<\2>\1<</
-       s/[     ]*<<//
+       s/^\(.*<<-*[    ]*\)[\\'"]*\([A-Za-z0-9_][A-Za-z0-9_]*\)['"]*/<\2>\1\2/
        :hered
        N
        /^<\([^>]*\)>.*\n[      ]*\1[   ]*$/!{
@@ -238,6 +237,7 @@ s/.*\n//
 :cont
 # retrieve and print previous line
 x
+s/?!HERE?!/<</g
 n
 bslurp
 
@@ -278,8 +278,7 @@ bfolded
 # found here-doc -- swallow it to avoid false hits within its body (but keep
 # the command to which it was attached)
 :heredoc
-s/^\(.*\)<<-*[         ]*[\\'"]*\([A-Za-z0-9_][A-Za-z0-9_]*\)['"]*/<\2>\1<</
-s/[    ]*<<//
+s/^\(.*\)<<\(-*[       ]*\)[\\'"]*\([A-Za-z0-9_][A-Za-z0-9_]*\)['"]*/<\3>\1?!HERE?!\2\3/
 :hdocsub
 N
 /^<\([^>]*\)>.*\n[     ]*\1[   ]*$/!{
@@ -293,6 +292,7 @@ bfolded
 # found "case ... in" -- pass through untouched
 :case
 x
+s/?!HERE?!/<</g
 n
 /^[    ]*esac/bslurp
 bcase
@@ -320,6 +320,7 @@ bchkchn
 :nest
 x
 :nstslrp
+s/?!HERE?!/<</g
 n
 # closing ")" on own line -- stop nested slurp
 /^[    ]*)/bnstcl
@@ -342,6 +343,7 @@ bchkchn
 # found multi-line "{...\n...}" block -- pass through untouched
 :block
 x
+s/?!HERE?!/<</g
 n
 # closing "}" -- stop block slurp
 /}/bchkchn
@@ -352,13 +354,17 @@ bblock
 :clssolo
 x
 s/\( ?!AMP?!\)* ?!AMP?!$//
+s/?!HERE?!/<</g
 p
 x
+s/?!HERE?!/<</g
 b
 
 # found closing "...)" -- exit subshell loop
 :close
 x
+s/?!HERE?!/<</g
 p
 x
+s/?!HERE?!/<</g
 b
index b74df064c5053c5c87d6f3021fdfa394b6037fdd..6671b8cd842de110882342fc4ee359eb7e4d1375 100644 (file)
@@ -2,7 +2,7 @@
        for i in a b c
        do
                echo $i ?!AMP?!
-               cat
+               cat <<-EOF
        done ?!AMP?!
        for i in a b c; do
                echo $i &&
index e7485265709ae942a39f70fa2b95e4d433c3bda7..2af9ced71cc331414ce22e5d4ef3fc1320b3c15d 100644 (file)
@@ -1,2 +1,2 @@
 (
-       cat)
+       cat <<-INPUT)
index f1248f8aded77aff41bafd67ec348c09324960a4..f8b3aa73c4f180be48afff988c0f7cece67e45d4 100644 (file)
@@ -1,5 +1,5 @@
 (
-       x=$(bobble &&
+       x=$(bobble <<-END &&
                wiffle) ?!AMP?!
        echo $x
 )
index 7e883b252e11f2092d0b31d8b8d919d302a0ba8f..2578191ca8a809c8bbc271c9f1b8b744d9d8444e 100644 (file)
@@ -1,4 +1,4 @@
 (
-       cat && echo "multi-line string" ?!AMP?!
+       cat <<-TXT && echo "multi-line  string" ?!AMP?!
        bap
 )
index 8449eb2e02a5f982f1ee8021ec32ed175ee55967..110059ba58420e5924de64edb0ec44346b43cb34 100644 (file)
@@ -1,7 +1,7 @@
-boodle wobba        gorgo snoot        wafta snurb &&
+boodle wobba        gorgo snoot        wafta snurb <<EOF &&
 
-cat >foo &&
+cat <<-Arbitrary_Tag_42 >foo &&
 
-cat >boo &&
+cat <<zump >boo &&
 
-horticulture
+horticulture <<EOF
index debcf7b75618cd23775df37c2e9d3f8247d4299f..44d86c35976ce1957aa0b4fb90f6b7e31f230d3c 100644 (file)
@@ -8,7 +8,7 @@
                echo foo
        else
                echo foo &&
-               cat
+               cat <<-EOF
        fi ?!AMP?!
        echo poodle
 ) &&
index 2a51205d3294d421b9a351474dff04a025f0b421..e3bef63f7548cb0c187ae938280029dd470922bb 100644 (file)
@@ -1,7 +1,7 @@
-cat >foop &&
+cat <<ARBITRARY >foop &&
 
 (
-       cat &&
-       cat ?!AMP?!
+       cat <<-INPUT_END &&
+       cat <<-EOT ?!AMP?!
        foobar
 )
index b7250ca753d3500291b08c537bee8091104475e4..029d129299a0a5c68d45661071ba3ae144cd5377 100644 (file)
@@ -1,10 +1,10 @@
 (
-       echo wobba             gorgo snoot             wafta snurb &&
-       cat >bip ?!AMP?!
-       echo >bop
+       echo wobba             gorgo snoot             wafta snurb <<-EOF &&
+       cat <<EOF >bip ?!AMP?!
+       echo <<-EOF >bop
 ) &&
 (
-       cat >bup &&
-       cat >bup3 &&
+       cat <<-ARBITRARY >bup &&
+       cat <<-ARBITRARY3 >bup3 &&
        meep
 )
index 215aca01c2c1b2baa82d55f12928345138ed50dd..1cccc7bf7e1a47d9a922dda821b9eac513c83104 100644 (file)
@@ -1,9 +1,9 @@
 (
        chks="sub1sub2sub3sub4" &&
-       chks_sub=$(cat | sed "s,^,sub dir/,"
+       chks_sub=$(cat <<TXT | sed "s,^,sub dir/,"
 ) &&
        chkms="main-sub1main-sub2main-sub3main-sub4" &&
-       chkms_sub=$(cat | sed "s,^,sub dir/,"
+       chkms_sub=$(cat <<TXT | sed "s,^,sub dir/,"
 ) &&
        subfiles=$(git ls-files) &&
        check_equal "$subfiles" "$chkms$chks"
index e2813b378e8165e72ed9dfa4777154219e24c627..0d3a9b3d128940a9515d9924964e9efeeaf48152 100644 (file)
@@ -2,7 +2,7 @@
        while true
        do
                echo foo ?!AMP?!
-               cat
+               cat <<-EOF
        done ?!AMP?!
        while true; do
                echo foo &&