]> git.ipfire.org Git - thirdparty/git.git/commitdiff
chainlint: prefix annotated test definition with line numbers
authorEric Sunshine <sunshine@sunshineco.com>
Fri, 11 Nov 2022 07:34:54 +0000 (07:34 +0000)
committerTaylor Blau <me@ttaylorr.com>
Fri, 11 Nov 2022 21:56:21 +0000 (16:56 -0500)
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>
Signed-off-by: Taylor Blau <me@ttaylorr.com>
t/Makefile
t/chainlint.pl

index 882782a519c97b65d2a6d487ac6849a540015fe4..2c2b2522402d087bee89ae8c08be99449c893057 100644 (file)
@@ -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 && \
index 67c2c5ebee89ee32e4f5b423ef7cb560aae141a0..4e47e808d017c274b3fecc39ad6f7fe7026ae257 100755 (executable)
@@ -614,6 +614,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) {
@@ -623,10 +624,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");
 }
@@ -658,7 +661,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;
@@ -669,6 +672,7 @@ sub get_colors {
        if ($ENV{TERM} =~ /xterm|xterm-\d+color|xterm-new|xterm-direct|nsterm|nsterm-\d+color|nsterm-direct/) {
                %COLORS = (bold  => "\e[1m",
                           rev   => "\e[7m",
+                          dim   => "\e[2m",
                           reset => "\e[0m",
                           blue  => "\e[34m",
                           green => "\e[32m",
@@ -678,9 +682,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`,