Skip to content

Commit 34ba05c

Browse files
sunshinecogitster
authored andcommitted
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 <<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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 22597af commit 34ba05c

11 files changed

+35
-29
lines changed

t/chainlint.sed

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -62,20 +62,20 @@
6262
# receives similar treatment.
6363
#
6464
# Swallowing here-docs with arbitrary tags requires a bit of finesse. When a
65-
# line such as "cat <<EOF >out" is seen, the here-doc tag is moved to the front
66-
# of the line enclosed in angle brackets as a sentinel, giving "<EOF>cat >out".
65+
# line such as "cat <<EOF" is seen, the here-doc tag is copied to the front of
66+
# the line enclosed in angle brackets as a sentinel, giving "<EOF>cat <<EOF".
6767
# As each subsequent line is read, it is appended to the target line and a
6868
# (whitespace-loose) back-reference match /^<(.*)>\n\1$/ is attempted to see if
6969
# the content inside "<...>" matches the entirety of the newly-read line. For
7070
# instance, if the next line read is "some data", when concatenated with the
71-
# target line, it becomes "<EOF>cat >out\nsome data", and a match is attempted
71+
# target line, it becomes "<EOF>cat <<EOF\nsome data", and a match is attempted
7272
# to see if "EOF" matches "some data". Since it doesn't, the next line is
7373
# attempted. When a line consisting of only "EOF" (and possible whitespace) is
74-
# encountered, it is appended to the target line giving "<EOF>cat >out\nEOF",
74+
# encountered, it is appended to the target line giving "<EOF>cat <<EOF\nEOF",
7575
# in which case the "EOF" inside "<...>" does match the text following the
7676
# newline, thus the closing here-doc tag has been found. The closing tag line
7777
# and the "<...>" prefix on the target line are then discarded, leaving just
78-
# the target line "cat >out".
78+
# the target line "cat <<EOF".
7979
#------------------------------------------------------------------------------
8080

