From: Jeff King <peff@peff.net>
To: Eric Sunshine via GitGitGadget <gitgitgadget@gmail.com>
Cc: git@vger.kernel.org, Eric Sunshine <sunshine@sunshineco.com>
Subject: Re: [PATCH] chainlint: colorize problem annotations and test delimiters
Date: Mon, 12 Sep 2022 20:15:33 -0400 [thread overview]
Message-ID: <Yx/LpUglpjY5ZNas@coredump.intra.peff.net> (raw)
In-Reply-To: <pull.1324.git.git.1663023888412.gitgitgadget@gmail.com>
On Mon, Sep 12, 2022 at 11:04:48PM +0000, Eric Sunshine via GitGitGadget wrote:
> @@ -585,12 +585,14 @@ sub check_test {
> my $parser = TestParser->new(\$body);
> my @tokens = $parser->parse();
> return unless $emit_all || grep(/\?![^?]+\?!/, @tokens);
> + my $c = main::fd_colors(1);
> my $checked = join(' ', @tokens);
> $checked =~ s/^\n//;
> $checked =~ s/^ //mg;
> $checked =~ s/ $//mg;
> + $checked =~ s/(\?![^?]+\?!)/$c->{bold}$c->{red}$1$c->{reset}/mg;
> $checked .= "\n" unless $checked =~ /\n$/;
> - push(@{$self->{output}}, "# chainlint: $title\n$checked");
> + push(@{$self->{output}}, "$c->{blue}# chainlint: $title$c->{reset}\n$checked");
> }
Nice, this ended up much simpler than I feared. I thought we'd have to
touch each spot that added an annotation, and then deal with the
internal text matching (like the one in the hunk above). Being able to
do it centrally on output is much nicer.
> +my @NOCOLORS = (bold => '', reset => '', blue => '', green => '', red => '');
> +my %COLORS = ();
> +sub get_colors {
> + return \%COLORS if %COLORS;
> + if (exists($ENV{NO_COLOR}) ||
> + system("tput sgr0 >/dev/null 2>&1") != 0 ||
> + system("tput bold >/dev/null 2>&1") != 0 ||
> + system("tput setaf 1 >/dev/null 2>&1") != 0) {
> + %COLORS = @NOCOLORS;
> + return \%COLORS;
> + }
> + %COLORS = (bold => `tput bold`,
> + reset => `tput sgr0`,
> + blue => `tput setaf 4`,
> + green => `tput setaf 2`,
> + red => `tput setaf 1`);
> + chomp(%COLORS);
> + return \%COLORS;
> +}
This is a lot of new processes. Should be OK in the run-once-for-all-tests
mode. It does make me wonder how much time regular test-lib.sh spends
doing these tput checks for every script (at least it's not every
snippet!).
It feels like we could build a color.sh snippet once and then include it
in each script. But maybe that is dumb, since you could in theory build
in one terminal and then run in another. Unlikely, but it shows that
file dependencies are a mismatch. I guess a better match would be
stuffing it into the environment before starting all of the tests.
> [...]
I ran this on my pre-fixup state where I had a half-dozen linter checks.
It's _so_ much more readable. Thanks for working on it.
-Peff
next prev parent reply other threads:[~2022-09-13 0:15 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-09-12 23:04 [PATCH] chainlint: colorize problem annotations and test delimiters Eric Sunshine via GitGitGadget
2022-09-12 23:55 ` Junio C Hamano
2022-09-13 0:14 ` Eric Sunshine
2022-09-13 0:21 ` Junio C Hamano
2022-09-13 0:39 ` Eric Sunshine
2022-09-13 0:16 ` Jeff King
2022-09-13 0:15 ` Jeff King [this message]
2022-09-13 0:30 ` Eric Sunshine
2022-09-13 1:34 ` Jeff King
2022-09-13 0:32 ` Jeff King
2022-09-13 4:01 ` [PATCH v2] " Eric Sunshine via GitGitGadget
2022-09-13 20:40 ` Jeff King
2022-09-13 20:46 ` Junio C Hamano
2022-10-24 9:57 ` Ævar Arnfjörð Bjarmason
2022-10-24 9:57 ` chainlint.pl's new "deparse" output (was: [PATCH v2] [...]) Ævar Arnfjörð Bjarmason
2022-10-25 4:05 ` Eric Sunshine
2022-10-25 4:15 ` Eric Sunshine
2022-10-25 10:07 ` Ævar Arnfjörð Bjarmason
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=Yx/LpUglpjY5ZNas@coredump.intra.peff.net \
--to=peff@peff.net \
--cc=git@vger.kernel.org \
--cc=gitgitgadget@gmail.com \
--cc=sunshine@sunshineco.com \
/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).