From: Eric Sunshine <sunshine@sunshineco.com>
To: Jeff King <peff@peff.net>
Cc: "Eric Sunshine" <ericsunshine@charter.net>,
git@vger.kernel.org, "Junio C Hamano" <gitster@pobox.com>,
"René Scharfe" <l.s.r@web.de>
Subject: Re: [PATCH 1/3] chainlint.pl: fix line number reporting
Date: Mon, 8 Jul 2024 01:08:02 -0400 [thread overview]
Message-ID: <CAPig+cRxnpG9Yfix09EnJAbnzwN=yoUtSeYxt7S-Od+xBgfaYQ@mail.gmail.com> (raw)
In-Reply-To: <20240706060515.GA700151@coredump.intra.peff.net>
On 7/6/24 2:05 AM, Jeff King wrote:
> The previous commit taught chainlint.pl to handle test bodies in
> heredocs, but there are two small bugs related to line numbers:
>
> 2. For an invocation like the one above, if the test_expect_success
> line is X, then "test body" would correctly start at X+1, since the
> hanging newline at the start of the single-quoted test body
> increments the count. But for a here-doc, there is an implicit
> newline at the end of the token stream before the here-doc starts.
> We have to increment "lineno" to account for this.
>
> Actually, this is not _quite_ correct, as there could be multiple
> here-docs, like:
>
> test_expect_success "$(cat <<END_OF_TITLE)" - <<END_OF_TEST
> this is the title
> END_OF_TITLE
> this is the test
> END_OF_TEST
>
> in which case we'd need to skip past END_OF_TITLE. Given how
> unlikely it is for anybody to do this, and since it would only
> affect line numbers, it's probably not worth caring about too much.
> The solution would probably be to record the starting line number
> of each here-doc section in the lexer/shellparser stage.
>
> Signed-off-by: Jeff King <peff@peff.net>
> ---
> I actually suspect the "record the heredoc line number" thing would not
> be too hard. I.e., turn ShellParser's "heredoc" hash to point to
> hashrefs like: "{ content => ..., lineno => ... }". And that would give
> us a good spot to stick an "interpolate" boolean later if we want.
It turned out to be quite easy. See below for an implementation atop
your patch [1/3] (modulo Gmail whitespace damage). Given how simple
this ended up being, it probably makes sense to squash this change in,
as well.
--- >8 ---
diff --git a/t/chainlint.pl b/t/chainlint.pl
index c9ab79b6b0..b31cb263f8 100755
--- a/t/chainlint.pl
+++ b/t/chainlint.pl
@@ -174,8 +174,10 @@ sub swallow_heredocs {
$$b =~ /(?:\G|\n)$indent\Q$$tag[0]\E(?:\n|\z)/gc;
if (pos($$b) > $start) {
my $body = substr($$b, $start, pos($$b) - $start);
- $self->{parser}->{heredocs}->{$$tag[0]} =
- substr($body, 0, length($body) - length($&));
+ $self->{parser}->{heredocs}->{$$tag[0]} = {
+ content => substr($body, 0, length($body) - length($&)),
+ start_line => $self->{lineno},
+ };
$self->{lineno} += () = $body =~ /\n/sg;
next;
}
@@ -624,8 +626,9 @@ sub check_test {
my $lineno = $body->[3];
$body = unwrap($body);
if ($body eq '-') {
- $body = shift @_;
- $lineno++;
+ my $herebody = shift @_;
+ $body = $herebody->{content};
+ $lineno = $herebody->{start_line};
}
$self->{ntests}++;
my $parser = TestParser->new(\$body);
--
next prev parent reply other threads:[~2024-07-08 5:08 UTC|newest]
Thread overview: 65+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-07-01 22:08 [PATCH 0/2] here-doc test bodies Jeff King
2024-07-01 22:08 ` [PATCH 1/2] test-lib: allow test snippets as here-docs Jeff King
2024-07-01 22:45 ` Eric Sunshine
2024-07-01 23:43 ` Junio C Hamano
2024-07-02 0:51 ` Jeff King
2024-07-02 1:13 ` Jeff King
2024-07-02 21:37 ` Eric Sunshine
2024-07-06 5:44 ` Jeff King
2024-07-02 21:19 ` Jeff King
2024-07-02 21:59 ` Eric Sunshine
2024-07-06 5:23 ` Jeff King
2024-07-02 21:25 ` Eric Sunshine
2024-07-02 22:36 ` Eric Sunshine
2024-07-02 22:48 ` Eric Sunshine
2024-07-06 5:31 ` Jeff King
2024-07-06 5:33 ` Jeff King
2024-07-06 6:11 ` Eric Sunshine
2024-07-06 6:47 ` Eric Sunshine
2024-07-06 6:55 ` Jeff King
2024-07-06 7:06 ` Eric Sunshine
2024-07-06 6:54 ` Jeff King
2024-07-01 22:08 ` [PATCH 2/2] t: convert some here-doc test bodies Jeff King
2024-07-02 23:50 ` [PATCH] chainlint.pl: recognize test bodies defined via heredoc Eric Sunshine
2024-07-06 6:01 ` Jeff King
2024-07-06 6:05 ` [PATCH 1/3] chainlint.pl: fix line number reporting Jeff King
2024-07-08 5:08 ` Eric Sunshine [this message]
2024-07-08 9:10 ` Jeff King
2024-07-06 6:06 ` [PATCH 2/3] t/chainlint: add test_expect_success call to test snippets Jeff King
2024-07-06 6:09 ` Jeff King
2024-07-08 3:59 ` Eric Sunshine
2024-07-06 6:07 ` [PATCH 3/3] t/chainlint: add tests for test body in heredoc Jeff King
2024-07-08 2:43 ` Eric Sunshine
2024-07-08 8:59 ` Jeff King
2024-07-06 22:15 ` [PATCH] chainlint.pl: recognize test bodies defined via heredoc Junio C Hamano
2024-07-06 23:11 ` Jeff King
2024-07-08 3:51 ` Eric Sunshine
2024-07-08 9:08 ` Jeff King
2024-07-08 19:46 ` Eric Sunshine
2024-07-08 20:17 ` Eric Sunshine
2024-07-10 0:37 ` Jeff King
2024-07-10 1:09 ` Jeff King
2024-07-10 3:02 ` Eric Sunshine
2024-07-10 7:06 ` Jeff King
2024-07-10 7:29 ` Eric Sunshine
2024-07-08 3:40 ` Eric Sunshine
2024-07-08 9:05 ` Jeff King
2024-07-08 20:06 ` Eric Sunshine
2024-07-10 0:48 ` Jeff King
2024-07-10 2:38 ` Eric Sunshine
2024-07-10 8:34 ` [PATCH v2 0/9] here-doc test bodies (now with 100% more chainlinting) Jeff King
2024-07-10 8:34 ` [PATCH v2 1/9] chainlint.pl: add test_expect_success call to test snippets Jeff King
2024-07-10 8:35 ` [PATCH v2 2/9] chainlint.pl: only start threads if jobs > 1 Jeff King
2024-07-10 8:35 ` [PATCH v2 3/9] chainlint.pl: do not spawn more threads than we have scripts Jeff King
2024-07-10 8:37 ` [PATCH v2 4/9] chainlint.pl: force CRLF conversion when opening input files Jeff King
2024-07-10 8:37 ` [PATCH v2 5/9] chainlint.pl: check line numbers in expected output Jeff King
2024-08-21 7:00 ` Eric Sunshine
2024-08-21 12:14 ` Jeff King
2024-08-21 17:02 ` Eric Sunshine
2024-07-10 8:38 ` [PATCH v2 6/9] chainlint.pl: recognize test bodies defined via heredoc Jeff King
2024-07-10 8:39 ` [PATCH v2 7/9] chainlint.pl: add tests for test body in heredoc Jeff King
2024-07-10 8:39 ` [PATCH v2 8/9] test-lib: allow test snippets as here-docs Jeff King
2024-07-10 8:39 ` [PATCH v2 9/9] t: convert some here-doc test bodies Jeff King
2024-07-10 8:47 ` [PATCH v2 10/9] t/.gitattributes: ignore whitespace in chainlint expect files Jeff King
2024-07-10 17:15 ` Junio C Hamano
2024-08-21 7:31 ` [PATCH v2 0/9] here-doc test bodies (now with 100% more chainlinting) Eric Sunshine
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='CAPig+cRxnpG9Yfix09EnJAbnzwN=yoUtSeYxt7S-Od+xBgfaYQ@mail.gmail.com' \
--to=sunshine@sunshineco.com \
--cc=ericsunshine@charter.net \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=l.s.r@web.de \
--cc=peff@peff.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).