8181
# incomplete line -- slurp up next line
@@ -90,8 +90,7 @@
9090
# command to which it was attached)
9191
/<<-*[ ]*[\\'"]*[A-Za-z0-9_]/ {
9292
/"[^"]*<<[^"]*"/bnotdoc
93-
s/^\(.*\)<<-*[ ]*[\\'"]*\([A-Za-z0-9_][A-Za-z0-9_]*\)['"]*/<\2>\1<</
94-
s/[ ]*<<//
93+
s/^\(.*<<-*[ ]*\)[\\'"]*\([A-Za-z0-9_][A-Za-z0-9_]*\)['"]*/<\2>\1\2/
9594
:hered
9695
N
9796
/^<\([^>]*\)>.*\n[ ]*\1[ ]*$/!{
@@ -238,6 +237,7 @@ s/.*\n//
238237
:cont
239238
# retrieve and print previous line
240239
x
240+
s/?!HERE?!/<</g
241241
n
242242
bslurp
243243

@@ -278,8 +278,7 @@ bfolded
278278
# found here-doc -- swallow it to avoid false hits within its body (but keep
279279
# the command to which it was attached)
280280
:heredoc
281-
s/^\(.*\)<<-*[ ]*[\\'"]*\([A-Za-z0-9_][A-Za-z0-9_]*\)['"]*/<\2>\1<</
282-
s/[ ]*<<//
281+
s/^\(.*\)<<\(-*[ ]*\)[\\'"]*\([A-Za-z0-9_][A-Za-z0-9_]*\)['"]*/<\3>\1?!HERE?!\2\3/
283282
:hdocsub
284283
N
285284
/^<\([^>]*\)>.*\n[ ]*\1[ ]*$/!{
@@ -293,6 +292,7 @@ bfolded
293292
# found "case ... in" -- pass through untouched
294293
:case
295294
x
295+
s/?!HERE?!/<</g
296296
n
297297
/^[ ]*esac/bslurp
298298
bcase
@@ -320,6 +320,7 @@ bchkchn
320320
:nest
321321
x
322322
:nstslrp
323+
s/?!HERE?!/<</g
323324
n
324325
# closing ")" on own line -- stop nested slurp
325326
/^[ ]*)/bnstcl
@@ -342,6 +343,7 @@ bchkchn
342343
# found multi-line "{...\n...}" block -- pass through untouched
343344
:block
344345
x
346+
s/?!HERE?!/<</g
345347
n
346348
# closing "}" -- stop block slurp
347349
/}/bchkchn
@@ -352,13 +354,17 @@ bblock
352354
:clssolo
353355
x
354356
s/\( ?!AMP?!\)* ?!AMP?!$//
357+
s/?!HERE?!/<</g
355358
p
356359
x
360+
s/?!HERE?!/<</g
357361
b
358362

359363
# found closing "...)" -- exit subshell loop
360364
:close
361365
x
366+
s/?!HERE?!/<</g
362367
p
363368
x
369+
s/?!HERE?!/<</g
364370
b

t/chainlint/for-loop.expect

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
for i in a b c
33
do
44
echo $i ?!AMP?!
5-
cat
5+
cat <<-EOF
66
done ?!AMP?!
77
for i in a b c; do
88
echo $i &&
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
(
2-
cat)
2+
cat <<-INPUT)
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
(
2-
x=$(bobble &&
2+
x=$(bobble <<-END &&
33
wiffle) ?!AMP?!
44
echo $x
55
)
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
(
2-
cat && echo "multi-line string" ?!AMP?!
2+
cat <<-TXT && echo "multi-line string" ?!AMP?!
33
bap
44
)

t/chainlint/here-doc.expect

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
boodle wobba gorgo snoot wafta snurb &&
1+
boodle wobba gorgo snoot wafta snurb <<EOF &&
22

3-
cat >foo &&
3+
cat <<-Arbitrary_Tag_42 >foo &&
44

5-
cat >boo &&
5+
cat <<zump >boo &&
66

7-
horticulture
7+
horticulture <<EOF

t/chainlint/if-then-else.expect

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
echo foo
99
else
1010
echo foo &&
11-
cat
11+
cat <<-EOF
1212
fi ?!AMP?!
1313
echo poodle
1414
) &&

t/chainlint/nested-here-doc.expect

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
cat >foop &&
1+
cat <<ARBITRARY >foop &&
22

33
(
4-
cat &&
5-
cat ?!AMP?!
4+
cat <<-INPUT_END &&
5+
cat <<-EOT ?!AMP?!
66
foobar
77
)

t/chainlint/subshell-here-doc.expect

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
(
2-
echo wobba gorgo snoot wafta snurb &&
3-
cat >bip ?!AMP?!
4-
echo >bop
2+
echo wobba gorgo snoot wafta snurb <<-EOF &&
3+
cat <<EOF >bip ?!AMP?!
4+
echo <<-EOF >bop
55
) &&
66
(
7-
cat >bup &&
8-
cat >bup3 &&
7+
cat <<-ARBITRARY >bup &&
8+
cat <<-ARBITRARY3 >bup3 &&
99
meep
1010
)

t/chainlint/t7900-subtree.expect

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
(
22
chks="sub1sub2sub3sub4" &&
3-
chks_sub=$(cat | sed "s,^,sub dir/,"
3+
chks_sub=$(cat <<TXT | sed "s,^,sub dir/,"
44
) &&
55
chkms="main-sub1main-sub2main-sub3main-sub4" &&
6-
chkms_sub=$(cat | sed "s,^,sub dir/,"
6+
chkms_sub=$(cat <<TXT | sed "s,^,sub dir/,"
77
) &&
88
subfiles=$(git ls-files) &&
99
check_equal "$subfiles" "$chkms$chks"

0 commit comments

Comments
 (0)