Skip to content

Commit 48d69d8

Browse files
sunshinecottaylorr
authored andcommitted
chainlint: prefix annotated test definition with line numbers
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 <[email protected]> Signed-off-by: Eric Sunshine <[email protected]> Signed-off-by: Taylor Blau <[email protected]>
1 parent bf42f0a commit 48d69d8

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

t/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ check-chainlint:
9494
done \
9595
} >'$(CHAINLINTTMP_SQ)'/expect && \
9696
$(CHAINLINT) --emit-all '$(CHAINLINTTMP_SQ)'/tests | \
97-
grep -v '^[ ]*$$' >'$(CHAINLINTTMP_SQ)'/actual && \
97+
sed -e 's/^[1-9][0-9]* //;/^[ ]*$$/d' >'$(CHAINLINTTMP_SQ)'/actual && \
9898
if test -f ../GIT-BUILD-OPTIONS; then \
9999
. ../GIT-BUILD-OPTIONS; \
100100
fi && \

t/chainlint.pl

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -614,6 +614,7 @@ sub check_test {
614614
my $problems = $parser->{problems};
615615
return unless $emit_all || @$problems;
616616
my $c = main::fd_colors(1);
617+
my $lineno = $_[1]->[3];
617618
my $start = 0;
618619
my $checked = '';
619620
for (sort {$a->[1]->[2] <=> $b->[1]->[2]} @$problems) {
@@ -623,10 +624,12 @@ sub check_test {
623624
$start = $pos;
624625
}
625626
$checked .= substr($body, $start);
626-
$checked =~ s/^\n//;
627+
$checked =~ s/^/$lineno++ . ' '/mge;
628+
$checked =~ s/^\d+ \n//;
627629
$checked =~ s/(\s) \?!/$1?!/mg;
628630
$checked =~ s/\?! (\s)/?!$1/mg;
629631
$checked =~ s/(\?![^?]+\?!)/$c->{rev}$c->{red}$1$c->{reset}/mg;
632+
$checked =~ s/^\d+/$c->{dim}$&$c->{reset}/mg;
630633
$checked .= "\n" unless $checked =~ /\n$/;
631634
push(@{$self->{output}}, "$c->{blue}# chainlint: $title$c->{reset}\n$checked");
632635
}
@@ -658,7 +661,7 @@ package main;
658661
# thread and ignore %ENV changes in subthreads.
659662
$ENV{TERM} = $ENV{USER_TERM} if $ENV{USER_TERM};
660663

661-
my @NOCOLORS = (bold => '', rev => '', reset => '', blue => '', green => '', red => '');
664+
my @NOCOLORS = (bold => '', rev => '', dim => '', reset => '', blue => '', green => '', red => '');
662665
my %COLORS = ();
663666
sub get_colors {
664667
return \%COLORS if %COLORS;
@@ -669,6 +672,7 @@ sub get_colors {
669672
if ($ENV{TERM} =~ /xterm|xterm-\d+color|xterm-new|xterm-direct|nsterm|nsterm-\d+color|nsterm-direct/) {
670673
%COLORS = (bold => "\e[1m",
671674
rev => "\e[7m",
675+
dim => "\e[2m",
672676
reset => "\e[0m",
673677
blue => "\e[34m",
674678
green => "\e[32m",
@@ -678,9 +682,11 @@ sub get_colors {
678682
if (system("tput sgr0 >/dev/null 2>&1") == 0 &&
679683
system("tput bold >/dev/null 2>&1") == 0 &&
680684
system("tput rev >/dev/null 2>&1") == 0 &&
685+
system("tput dim >/dev/null 2>&1") == 0 &&
681686
system("tput setaf 1 >/dev/null 2>&1") == 0) {
682687
%COLORS = (bold => `tput bold`,
683688
rev => `tput rev`,
689+
dim => `tput dim`,
684690
reset => `tput sgr0`,
685691
blue => `tput setaf 4`,
686692
green => `tput setaf 2`,

0 commit comments

Comments
 (0)