From patchwork Fri Nov 11 07:34:52 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Sunshine X-Patchwork-Id: 13039771 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id B660BC4332F for ; Fri, 11 Nov 2022 07:35:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233030AbiKKHfC (ORCPT ); Fri, 11 Nov 2022 02:35:02 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57600 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232890AbiKKHe7 (ORCPT ); Fri, 11 Nov 2022 02:34:59 -0500 Received: from mail-wr1-x42c.google.com (mail-wr1-x42c.google.com [IPv6:2a00:1450:4864:20::42c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 91C6579D18 for ; Thu, 10 Nov 2022 23:34:58 -0800 (PST) Received: by mail-wr1-x42c.google.com with SMTP id k8so5376967wrh.1 for ; Thu, 10 Nov 2022 23:34:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date:from :references:in-reply-to:message-id:from:to:cc:subject:date :message-id:reply-to; bh=KVRCA/Vj3iWfP1v51N/p0YliwQJxjrjjB8kuWpuvQbk=; b=lKZqFz+lmBLmjJh4w5RC5ockoD9HL8rfqCHcmVv0O7/GrZmqXsEvxuqZJ9fVQ6p2CH VIQ1o2xstrNdnnY4k6A/iBmXsK4zYlLoCAnHntwmPqLUxxdIaBqiec4Gq2hIfAMVz9JY vYEdFPkB0+gBVkYH3DTDT8SMPj0IMoOJFF+TOwK+JvvMbO7aMa3TdeHc4zjioG1g5YbU /WGkwq2ehS33Y8ZkEdqZCu7cZVuLmaQ50OJEwgdKvrgWMyZrqBJARngOf/AXviGbbZN3 5Yld3bDLNBPnDF/NDXle73xw4J6QrLX/5RU0cy5yfTgEgvBEpzt2HUg0BT0Dt7vc4MTq Gsiw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date:from :references:in-reply-to:message-id:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=KVRCA/Vj3iWfP1v51N/p0YliwQJxjrjjB8kuWpuvQbk=; b=RTToDfGdBJ18D6uTXQJNWXjvpqcoi2sIew6m9RVr7kHnY2ArioqgBSOXPDZHlhOZkR O7evdj7n0ShEn4AQb6JxgBV8NcGurufqSQKIeLEy2wfzgXLifLEaGPiA2++fAU0c7wel B07fAujh/mZVJ6AVca1Q2ctNnPkWacO80feywMN9cXHPGO8/zZ3dtmMxvtun6Q667gBp jjVJOt65BScl3NneDred25XK0X7Q8+vH74DBTt+5c8Pvr5MCeC/zyXi60ygGg7tXpFm2 KpERXiRaZX868FkHypclabXnYUmMGocNKvOZedyekBVMNMTap4VEv5l3xdKPLAR41egD mmmA== X-Gm-Message-State: ANoB5pl996LdHbEGzn3ByQl/KWL1lEaL9org0TRciQAIiMv+Mzxh6SfT GXlmnbLuAjYGETDP/W7oaFH4gaVJejY= X-Google-Smtp-Source: AA0mqf6f1G6g473YrELyA2W+5voFGtWe7XmIW7XUsMeqOhBBtV149OQxDGvKikNPt0lmTj9Iqp8mPQ== X-Received: by 2002:a05:6000:4d:b0:236:4ba1:fb2c with SMTP id k13-20020a056000004d00b002364ba1fb2cmr463510wrx.431.1668152096928; Thu, 10 Nov 2022 23:34:56 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id n9-20020a7bcbc9000000b003b47ff307e1sm1918910wmi.31.2022.11.10.23.34.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Nov 2022 23:34:56 -0800 (PST) Message-Id: In-Reply-To: References: Date: Fri, 11 Nov 2022 07:34:52 +0000 Subject: [PATCH v2 1/3] chainlint: sidestep impoverished macOS "terminfo" Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Jeff King , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsA==?= Bjarmason , Taylor Blau , "brian m. carlson" , Eric Sunshine , Eric Sunshine Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Eric Sunshine From: Eric Sunshine Although the macOS Terminal.app is "xterm"-compatible, its corresponding "terminfo" entries -- such as "xterm", "xterm-256color", and "xterm-new"[1] -- neglect to mention capabilities which Terminal.app actually supports (such as "dim text"). This oversight on Apple's part ends up penalizing users of "good citizen" console programs which consult "terminfo" to tailor their output based upon reported terminal capabilities (as opposed to programs which assume that the terminal supports ANSI codes). The same problem is present in other Apple "terminfo" entries, such as "nsterm"[2], with which macOS Terminal.app may be configured. Sidestep this Apple problem by imbuing get_colors() with specific knowledge of capabilities common to "xterm" and "nsterm", rather than trusting "terminfo" to report them correctly. Although hard-coding such knowledge is ugly, "xterm" support is nearly ubiquitous these days, and Git itself sets precedence by assuming support for ANSI color codes. For other terminal types, fall back to querying "terminfo" via `tput` as usual. FOOTNOTES [1] iTerm2 FAQ suggests "xterm-new": https://iterm2.com/faq.html [2] Neovim documentation recommends terminal type "nsterm" with Terminal.app: https://neovim.io/doc/user/term.html#terminfo Signed-off-by: Eric Sunshine --- t/chainlint.pl | 35 +++++++++++++++++++++++------------ 1 file changed, 23 insertions(+), 12 deletions(-) diff --git a/t/chainlint.pl b/t/chainlint.pl index 7972c5bbe6f..0ee5cc36437 100755 --- a/t/chainlint.pl +++ b/t/chainlint.pl @@ -653,21 +653,32 @@ my @NOCOLORS = (bold => '', rev => '', 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 rev >/dev/null 2>&1") != 0 || - system("tput setaf 1 >/dev/null 2>&1") != 0) { + if (exists($ENV{NO_COLOR})) { %COLORS = @NOCOLORS; return \%COLORS; } - %COLORS = (bold => `tput bold`, - rev => `tput rev`, - reset => `tput sgr0`, - blue => `tput setaf 4`, - green => `tput setaf 2`, - red => `tput setaf 1`); - chomp(%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", + reset => "\e[0m", + blue => "\e[34m", + green => "\e[32m", + red => "\e[31m"); + return \%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 setaf 1 >/dev/null 2>&1") == 0) { + %COLORS = (bold => `tput bold`, + rev => `tput rev`, + reset => `tput sgr0`, + blue => `tput setaf 4`, + green => `tput setaf 2`, + red => `tput setaf 1`); + return \%COLORS; + } + %COLORS = @NOCOLORS; return \%COLORS; } From patchwork Fri Nov 11 07:34:53 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Sunshine X-Patchwork-Id: 13039772 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5486AC433FE for ; Fri, 11 Nov 2022 07:35:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233074AbiKKHfE (ORCPT ); Fri, 11 Nov 2022 02:35:04 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57600 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232949AbiKKHfA (ORCPT ); Fri, 11 Nov 2022 02:35:00 -0500 Received: from mail-wm1-x32e.google.com (mail-wm1-x32e.google.com [IPv6:2a00:1450:4864:20::32e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7EFBE79D12 for ; Thu, 10 Nov 2022 23:34:59 -0800 (PST) Received: by mail-wm1-x32e.google.com with SMTP id v124-20020a1cac82000000b003cf7a4ea2caso5021895wme.5 for ; Thu, 10 Nov 2022 23:34:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date:from :references:in-reply-to:message-id:from:to:cc:subject:date :message-id:reply-to; bh=s9hQJpAEXF7ETyJBJagD4laIajYoDDRzBHFa3WSzqUw=; b=QZT68IStd0h7dK0SFZ9ZAI3o6tk8VJ4zHrBwrVZKIDCFALoNXjltFEZdilooqpwslJ Lou/B9+jBoT0KmEXvvpN4LvYjLHpT+6v1CmaenK+ykA52KOURJpd2/7U/8SiJNXHO5Uj PGAcDK4Uu8zLYKDJtsujy3YlDbKvjoAf0FWqduIl1uB3el/Xj0oQf8kR3YZ7n5Ggy3yb 2EGPnFBBxrv1sVh8NePIx7PU0y7bgocJHmqNYmlf218nTXf/R1uTZgzo4/rcZK/dPfX2 2X4VX9m6cxlSalZrcNbHCF5l8kGovwoGnMOJ1k7K2YQBcjNcVaU1viVNJIcweyh+TtWg X/Mw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date:from :references:in-reply-to:message-id:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=s9hQJpAEXF7ETyJBJagD4laIajYoDDRzBHFa3WSzqUw=; b=8BaxsCob4Dm2gEcoxMIrM0S5uqctbd1pnLwSwxJf9jIKg1LRsfNCYXBbOkxTRCuQWv p3M3LpPkY5F/zzVDoGIZ5pegkorahQ5n7fdHuk1rAon3YeTl7zDZ6Qlo2PucafRlp3DO 79pLeYPfislQwCnnNLJvzO8mJYipQKJ1t/C9/OltDcLzL9F/+cHBVZX0hpJOrSTLWzPa 329B/ui1qoDy+jCnlObone9RiwNCUsNfwoiH+PuBq7h5FGuCU3yvwGT19+Qo2AGsDvdB 32k1kvKgrf/nTGlLpcbGiDcEG6dRRUd37u+iwa3p7pBnErjcYDaCPinNSIGRkJhSFtFC eOhA== X-Gm-Message-State: ANoB5plq3xjDgi62h+2BhTw7A/bZ9/5+mUrgoQMIGc/c63qN40Gh7PKb VKgX6uYWegA1VwldGvCqFoD8/vQxEBg= X-Google-Smtp-Source: AA0mqf4EhsZtVkke/fCpl3KUGQoIDPnyifpklOOwX7Ol8aY9iaJq8v5h0+RlXTHLFvpYUsHygEa0FA== X-Received: by 2002:a05:600c:1ca1:b0:3cf:ca91:7094 with SMTP id k33-20020a05600c1ca100b003cfca917094mr361951wms.24.1668152097735; Thu, 10 Nov 2022 23:34:57 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id z8-20020adfec88000000b00236722ebe66sm1158054wrn.75.2022.11.10.23.34.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Nov 2022 23:34:57 -0800 (PST) Message-Id: <84ddc6707fb0fd5e1be675ba587e453c55a76acc.1668152094.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Fri, 11 Nov 2022 07:34:53 +0000 Subject: [PATCH v2 2/3] chainlint: latch line numbers at which each token starts and ends Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Jeff King , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsA==?= Bjarmason , Taylor Blau , "brian m. carlson" , Eric Sunshine , Eric Sunshine Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Eric Sunshine From: Eric Sunshine 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, an upcoming change will display line numbers along with the annotated test definition, thus allowing the author to jump directly to each problematic line. As preparation, upgrade Lexer to latch the line numbers at which each token starts and ends, and return that information with the token itself. Signed-off-by: Eric Sunshine --- t/chainlint.pl | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/t/chainlint.pl b/t/chainlint.pl index 0ee5cc36437..67c2c5ebee8 100755 --- a/t/chainlint.pl +++ b/t/chainlint.pl @@ -67,6 +67,7 @@ sub new { bless { parser => $parser, buff => $s, + lineno => 1, heretags => [] } => $class; } @@ -97,7 +98,9 @@ sub scan_op { sub scan_sqstring { my $self = shift @_; ${$self->{buff}} =~ /\G([^']*'|.*\z)/sgc; - return "'" . $1; + my $s = $1; + $self->{lineno} += () = $s =~ /\n/sg; + return "'" . $s; } sub scan_dqstring { @@ -115,7 +118,7 @@ sub scan_dqstring { if ($c eq '\\') { $s .= '\\', last unless $$b =~ /\G(.)/sgc; $c = $1; - next if $c eq "\n"; # line splice + $self->{lineno}++, next if $c eq "\n"; # line splice # backslash escapes only $, `, ", \ in dq-string $s .= '\\' unless $c =~ /^[\$`"\\]$/; $s .= $c; @@ -123,6 +126,7 @@ sub scan_dqstring { } die("internal error scanning dq-string '$c'\n"); } + $self->{lineno} += () = $s =~ /\n/sg; return $s; } @@ -137,6 +141,7 @@ sub scan_balanced { $depth--; last if $depth == 0; } + $self->{lineno} += () = $s =~ /\n/sg; return $s; } @@ -163,8 +168,11 @@ sub swallow_heredocs { my $b = $self->{buff}; my $tags = $self->{heretags}; while (my $tag = shift @$tags) { + my $start = pos($$b); my $indent = $tag =~ s/^\t// ? '\\s*' : ''; $$b =~ /(?:\G|\n)$indent\Q$tag\E(?:\n|\z)/gc; + my $body = substr($$b, $start, pos($$b) - $start); + $self->{lineno} += () = $body =~ /\n/sg; } } @@ -172,11 +180,12 @@ sub scan_token { my $self = shift @_; my $b = $self->{buff}; my $token = ''; - my $start; + my ($start, $startln); RESTART: + $startln = $self->{lineno}; $$b =~ /\G[ \t]+/gc; # skip whitespace (but not newline) $start = pos($$b) || 0; - return ["\n", $start, pos($$b)] if $$b =~ /\G#[^\n]*(?:\n|\z)/gc; # comment + $self->{lineno}++, return ["\n", $start, pos($$b), $startln, $startln] if $$b =~ /\G#[^\n]*(?:\n|\z)/gc; # comment while (1) { # slurp up non-special characters $token .= $1 if $$b =~ /\G([^\\;&|<>(){}'"\$\s]+)/gc; @@ -188,20 +197,20 @@ RESTART: $token .= $self->scan_sqstring(), next if $c eq "'"; $token .= $self->scan_dqstring(), next if $c eq '"'; $token .= $c . $self->scan_dollar(), next if $c eq '$'; - $self->swallow_heredocs(), $token = $c, last if $c eq "\n"; + $self->{lineno}++, $self->swallow_heredocs(), $token = $c, last if $c eq "\n"; $token = $self->scan_op($c), last if $c =~ /^[;&|<>]$/; $token = $c, last if $c =~ /^[(){}]$/; if ($c eq '\\') { $token .= '\\', last unless $$b =~ /\G(.)/sgc; $c = $1; - next if $c eq "\n" && length($token); # line splice - goto RESTART if $c eq "\n"; # line splice + $self->{lineno}++, next if $c eq "\n" && length($token); # line splice + $self->{lineno}++, goto RESTART if $c eq "\n"; # line splice $token .= '\\' . $c; next; } die("internal error scanning character '$c'\n"); } - return length($token) ? [$token, $start, pos($$b)] : undef; + return length($token) ? [$token, $start, pos($$b), $startln, $self->{lineno}] : undef; } # ShellParser parses POSIX shell scripts (with minor extensions for Bash). It From patchwork Fri Nov 11 07:34:54 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Eric Sunshine X-Patchwork-Id: 13039773 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 08CE9C433FE for ; Fri, 11 Nov 2022 07:35:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233117AbiKKHfG (ORCPT ); Fri, 11 Nov 2022 02:35:06 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57600 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232985AbiKKHfB (ORCPT ); Fri, 11 Nov 2022 02:35:01 -0500 Received: from mail-wr1-x433.google.com (mail-wr1-x433.google.com [IPv6:2a00:1450:4864:20::433]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5267579D18 for ; Thu, 10 Nov 2022 23:35:00 -0800 (PST) Received: by mail-wr1-x433.google.com with SMTP id bs21so5357637wrb.4 for ; Thu, 10 Nov 2022 23:35:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=cc:to:fcc:content-transfer-encoding:mime-version:subject:date:from :references:in-reply-to:message-id:from:to:cc:subject:date :message-id:reply-to; bh=s6FCyrFXbh3obm2y4A9Slp4FVhb+lEF3leBe8lle/Y0=; b=LGFlCIeZ9iXFwRCt0ZPUrwUvrfJAvJCrVurXDQFjmCTqdPVUY7B0Zh480dV3+NbyYj UQ+NGKOfQWaYTFARLZvJZbhXHrU/PkxU6czoekUvQO6VBS3PRJT912u82NWRwWB+LTcq ELUurF7S2UJKbIfpMczIbjAA+u6r5zHNGOO0lHR1i3nnu69ky8ZHnXxS+6prMXF+gpg0 6X1SexsVQj+nLkLa7KCEAiN2Fj4O5wh8799LFIm1X7lPhQnLTt0iq1udHn2PtgrNOTjd gCNCr67VihCAQZXC+kuSyntkc6Kp33kVorLL6eSbogZEE8t5M55xApxJCtdvfNQlG177 2/fg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:fcc:content-transfer-encoding:mime-version:subject:date:from :references:in-reply-to:message-id:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=s6FCyrFXbh3obm2y4A9Slp4FVhb+lEF3leBe8lle/Y0=; b=JnI8CDAmovoQm6+ARy09S1O86DX/IpkTlYv9EcmWGIrO9NP3wspUUjj6uwSV27J51h P5JiTCueueKuzp5J9AL+/THBFl31hxKqVBNDgVctnBVnDhNqj0tPzzxGKg1XIkZkRcvF l/qIFTQDz8bS3L8HfFNZG37WRXivqPeZD0jhSX4yyc8caMMTjTKMDeDdeJagryGMugsW oo37MonxHyjfT7eQe+CRQuH4FKNaZ1A6BAImXnxeP53sTqSsFj2XC6t4OOfj4Xs+Ytpa pFg3GlctH22x8u3YZZFrxvAseGlySTmnuYxWfyOseyrNINmmzXlwmZuQxg/Rpun4aP18 a5Tg== X-Gm-Message-State: ANoB5pmNXnjyr81wHqRaALHX6OzTOQQBfInrYM8CTJPn205o9pi1gJ3S f/YHc1Y2ar71jT6YSqJ1/AWNxhAv5Ns= X-Google-Smtp-Source: AA0mqf6NX5OmofQBYt19mRz/bjLKY6gacCD3Soozi9xJ7rCFZN143QL6bNjP8eJGeW8eagjId3kEDg== X-Received: by 2002:adf:fb01:0:b0:22e:5291:c4b0 with SMTP id c1-20020adffb01000000b0022e5291c4b0mr435378wrr.449.1668152098605; Thu, 10 Nov 2022 23:34:58 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id k7-20020a05600c1c8700b003c6b7f5567csm11845323wms.0.2022.11.10.23.34.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Nov 2022 23:34:58 -0800 (PST) Message-Id: <3cb4ff4d330acf0f6feaa53c499d1931cc793dc6.1668152094.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Fri, 11 Nov 2022 07:34:54 +0000 Subject: [PATCH v2 3/3] chainlint: prefix annotated test definition with line numbers MIME-Version: 1.0 Fcc: Sent To: git@vger.kernel.org Cc: Jeff King , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsA==?= Bjarmason , Taylor Blau , "brian m. carlson" , Eric Sunshine , Eric Sunshine Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Eric Sunshine From: Eric Sunshine 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 Signed-off-by: Eric Sunshine --- 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 67c2c5ebee8..4e47e808d01 100755 --- a/t/chainlint.pl +++ b/t/chainlint.pl @@ -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`,