git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Eric Sunshine via GitGitGadget" <gitgitgadget@gmail.com>
To: git@vger.kernel.org
Cc: "Jeff King" <peff@peff.net>,
	"Ævar Arnfjörð Bjarmason" <avarab@gmail.com>,
	"Eric Sunshine" <sunshine@sunshineco.com>,
	"Eric Sunshine" <sunshine@sunshineco.com>
Subject: [PATCH 3/3] chainlint: prefix annotated test definition with line numbers
Date: Wed, 09 Nov 2022 16:58:34 +0000	[thread overview]
Message-ID: <380b146abd1d97d51511c7acd11ffb99d1affcc6.1668013114.git.gitgitgadget@gmail.com> (raw)
In-Reply-To: <pull.1413.git.1668013114.gitgitgadget@gmail.com>

From: Eric Sunshine <sunshine@sunshineco.com>

When chainlint detects problems in a test, it prints out the name of the
test script, the name of the problematic test, and a copy of the test
definition with "?!FOO?!" annotations inserted at the locations where
problems were detected. Taken together this information is sufficient
for the test author to identify the problematic code in the original
test definition. However, in a lengthy script or a lengthy test
definition, the author may still end up using the editor's search
feature to home in on the exact problem location.

To further assist the test author, display line numbers along with the
annotated test definition, thus allowing the author to jump directly to
each problematic line.

Suggested-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Signed-off-by: Eric Sunshine <sunshine@sunshineco.com>
---
 t/Makefile     |  2 +-
 t/chainlint.pl | 10 ++++++++--
 2 files changed, 9 insertions(+), 3 deletions(-)

diff --git a/t/Makefile b/t/Makefile
index 882782a519c..2c2b2522402 100644
--- a/t/Makefile
+++ b/t/Makefile
@@ -94,7 +94,7 @@ check-chainlint:
 		done \
 	} >'$(CHAINLINTTMP_SQ)'/expect && \
 	$(CHAINLINT) --emit-all '$(CHAINLINTTMP_SQ)'/tests | \
-		grep -v '^[ 	]*$$' >'$(CHAINLINTTMP_SQ)'/actual && \
+		sed -e 's/^[1-9][0-9]* //;/^[ 	]*$$/d' >'$(CHAINLINTTMP_SQ)'/actual && \
 	if test -f ../GIT-BUILD-OPTIONS; then \
 		. ../GIT-BUILD-OPTIONS; \
 	fi && \
diff --git a/t/chainlint.pl b/t/chainlint.pl
index 01f261165b1..48dde978480 100755
--- a/t/chainlint.pl
+++ b/t/chainlint.pl
@@ -613,6 +613,7 @@ sub check_test {
 	my $problems = $parser->{problems};
 	return unless $emit_all || @$problems;
 	my $c = main::fd_colors(1);
+	my $lineno = $_[1]->[3];
 	my $start = 0;
 	my $checked = '';
 	for (sort {$a->[1]->[2] <=> $b->[1]->[2]} @$problems) {
@@ -622,10 +623,12 @@ sub check_test {
 		$start = $pos;
 	}
 	$checked .= substr($body, $start);
-	$checked =~ s/^\n//;
+	$checked =~ s/^/$lineno++ . ' '/mge;
+	$checked =~ s/^\d+ \n//;
 	$checked =~ s/(\s) \?!/$1?!/mg;
 	$checked =~ s/\?! (\s)/?!$1/mg;
 	$checked =~ s/(\?![^?]+\?!)/$c->{rev}$c->{red}$1$c->{reset}/mg;
+	$checked =~ s/^\d+/$c->{dim}$&$c->{reset}/mg;
 	$checked .= "\n" unless $checked =~ /\n$/;
 	push(@{$self->{output}}, "$c->{blue}# chainlint: $title$c->{reset}\n$checked");
 }
@@ -657,7 +660,7 @@ if (eval {require Time::HiRes; Time::HiRes->import(); 1;}) {
 # thread and ignore %ENV changes in subthreads.
 $ENV{TERM} = $ENV{USER_TERM} if $ENV{USER_TERM};
 
-my @NOCOLORS = (bold => '', rev => '', reset => '', blue => '', green => '', red => '');
+my @NOCOLORS = (bold => '', rev => '', dim => '', reset => '', blue => '', green => '', red => '');
 my %COLORS = ();
 sub get_colors {
 	return \%COLORS if %COLORS;
@@ -668,6 +671,7 @@ sub get_colors {
 	if ($ENV{TERM} =~ /\bxterm\b/) {
 		%COLORS = (bold  => "\e[1m",
 			   rev   => "\e[7m",
+			   dim   => "\e[2m",
 			   reset => "\e[0m",
 			   blue  => "\e[34m",
 			   green => "\e[32m",
@@ -677,9 +681,11 @@ sub get_colors {
 	if (system("tput sgr0 >/dev/null 2>&1") == 0 &&
 	    system("tput bold >/dev/null 2>&1") == 0 &&
 	    system("tput rev  >/dev/null 2>&1") == 0 &&
+	    system("tput dim  >/dev/null 2>&1") == 0 &&
 	    system("tput setaf 1 >/dev/null 2>&1") == 0) {
 		%COLORS = (bold  => `tput bold`,
 			   rev   => `tput rev`,
+			   dim   => `tput dim`,
 			   reset => `tput sgr0`,
 			   blue  => `tput setaf 4`,
 			   green => `tput setaf 2`,
-- 
gitgitgadget

  parent reply	other threads:[~2022-11-09 17:01 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-11-09 16:58 [PATCH 0/3] chainlint: emit line numbers alongside test definitions Eric Sunshine via GitGitGadget
2022-11-09 16:58 ` [PATCH 1/3] chainlint: sidestep impoverished macOS "terminfo" Eric Sunshine via GitGitGadget
2022-11-09 22:18   ` Taylor Blau
2022-11-10  2:40   ` brian m. carlson
2022-11-10  3:37     ` Eric Sunshine
2022-11-10 22:21       ` brian m. carlson
2022-11-10 22:36         ` Eric Sunshine
2022-11-10 22:48           ` brian m. carlson
2022-11-09 16:58 ` [PATCH 2/3] chainlint: latch line numbers at which each token starts and ends Eric Sunshine via GitGitGadget
2022-11-09 16:58 ` Eric Sunshine via GitGitGadget [this message]
2022-11-09 22:22 ` [PATCH 0/3] chainlint: emit line numbers alongside test definitions Taylor Blau
2022-11-11  7:34 ` [PATCH v2 " Eric Sunshine via GitGitGadget
2022-11-11  7:34   ` [PATCH v2 1/3] chainlint: sidestep impoverished macOS "terminfo" Eric Sunshine via GitGitGadget
2022-11-11 14:55     ` Ævar Arnfjörð Bjarmason
2022-11-11 16:44       ` Eric Sunshine
2022-11-11 17:15         ` Eric Sunshine
2022-11-11 21:56           ` Taylor Blau
2022-11-11  7:34   ` [PATCH v2 2/3] chainlint: latch line numbers at which each token starts and ends Eric Sunshine via GitGitGadget
2022-11-11  7:34   ` [PATCH v2 3/3] chainlint: prefix annotated test definition with line numbers Eric Sunshine via GitGitGadget
2022-11-11 15:03 ` [PATCH 0/3] chainlint: emit line numbers alongside test definitions Æ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=380b146abd1d97d51511c7acd11ffb99d1affcc6.1668013114.git.gitgitgadget@gmail.com \
    --to=gitgitgadget@gmail.com \
    --cc=avarab@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=peff@peff.net \
    --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).