From patchwork Mon Dec 13 06:30:45 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Sunshine X-Patchwork-Id: 12673105 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 8E127C433F5 for ; Mon, 13 Dec 2021 06:32:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232224AbhLMGcA (ORCPT ); Mon, 13 Dec 2021 01:32:00 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40074 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232222AbhLMGb7 (ORCPT ); Mon, 13 Dec 2021 01:31:59 -0500 Received: from mail-io1-xd35.google.com (mail-io1-xd35.google.com [IPv6:2607:f8b0:4864:20::d35]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C7DD5C06173F for ; Sun, 12 Dec 2021 22:31:59 -0800 (PST) Received: by mail-io1-xd35.google.com with SMTP id x6so17196259iol.13 for ; Sun, 12 Dec 2021 22:31:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=qjmiBxNJ14WLAMJ69Bk7Mc2PPGKV1OaRxla+zsh+NhY=; b=X9Hm9Il2UEVSO3Xw6cl32F4DI+wNsqFaWTki08pAmsquegPgOIMz4zLImhWPDYLq+x XyUSyNHtnLFr4F/1e1PvnbZ+SdUpbEniw/+z9cTYNdB0hKVvq6zQAgEjP78sioGkLpZV qlTTF6n94WZrgUb7E/f6+2AS3sq79+tCgyNmYxaeqWWiDN/vJh2Mr4AdP5U2RAEhreK8 Uipc+gXQfp2EsL36wFOQTH4oov2mmuS804+/ACCXoIkjpZhPg2gEEJQBpLFGfBlK7VSc XYSo48fjA9ejW0ciEAMsKZsdGwf8ryEuAt4Uyyn2NIsxFu7UBHh5/zcCtvPFtpYPiTiO hnRQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=qjmiBxNJ14WLAMJ69Bk7Mc2PPGKV1OaRxla+zsh+NhY=; b=FZCfWhnwbQ/gWYbWA+e2qarvJ6vacOGxHwaUzyikxO4sRu/MlsXMCAPyRubQZEGoMv vR1APIai9RKcTUZs+7D1JuDyxE2NIL2avaZH/TLaXiUrpZVOTlSDl4iMp5fGkGCjWWFc ZmDFwHiHlPEDdd0uKeM/N0tfBI7EtFejYHFmIflmeQNNz3Cy0XJEs35N0eqHGQMYBiEA 3pStq517nOcRsbwt+i4oKZadTB3bj2Qjf0/7j72o5D5sfexMK+CcsF/Pz4tO7kLuPY0f 7h9aGOaQwVrxc7JpdWE53BDY8p2UfNTwMaelSmJbol+uVMkarNe/W2Mp3fWZZCyKExZ5 vfgQ== X-Gm-Message-State: AOAM530tNTZsjYGZ3Vs5h3LpaND61LCulnYdo3pS99Q5+ukdAPV3tXKJ Pn1QnTxG9gWIQrz+jG6OuWwO6nTZJ/dx4w== X-Google-Smtp-Source: ABdhPJxDWvyY3Pxsf4biiRORuuLeKPXXU8obtR+yftojZGdRO8U7OdkaXUFa3zPIOXe2hLgkLom1eQ== X-Received: by 2002:a05:6602:1813:: with SMTP id t19mr31705144ioh.135.1639377118926; Sun, 12 Dec 2021 22:31:58 -0800 (PST) Received: from localhost.localdomain (097-069-216-153.res.spectrum.com. [97.69.216.153]) by smtp.gmail.com with ESMTPSA id f10sm7305408ils.13.2021.12.12.22.31.58 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sun, 12 Dec 2021 22:31:58 -0800 (PST) Sender: Eric Sunshine From: Eric Sunshine To: git@vger.kernel.org Cc: Jeff King , Elijah Newren , Fabian Stelzer , Eric Sunshine Subject: [PATCH 01/15] t/chainlint/*.test: don't use invalid shell syntax Date: Mon, 13 Dec 2021 01:30:45 -0500 Message-Id: <20211213063059.19424-2-sunshine@sunshineco.com> X-Mailer: git-send-email 2.34.1.397.gfae76fe5da In-Reply-To: <20211213063059.19424-1-sunshine@sunshineco.com> References: <20211213063059.19424-1-sunshine@sunshineco.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org The chainlint self-test code snippets are supposed to represent the body of a test_expect_success() or test_expect_failure(), yet the contents of these tests would have caused the shell to report syntax errors had they been real test bodies. Although chainlint.sed, with its simplistic heuristics, is blind to these syntactic problems, a future more robust chainlint implementation might not have such a limitation, so make these snippets syntactically valid. Signed-off-by: Eric Sunshine --- t/chainlint/if-then-else.expect | 5 +++-- t/chainlint/if-then-else.test | 3 ++- t/chainlint/subshell-here-doc.test | 2 +- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/t/chainlint/if-then-else.expect b/t/chainlint/if-then-else.expect index 5953c7bfbc..a80f5e6c75 100644 --- a/t/chainlint/if-then-else.expect +++ b/t/chainlint/if-then-else.expect @@ -4,6 +4,7 @@ ?!AMP?! echo very echo empty elif test -z "" + then echo foo else echo foo && @@ -14,6 +15,6 @@ ( if test -n ""; then echo very && -?!AMP?! echo empty - if + echo empty + fi >) diff --git a/t/chainlint/if-then-else.test b/t/chainlint/if-then-else.test index 9bd8e9a4c6..d2b03ca6b4 100644 --- a/t/chainlint/if-then-else.test +++ b/t/chainlint/if-then-else.test @@ -7,6 +7,7 @@ # LINT: last statement before 'elif' does not need "&&" echo empty elif test -z "" + then # LINT: last statement before 'else' does not need "&&" echo foo else @@ -24,5 +25,5 @@ if test -n ""; then echo very && echo empty - if + fi ) diff --git a/t/chainlint/subshell-here-doc.test b/t/chainlint/subshell-here-doc.test index f6b3ba4214..0cce907ba8 100644 --- a/t/chainlint/subshell-here-doc.test +++ b/t/chainlint/subshell-here-doc.test @@ -11,7 +11,7 @@ # LINT: missing "&&" on 'cat' cat <bip fish fly high - EOF +EOF # LINT: swallow here-doc (EOF is last line of subshell) echo <<-\EOF >bop From patchwork Mon Dec 13 06:30:46 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Sunshine X-Patchwork-Id: 12673109 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 3A6E0C433FE for ; Mon, 13 Dec 2021 06:32:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232239AbhLMGcE (ORCPT ); Mon, 13 Dec 2021 01:32:04 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40080 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232225AbhLMGcA (ORCPT ); Mon, 13 Dec 2021 01:32:00 -0500 Received: from mail-io1-xd2e.google.com (mail-io1-xd2e.google.com [IPv6:2607:f8b0:4864:20::d2e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7D19CC06173F for ; Sun, 12 Dec 2021 22:32:00 -0800 (PST) Received: by mail-io1-xd2e.google.com with SMTP id p65so17396935iof.3 for ; Sun, 12 Dec 2021 22:32:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=GK02UCuwR4lVt8dksekV0yRcVjCUg5ZVJU88r2THo/4=; b=ovjRX0FIsaBTwQrxWAZUQqsdNMSAOzo1SKwTPO34MptmJJuYrxivWXzZGs7fV/83TT BuasXlsxwf30gCmCmsApjgKlNASgAxENNWPcYhDMbPIsovG2AjAggtydxLSV1IFddlSk hwZskYlafpgT0YjPY1fX+qpsQKYeXqSc3io2/V29C/tuQ8YTvvrOiCyCwaXAxabpU2Tb YhZJ/5L0VOaoQKCYh1aDV153Eti3voc91LuNGv8+TKo9y/XyXc3rMH/cuNSo9qespinF NpWK70ZJdR2AyvbFTZRfThpnCvc2tqhJhixcaz0ZwNaLpv83SL1KUncqCtg1WczoKyqX ZnBw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=GK02UCuwR4lVt8dksekV0yRcVjCUg5ZVJU88r2THo/4=; b=PcYrWuOp4kDVoy5Gr0SgIBwfh9xFVJrFswEwN379qJhG4BYiO9Ki3WDlIt3cL09rEr GHNM66Kx0npg5LAlmot6KNaXcaPAL1XNowNglLu6VU4r+3OCgbWe0db3zXBycX3vgQa9 8SVK8NIEEoHHPjncroc71jrFcUf1AnFZZ6765jSailEJPBM8uHjK9nhO145OKHUjd0ZR tlN14FPw2HiL4eBwL/ejSTLq8E+nrqBHPqVpZva7bDV5QnihdsgjRym76rWlLtaNxHfT mpD5gMNvuq+7jV0GXjTmkFfaz+b3ySbCsybrAvfToa7PZsKi/tgGBsBJjqi7RxrMn+Y+ Aw7g== X-Gm-Message-State: AOAM530sHINBQWTrftRd6rFQCzgPDyLgM3/CCQPbmExCw4999Xw5GKFy 5vPZHfLwII4TzTvlwVeKbzt5GbY1FD7YlA== X-Google-Smtp-Source: ABdhPJwCpKJhhMqc+9AT7lz4+LZivqVXlTYMmCwI7TcRg/av2BJgulNYb7fL0WIO9+qy6zm+f0LyGg== X-Received: by 2002:a02:6d41:: with SMTP id e1mr30742410jaf.74.1639377119634; Sun, 12 Dec 2021 22:31:59 -0800 (PST) Received: from localhost.localdomain (097-069-216-153.res.spectrum.com. [97.69.216.153]) by smtp.gmail.com with ESMTPSA id f10sm7305408ils.13.2021.12.12.22.31.58 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sun, 12 Dec 2021 22:31:59 -0800 (PST) Sender: Eric Sunshine From: Eric Sunshine To: git@vger.kernel.org Cc: Jeff King , Elijah Newren , Fabian Stelzer , Eric Sunshine Subject: [PATCH 02/15] t/chainlint/*.test: fix invalid test cases due to mixing quote types Date: Mon, 13 Dec 2021 01:30:46 -0500 Message-Id: <20211213063059.19424-3-sunshine@sunshineco.com> X-Mailer: git-send-email 2.34.1.397.gfae76fe5da In-Reply-To: <20211213063059.19424-1-sunshine@sunshineco.com> References: <20211213063059.19424-1-sunshine@sunshineco.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org The chainlint self-test code snippets are supposed to represent the body of a test_expect_success() or test_expect_failure(), yet the contents of a few tests would have caused the shell to report syntax errors had they been real test bodies due to the mix of single- and double-quotes. Although chainlint.sed, with its simplistic heuristics, is blind to this problem, a future more robust chainlint implementation might not have such a limitation. Therefore, stop mixing quote types haphazardly in those tests and unify quoting throughout. While at it, drop chunks of tests which merely repeat what is already tested elsewhere but with alternative quotes. Signed-off-by: Eric Sunshine --- t/chainlint/broken-chain.test | 2 +- t/chainlint/case.test | 6 +++--- t/chainlint/complex-if-in-cuddled-loop.test | 2 +- t/chainlint/cuddled-if-then-else.test | 2 +- t/chainlint/cuddled-loop.test | 2 +- t/chainlint/for-loop.test | 8 ++++---- t/chainlint/here-doc.expect | 2 -- t/chainlint/here-doc.test | 7 ------- t/chainlint/if-in-loop.test | 6 +++--- t/chainlint/if-then-else.test | 14 +++++++------- t/chainlint/loop-in-if.test | 6 +++--- t/chainlint/multi-line-string.expect | 8 +------- t/chainlint/multi-line-string.test | 16 ++-------------- t/chainlint/nested-subshell-comment.test | 2 +- t/chainlint/pipe.test | 2 +- t/chainlint/subshell-here-doc.expect | 1 - t/chainlint/subshell-here-doc.test | 6 +----- t/chainlint/t7900-subtree.expect | 4 ++-- t/chainlint/t7900-subtree.test | 4 ++-- t/chainlint/while-loop.test | 8 ++++---- 20 files changed, 38 insertions(+), 70 deletions(-) diff --git a/t/chainlint/broken-chain.test b/t/chainlint/broken-chain.test index 3cc67b65d0..2a44aa73b7 100644 --- a/t/chainlint/broken-chain.test +++ b/t/chainlint/broken-chain.test @@ -1,6 +1,6 @@ ( foo && -# LINT: missing "&&" from 'bar' +# LINT: missing "&&" from "bar" bar baz && # LINT: final statement before closing ")" legitimately lacks "&&" diff --git a/t/chainlint/case.test b/t/chainlint/case.test index 5ef6ff7db5..4cb086bf87 100644 --- a/t/chainlint/case.test +++ b/t/chainlint/case.test @@ -1,5 +1,5 @@ ( -# LINT: "...)" arms in 'case' not misinterpreted as subshell-closing ")" +# LINT: "...)" arms in "case" not misinterpreted as subshell-closing ")" case "$x" in x) foo ;; *) bar ;; @@ -7,7 +7,7 @@ foobar ) && ( -# LINT: missing "&&" on 'esac' +# LINT: missing "&&" on "esac" case "$x" in x) foo ;; *) bar ;; @@ -15,7 +15,7 @@ foobar ) && ( -# LINT: "...)" arm in one-liner 'case' not misinterpreted as closing ")" +# LINT: "...)" arm in one-liner "case" not misinterpreted as closing ")" case "$x" in 1) true;; esac && # LINT: same but missing "&&" case "$y" in 2) false;; esac diff --git a/t/chainlint/complex-if-in-cuddled-loop.test b/t/chainlint/complex-if-in-cuddled-loop.test index 571bbd85cd..5efeda58b2 100644 --- a/t/chainlint/complex-if-in-cuddled-loop.test +++ b/t/chainlint/complex-if-in-cuddled-loop.test @@ -1,4 +1,4 @@ -# LINT: 'for' loop cuddled with "(" and ")" and nested 'if' with complex +# LINT: "for" loop cuddled with "(" and ")" and nested "if" with complex # LINT: multi-line condition; indented with spaces, not tabs (for i in a b c; do if test "$(echo $(waffle bat))" = "eleventeen" && diff --git a/t/chainlint/cuddled-if-then-else.test b/t/chainlint/cuddled-if-then-else.test index eed774a9d6..7c53f4efe3 100644 --- a/t/chainlint/cuddled-if-then-else.test +++ b/t/chainlint/cuddled-if-then-else.test @@ -1,4 +1,4 @@ -# LINT: 'if' cuddled with "(" and ")"; indented with spaces, not tabs +# LINT: "if" cuddled with "(" and ")"; indented with spaces, not tabs (if test -z ""; then echo empty else diff --git a/t/chainlint/cuddled-loop.test b/t/chainlint/cuddled-loop.test index a841d781f0..3c2a62f751 100644 --- a/t/chainlint/cuddled-loop.test +++ b/t/chainlint/cuddled-loop.test @@ -1,4 +1,4 @@ -# LINT: 'while' loop cuddled with "(" and ")", with embedded (allowed) +# LINT: "while" loop cuddled with "(" and ")", with embedded (allowed) # LINT: "|| exit {n}" to exit loop early, and using redirection "<" to feed # LINT: loop; indented with spaces, not tabs ( while read x diff --git a/t/chainlint/for-loop.test b/t/chainlint/for-loop.test index 7db76262bc..6cb3428158 100644 --- a/t/chainlint/for-loop.test +++ b/t/chainlint/for-loop.test @@ -1,17 +1,17 @@ ( -# LINT: 'for', 'do', 'done' do not need "&&" +# LINT: "for", "do", "done" do not need "&&" for i in a b c do -# LINT: missing "&&" on 'echo' +# LINT: missing "&&" on "echo" echo $i # LINT: last statement of while does not need "&&" cat <<-\EOF bar EOF -# LINT: missing "&&" on 'done' +# LINT: missing "&&" on "done" done -# LINT: 'do' on same line as 'for' +# LINT: "do" on same line as "for" for i in a b c; do echo $i && cat $i diff --git a/t/chainlint/here-doc.expect b/t/chainlint/here-doc.expect index 534b065e38..8449eb2e02 100644 --- a/t/chainlint/here-doc.expect +++ b/t/chainlint/here-doc.expect @@ -2,8 +2,6 @@ boodle wobba gorgo snoot wafta snurb && cat >foo && -cat >bar && - cat >boo && horticulture diff --git a/t/chainlint/here-doc.test b/t/chainlint/here-doc.test index ad4ce8afd9..3f5f92cad3 100644 --- a/t/chainlint/here-doc.test +++ b/t/chainlint/here-doc.test @@ -14,13 +14,6 @@ boz woz Arbitrary_Tag_42 -# LINT: swallow 'quoted' here-doc -cat <<'FUMP' >bar && -snoz -boz -woz -FUMP - # LINT: swallow "quoted" here-doc cat <<"zump" >boo && snoz diff --git a/t/chainlint/if-in-loop.test b/t/chainlint/if-in-loop.test index daf22da164..f0cf19cfad 100644 --- a/t/chainlint/if-in-loop.test +++ b/t/chainlint/if-in-loop.test @@ -3,13 +3,13 @@ do if false then -# LINT: missing "&&" on 'echo' +# LINT: missing "&&" on "echo" echo "err" exit 1 -# LINT: missing "&&" on 'fi' +# LINT: missing "&&" on "fi" fi foo -# LINT: missing "&&" on 'done' +# LINT: missing "&&" on "done" done bar ) diff --git a/t/chainlint/if-then-else.test b/t/chainlint/if-then-else.test index d2b03ca6b4..2055336c2b 100644 --- a/t/chainlint/if-then-else.test +++ b/t/chainlint/if-then-else.test @@ -1,27 +1,27 @@ ( -# LINT: 'if', 'then', 'elif', 'else', 'fi' do not need "&&" +# LINT: "if", "then", "elif", "else", "fi" do not need "&&" if test -n "" then -# LINT: missing "&&" on 'echo' +# LINT: missing "&&" on "echo" echo very -# LINT: last statement before 'elif' does not need "&&" +# LINT: last statement before "elif" does not need "&&" echo empty elif test -z "" then -# LINT: last statement before 'else' does not need "&&" +# LINT: last statement before "else" does not need "&&" echo foo else echo foo && -# LINT: last statement before 'fi' does not need "&&" +# LINT: last statement before "fi" does not need "&&" cat <<-\EOF bar EOF -# LINT: missing "&&" on 'fi' +# LINT: missing "&&" on "fi" fi echo poodle ) && ( -# LINT: 'then' on same line as 'if' +# LINT: "then" on same line as "if" if test -n ""; then echo very && echo empty diff --git a/t/chainlint/loop-in-if.test b/t/chainlint/loop-in-if.test index 93e8ba8e4d..dfcc3f98fb 100644 --- a/t/chainlint/loop-in-if.test +++ b/t/chainlint/loop-in-if.test @@ -3,13 +3,13 @@ then while true do -# LINT: missing "&&" on 'echo' +# LINT: missing "&&" on "echo" echo "pop" echo "glup" -# LINT: missing "&&" on 'done' +# LINT: missing "&&" on "done" done foo -# LINT: missing "&&" on 'fi' +# LINT: missing "&&" on "fi" fi bar ) diff --git a/t/chainlint/multi-line-string.expect b/t/chainlint/multi-line-string.expect index 170cb59993..2829516495 100644 --- a/t/chainlint/multi-line-string.expect +++ b/t/chainlint/multi-line-string.expect @@ -1,15 +1,9 @@ ( x="line 1 line 2 line 3" && -?!AMP?! y='line 1 line2' +?!AMP?! y="line 1 line2" foobar >) && -( - echo "there's nothing to see here" && - exit ->) && ( echo "xyz" "abc def ghi" && - echo 'xyz' 'abc def ghi' && - echo 'xyz' "abc def ghi" && barfoo >) diff --git a/t/chainlint/multi-line-string.test b/t/chainlint/multi-line-string.test index 287ab89705..4a0af2107d 100644 --- a/t/chainlint/multi-line-string.test +++ b/t/chainlint/multi-line-string.test @@ -3,25 +3,13 @@ line 2 line 3" && # LINT: missing "&&" on assignment - y='line 1 - line2' + y="line 1 + line2" foobar ) && -( -# LINT: apostrophe (in a contraction) within string not misinterpreted as -# LINT: starting multi-line single-quoted string - echo "there's nothing to see here" && - exit -) && ( echo "xyz" "abc def ghi" && - echo 'xyz' 'abc - def - ghi' && - echo 'xyz' "abc - def - ghi" && barfoo ) diff --git a/t/chainlint/nested-subshell-comment.test b/t/chainlint/nested-subshell-comment.test index 0ff136ab3c..0215cdb192 100644 --- a/t/chainlint/nested-subshell-comment.test +++ b/t/chainlint/nested-subshell-comment.test @@ -7,7 +7,7 @@ # minor numbers of cows (or do they?) baz && snaff -# LINT: missing "&&" on ')' +# LINT: missing "&&" on ")" ) fuzzy ) diff --git a/t/chainlint/pipe.test b/t/chainlint/pipe.test index e6af4de916..dd82534c66 100644 --- a/t/chainlint/pipe.test +++ b/t/chainlint/pipe.test @@ -4,7 +4,7 @@ bar | baz && -# LINT: final line of pipe sequence ('cow') lacking "&&" +# LINT: final line of pipe sequence ("cow") lacking "&&" fish | cow diff --git a/t/chainlint/subshell-here-doc.expect b/t/chainlint/subshell-here-doc.expect index 74723e7340..7e057aee42 100644 --- a/t/chainlint/subshell-here-doc.expect +++ b/t/chainlint/subshell-here-doc.expect @@ -5,7 +5,6 @@ >) && ( cat >bup && - cat >bup2 && cat >bup3 && meep >) diff --git a/t/chainlint/subshell-here-doc.test b/t/chainlint/subshell-here-doc.test index 0cce907ba8..d40eb65583 100644 --- a/t/chainlint/subshell-here-doc.test +++ b/t/chainlint/subshell-here-doc.test @@ -8,7 +8,7 @@ nevermore... EOF -# LINT: missing "&&" on 'cat' +# LINT: missing "&&" on "cat" cat <bip fish fly high EOF @@ -27,10 +27,6 @@ EOF glink FIZZ ARBITRARY - cat <<-'ARBITRARY2' >bup2 && - glink - FIZZ - ARBITRARY2 cat <<-"ARBITRARY3" >bup3 && glink FIZZ diff --git a/t/chainlint/t7900-subtree.expect b/t/chainlint/t7900-subtree.expect index c9913429e6..f769244ef6 100644 --- a/t/chainlint/t7900-subtree.expect +++ b/t/chainlint/t7900-subtree.expect @@ -1,9 +1,9 @@ ( chks="sub1sub2sub3sub4" && - chks_sub=$(cat | sed 's,^,sub dir/,' + chks_sub=$(cat | sed "s,^,sub dir/," >>) && chkms="main-sub1main-sub2main-sub3main-sub4" && - chkms_sub=$(cat | sed 's,^,sub dir/,' + chkms_sub=$(cat | sed "s,^,sub dir/," >>) && subfiles=$(git ls-files) && check_equal "$subfiles" "$chkms$chks" diff --git a/t/chainlint/t7900-subtree.test b/t/chainlint/t7900-subtree.test index 277d8358df..02f3129232 100644 --- a/t/chainlint/t7900-subtree.test +++ b/t/chainlint/t7900-subtree.test @@ -3,7 +3,7 @@ sub2 sub3 sub4" && - chks_sub=$(cat < X-Patchwork-Id: 12673107 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 28B4BC433EF for ; Mon, 13 Dec 2021 06:32:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232235AbhLMGcD (ORCPT ); Mon, 13 Dec 2021 01:32:03 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40082 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232226AbhLMGcB (ORCPT ); Mon, 13 Dec 2021 01:32:01 -0500 Received: from mail-io1-xd35.google.com (mail-io1-xd35.google.com [IPv6:2607:f8b0:4864:20::d35]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0B131C061748 for ; Sun, 12 Dec 2021 22:32:01 -0800 (PST) Received: by mail-io1-xd35.google.com with SMTP id p23so17350418iod.7 for ; Sun, 12 Dec 2021 22:32:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=RV005bYLYVmT+17RQVAImFfKQLb6x+KwNGMizg4pl1U=; b=OAZcNgtSEczsiTwd8bBTRYJ1PZzU9zLe5gBX0+DpVKB0ugxQ+YTxbiWmvV+QsekCOs oBc9HbZFCdtR4qfqZwkfn7j4uHFzJ/JbB4Cp/SqgzRgKZh/Hj9KRBzv/M8xxhsQ00VCy Sdkb10e/NWr5GwXxDJcCBpGhNZvk2z7+m3IMXhrGAklEG7iOgvRYZaojbCIxIZUSu/ue qzFbIkXk+AeZ8iRY+Jhv+PLVIF/xqSZBxaJw9be4/z3XarUIEMGaRznLsbZ6YxwGXKkY cu3ybu93eZv9TYoh14f+Mquv6L8KDYCjKxSgbs19yU74BSUuH17leog8DRerk+eI6W7J KEhw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=RV005bYLYVmT+17RQVAImFfKQLb6x+KwNGMizg4pl1U=; b=Inuq43Y2uO5TZ9sO6dBtWRGC4DRA7FqNag42FFuo6P5OTJKP9ZUwzu88VeqGBCtMv4 CL3OFepRoVjrO9jhawvwPOowlQawSgIa9DyHNQ9FUpNmuPaKQZSK6LGeeFCtkvXr9rzn xSZ60dztAZlvoDcr/+Lad6H2EcJCLsphQfUO3e0erhpRVhSy9pGay4ACULIVGN1e8ufv kTFIQuDRII3nahHLXhcfQPHiiZyjeNn0cIT11zGz3Az6+dMxZ98wDrhBfMKu62LoVKFP YonLkWG4gXSAU3NDxKaPperg8Vg8ksjDDWzbf0eTrImb4MtCRkjnVt9j3kpFiqnONOvN EnyQ== X-Gm-Message-State: AOAM532/V+xTn3VbzuJpoz7EoV4LVR/nfHUnw8IHtvtUaqqqvEp9k6PV RfwmI500/IqfALqYH/+IXzWpIoOdbw5TLA== X-Google-Smtp-Source: ABdhPJw4oQvn7bnhre+pdW6G2BxiPvZ1jb+WDAb9SygxODhJNYCxFbfIS9Y1ScChKuneDJ55T7ZLHQ== X-Received: by 2002:a6b:d904:: with SMTP id r4mr30531589ioc.165.1639377120301; Sun, 12 Dec 2021 22:32:00 -0800 (PST) Received: from localhost.localdomain (097-069-216-153.res.spectrum.com. [97.69.216.153]) by smtp.gmail.com with ESMTPSA id f10sm7305408ils.13.2021.12.12.22.31.59 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sun, 12 Dec 2021 22:32:00 -0800 (PST) Sender: Eric Sunshine From: Eric Sunshine To: git@vger.kernel.org Cc: Jeff King , Elijah Newren , Fabian Stelzer , Eric Sunshine Subject: [PATCH 03/15] t/chainlint/*.test: generalize self-test commentary Date: Mon, 13 Dec 2021 01:30:47 -0500 Message-Id: <20211213063059.19424-4-sunshine@sunshineco.com> X-Mailer: git-send-email 2.34.1.397.gfae76fe5da In-Reply-To: <20211213063059.19424-1-sunshine@sunshineco.com> References: <20211213063059.19424-1-sunshine@sunshineco.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org The purpose of chainlint.sed is to detect &&-chain breakage only within subshells (one level deep); it doesn't bother checking for top-level &&-chain breakage since the &&-chain checker built into t/test-lib.sh should detect broken &&-chains outside of subshells by making them magically exit with code 117. However, this division of labor may not always be the case if a more capable chainlint implementation is ever developed. Beyond that, due to being sed-based and due to its use of heuristics, chainlint.sed has several limitations (such as being unable to detect &&-chain breakage in subshells more than one level deep since it only manually emulates recursion into a subshell). Some of the comments in the chainlint self-tests unnecessarily reflect the limitations of chainlint.sed even though those limitations are not what is being tested. Therefore, simplify and generalize the comments to explain only what is being tested, thus ensuring that they won't become outdated if a more capable chainlint is ever developed. Signed-off-by: Eric Sunshine --- t/chainlint/blank-line.test | 2 +- t/chainlint/block.test | 3 +-- t/chainlint/cuddled.test | 3 +-- t/chainlint/nested-subshell.test | 1 - t/chainlint/one-liner.test | 2 +- t/chainlint/semicolon.test | 4 ++-- 6 files changed, 6 insertions(+), 9 deletions(-) diff --git a/t/chainlint/blank-line.test b/t/chainlint/blank-line.test index f6dd14302b..0fdf15b3e1 100644 --- a/t/chainlint/blank-line.test +++ b/t/chainlint/blank-line.test @@ -3,7 +3,7 @@ nothing && something -# LINT: swallow blank lines since final _statement_ before subshell end is +# LINT: ignore blank lines since final _statement_ before subshell end is # LINT: significant to "&&"-check, not final _line_ (which might be blank) diff --git a/t/chainlint/block.test b/t/chainlint/block.test index d859151af1..0a82fd579f 100644 --- a/t/chainlint/block.test +++ b/t/chainlint/block.test @@ -1,6 +1,5 @@ ( -# LINT: missing "&&" in block not currently detected (for consistency with -# LINT: --chain-lint at top level and to provide escape hatch if needed) +# LINT: missing "&&" after first "echo" foo && { echo a diff --git a/t/chainlint/cuddled.test b/t/chainlint/cuddled.test index 0499fa4180..257b5b5eed 100644 --- a/t/chainlint/cuddled.test +++ b/t/chainlint/cuddled.test @@ -1,5 +1,4 @@ -# LINT: first subshell statement cuddled with opening "("; for implementation -# LINT: simplicity, "(..." is split into two lines, "(" and "..." +# LINT: first subshell statement cuddled with opening "(" (cd foo && bar ) && diff --git a/t/chainlint/nested-subshell.test b/t/chainlint/nested-subshell.test index 998b05a47d..440ee9992d 100644 --- a/t/chainlint/nested-subshell.test +++ b/t/chainlint/nested-subshell.test @@ -7,7 +7,6 @@ cd foo && ( -# LINT: nested multi-line subshell not presently checked for missing "&&" echo a echo b ) >file diff --git a/t/chainlint/one-liner.test b/t/chainlint/one-liner.test index ec9acb9825..69796d7505 100644 --- a/t/chainlint/one-liner.test +++ b/t/chainlint/one-liner.test @@ -3,7 +3,7 @@ (foo && bar) | (foo && bar) >baz && -# LINT: top-level one-liner subshell missing internal "&&" +# LINT: top-level one-liner subshell missing internal "&&" and broken &&-chain (foo; bar) && (foo; bar) | (foo; bar) >baz diff --git a/t/chainlint/semicolon.test b/t/chainlint/semicolon.test index d82c8ebbc0..67e1192c50 100644 --- a/t/chainlint/semicolon.test +++ b/t/chainlint/semicolon.test @@ -15,11 +15,11 @@ cat foo; echo bar ) && ( -# LINT: unnecessary terminating semicolon +# LINT: semicolon unnecessary but legitimate foo; ) && (cd foo && for i in a b c; do -# LINT: unnecessary terminating semicolon +# LINT: semicolon unnecessary but legitimate echo; done) From patchwork Mon Dec 13 06:30:48 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Sunshine X-Patchwork-Id: 12673111 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 9E055C433F5 for ; Mon, 13 Dec 2021 06:32:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232251AbhLMGcF (ORCPT ); Mon, 13 Dec 2021 01:32:05 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40086 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232227AbhLMGcC (ORCPT ); Mon, 13 Dec 2021 01:32:02 -0500 Received: from mail-io1-xd2d.google.com (mail-io1-xd2d.google.com [IPv6:2607:f8b0:4864:20::d2d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D4514C061751 for ; Sun, 12 Dec 2021 22:32:01 -0800 (PST) Received: by mail-io1-xd2d.google.com with SMTP id k21so17344733ioh.4 for ; Sun, 12 Dec 2021 22:32:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=qavUlmxKqwwH50whFgJkIc5I+rxBkwSULiHgjSYOAqY=; b=cW6iigM5TJJrfRuVslyuR/JV6mVkh5UHypOo/ukWBi8LeDfQjxUMbFIRDbCqHY4Fa/ M0oLlfgXjKeFKnPUJAdHFLWTKGq8jRbQ4RBcgbjNZniVqZOq5iYW35d5ACzHD2tcRQzd iEk5Mczm6fbXreFx7Peleg266eo5FwNo4qDrtNMBxfpsMKq7nfNn45IANwAY4QExFM6Q 9OGfbazcQ8kcO2knhR75HH4eVfLf5ski0LprUpdhFx4dkfrjRd9YMqh7s4IZlCdhmVcy 1/GDfsfuJlV6w0vb479gsK/lJ1HV5MtpdTdP8Htv0qm9QKjfqqXE+WKF4d2xfQ6h4mAA i6xA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=qavUlmxKqwwH50whFgJkIc5I+rxBkwSULiHgjSYOAqY=; b=HqIHdr/LaZZYco5n/pVfnqY+mklvQ2sI48tQN53GIxQFMPQJrQ+n7SSbzCzMkLHVWX +6nyaNuHYCaPjTUt8fooRlkba0AQRYcwc0wNxgMXTC1P+PqN81aK/Bkn0g2b044mVPNw SSs10fQ5eKT4I5xEGZmr9LyqbQSlCFEKeypyLk0KZA+72w5dB6oY8On3zqrYopB6XU0+ CjhhkWAJ/Kg7+MtfG1a7hCaJjnZXwvp8ORV/sV9wbGLXhMgXMV1zMH0baCfuvdyjJJJP YnIe2Qb3a2CNP0AbeZstZUi19VZE8pII0JEf6dReYhRQ+etLnc4UgQeuGJaV2ZQqLd0H YuuQ== X-Gm-Message-State: AOAM5319N627iNMnlpVrQsaM2eE0h3FeF9julWxmcLGi7NPjQDk2ag88 nw8cgs95+51bD8+eP7HIsQP5g2l8NTQ8XQ== X-Google-Smtp-Source: ABdhPJwf7wf+LKiUYFioQYOKJydx9e27T2NqhkjfiXzcZCgcbhAwp7ujPL0JlZf7SPioj+khAWazpw== X-Received: by 2002:a05:6638:300a:: with SMTP id r10mr30649900jak.91.1639377121087; Sun, 12 Dec 2021 22:32:01 -0800 (PST) Received: from localhost.localdomain (097-069-216-153.res.spectrum.com. [97.69.216.153]) by smtp.gmail.com with ESMTPSA id f10sm7305408ils.13.2021.12.12.22.32.00 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sun, 12 Dec 2021 22:32:00 -0800 (PST) Sender: Eric Sunshine From: Eric Sunshine To: git@vger.kernel.org Cc: Jeff King , Elijah Newren , Fabian Stelzer , Eric Sunshine Subject: [PATCH 04/15] t/chainlint/one-liner: avoid overly intimate chainlint.sed knowledge Date: Mon, 13 Dec 2021 01:30:48 -0500 Message-Id: <20211213063059.19424-5-sunshine@sunshineco.com> X-Mailer: git-send-email 2.34.1.397.gfae76fe5da In-Reply-To: <20211213063059.19424-1-sunshine@sunshineco.com> References: <20211213063059.19424-1-sunshine@sunshineco.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org The purpose of chainlint.sed is to detect &&-chain breakage only within subshells (one level deep); it doesn't bother checking for top-level &&-chain breakage since the &&-chain checker built into t/test-lib.sh should detect broken &&-chains outside of subshells by making them magically exit with code 117. Unfortunately, one of the chainlint.sed self-tests has overly intimate knowledge of this particular division of responsibilities and only cares about what chainlint.sed itself will produce, while ignoring the fact that a more all-encompassing linter would complain about a broken &&-chain outside the subshell. This makes it difficult to re-use the test with a more capable chainlint implementation should one ever be developed. Therefore, adjust the test and its "expected" output to avoid being specific to the tunnel-vision of this one implementation. Signed-off-by: Eric Sunshine --- t/chainlint/one-liner.expect | 2 +- t/chainlint/one-liner.test | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/t/chainlint/one-liner.expect b/t/chainlint/one-liner.expect index 237f227349..c64058f7af 100644 --- a/t/chainlint/one-liner.expect +++ b/t/chainlint/one-liner.expect @@ -4,6 +4,6 @@ ?!SEMI?!(foo; bar) && ?!SEMI?!(foo; bar) | -?!SEMI?!(foo; bar) >baz +?!SEMI?!(foo; bar) >baz && (foo "bar; baz") diff --git a/t/chainlint/one-liner.test b/t/chainlint/one-liner.test index 69796d7505..be9858fa29 100644 --- a/t/chainlint/one-liner.test +++ b/t/chainlint/one-liner.test @@ -6,7 +6,7 @@ # LINT: top-level one-liner subshell missing internal "&&" and broken &&-chain (foo; bar) && (foo; bar) | -(foo; bar) >baz +(foo; bar) >baz && # LINT: ";" in string not misinterpreted as broken &&-chain (foo "bar; baz") From patchwork Mon Dec 13 06:30:49 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Sunshine X-Patchwork-Id: 12673113 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 B1BD6C433F5 for ; Mon, 13 Dec 2021 06:32:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232256AbhLMGcH (ORCPT ); Mon, 13 Dec 2021 01:32:07 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40092 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232231AbhLMGcD (ORCPT ); Mon, 13 Dec 2021 01:32:03 -0500 Received: from mail-io1-xd2e.google.com (mail-io1-xd2e.google.com [IPv6:2607:f8b0:4864:20::d2e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 94570C06173F for ; Sun, 12 Dec 2021 22:32:02 -0800 (PST) Received: by mail-io1-xd2e.google.com with SMTP id k21so17344753ioh.4 for ; Sun, 12 Dec 2021 22:32:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=kI8fkABdM70wgQK17c7ffmtqSac2r0ZWGOzSGY/4HbU=; b=Gkk2lJK+qKwQ642qh1Ur3Y6T21ui2gQ931W9omL2Jnl8VLuNIelQobP1XfFb/o2G5n Em9vOZsgeZm348heYYcCKoGP92eOWXwbpaKeqD1Vmb1iwml6HqMeEBT8tFAAIu1rYwB+ 7VLumQd+rI8oxTtryxC8OKUbC8yzBBRt3UeXVn/43o8txfT5lTdu6NSCuoAXzTEzD/Qf h6TZhiERCGG9/NyWrFQqzf96ET49V8/JnUl2rs47rT+Cl40XvvFu11XC5IlUJInf0x6h LmxgrqleCFQk/d1/jbUEIqYeW2HUc5CgSUMq0X+7leZnA7AQks98VWLDqvJ2ME6Rc2H0 Y4/g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=kI8fkABdM70wgQK17c7ffmtqSac2r0ZWGOzSGY/4HbU=; b=TcomrruLWWu1grtcyQs8o4sSOnVI+e0CTn4LVR5wpN1LD2kkNr517rE5mLvJqE+9R4 wO5b/86EdUwCESxs5CoyyVFLl1urGIa+RmGGOlqxiJ/u625ao7qgWDxO770QBlrKJ2aW +u+1TGirdW2axaRym/7wpC9W81a7IEZO/kuqKhZrGeqX9tUW06KpBf+fp6CYA4pGrOvH J9wdM4IyhMDlf6l6WCOVx1iG2TuqPJtLPXbJqx6xNF6abqAFB41gGk3+7AI2zLbURt4J pw4WZ+fyENbdTRxfaGrmB3TgCt+2x5FS53rqtk3Vg9ZvnHxqe0dHJGEJKVSG1vYrHCFZ hUXg== X-Gm-Message-State: AOAM531x41GPRA4/6y0ZzmhIyiOjpXORT9v5iJWf5X9JfMLSKJ2/Wb/T Nagn56C1U+A8KVfnHHhd7De1c+5PvP7OVQ== X-Google-Smtp-Source: ABdhPJy2OCyR9GWouQ7Ho5BnjQv812QlMllp7GqFs9DAgguzrCCE0kB+AmnKcqBnfFDyf74ZlXu1yw== X-Received: by 2002:a05:6638:12d6:: with SMTP id v22mr31165435jas.6.1639377121848; Sun, 12 Dec 2021 22:32:01 -0800 (PST) Received: from localhost.localdomain (097-069-216-153.res.spectrum.com. [97.69.216.153]) by smtp.gmail.com with ESMTPSA id f10sm7305408ils.13.2021.12.12.22.32.01 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sun, 12 Dec 2021 22:32:01 -0800 (PST) Sender: Eric Sunshine From: Eric Sunshine To: git@vger.kernel.org Cc: Jeff King , Elijah Newren , Fabian Stelzer , Eric Sunshine Subject: [PATCH 05/15] t/Makefile: optimize chainlint self-test Date: Mon, 13 Dec 2021 01:30:49 -0500 Message-Id: <20211213063059.19424-6-sunshine@sunshineco.com> X-Mailer: git-send-email 2.34.1.397.gfae76fe5da In-Reply-To: <20211213063059.19424-1-sunshine@sunshineco.com> References: <20211213063059.19424-1-sunshine@sunshineco.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Rather than running `chainlint` and `diff` once per self-test -- which may become expensive as more tests are added -- instead run `chainlint` a single time over all tests bodies collectively and compare the result to the collective "expected" output. Signed-off-by: Eric Sunshine --- t/Makefile | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/t/Makefile b/t/Makefile index 882d26eee3..f4ae40be46 100644 --- a/t/Makefile +++ b/t/Makefile @@ -71,12 +71,10 @@ clean-chainlint: check-chainlint: @mkdir -p '$(CHAINLINTTMP_SQ)' && \ - err=0 && \ - for i in $(CHAINLINTTESTS); do \ - $(CHAINLINT) '$(CHAINLINTTMP_SQ)'/$$i.actual && \ - diff -u chainlint/$$i.expect '$(CHAINLINTTMP_SQ)'/$$i.actual || err=1; \ - done && exit $$err + sed -e '/^# LINT: /d' $(patsubst %,chainlint/%.test,$(CHAINLINTTESTS)) >'$(CHAINLINTTMP_SQ)'/tests && \ + cat $(patsubst %,chainlint/%.expect,$(CHAINLINTTESTS)) >'$(CHAINLINTTMP_SQ)'/expect && \ + $(CHAINLINT) '$(CHAINLINTTMP_SQ)'/tests >'$(CHAINLINTTMP_SQ)'/actual && \ + diff -u '$(CHAINLINTTMP_SQ)'/expect '$(CHAINLINTTMP_SQ)'/actual test-lint: test-lint-duplicates test-lint-executable test-lint-shell-syntax \ test-lint-filenames From patchwork Mon Dec 13 06:30:50 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Sunshine X-Patchwork-Id: 12673115 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 A6243C433FE for ; Mon, 13 Dec 2021 06:32:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232258AbhLMGcJ (ORCPT ); Mon, 13 Dec 2021 01:32:09 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40098 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232237AbhLMGcD (ORCPT ); Mon, 13 Dec 2021 01:32:03 -0500 Received: from mail-il1-x133.google.com (mail-il1-x133.google.com [IPv6:2607:f8b0:4864:20::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8418EC06173F for ; Sun, 12 Dec 2021 22:32:03 -0800 (PST) Received: by mail-il1-x133.google.com with SMTP id a11so14108851ilj.6 for ; Sun, 12 Dec 2021 22:32:03 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=X9okeRDwg8rHkftnFvnqxe2lmDgknjfg00e+p16vEf8=; b=h9xf24tuoLgY2BpQz1+dWTdcM3j8MkE7DYqYwrnENkBf3W15qZLFfy/4zbRi0hXj9j Qi6VxXMW//QugXi882G4GllI5KHp3rBVCLwQVW6Vaq6yqJ2sYamTLrvCISMdaF0YsZ3f A6zzAHCap+fnQzAEPztIGoK0mU0TuZ1EFiBt/yHeNraf+FnG6G/kptMI+gGTxvnR49RC GSDbEh1wFjdrYRhwWdCtogSterND0QsSYrW64t9i4yo2Dul4gSqrIWyRie60JKpVnbET wXdJVglQx6VvMWyOHjYInX2gDCjQowKAfmYawTjh/uScgZuqeHt4sJhww83nbmTz/E0t EN3w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=X9okeRDwg8rHkftnFvnqxe2lmDgknjfg00e+p16vEf8=; b=FnLVgjn5Y7nZF2jm2Dj6rdYGVbDCfkX9eEYlEyk8Kkgw7oP3l/S4FIKwr6m+W3gdGY aKQNfFHgc11MgcqT6vUtvkxm83sNle4UKYlrwj6sjrM3yRUE0hrhVZPvSGQGr/oIhTWF 6bgJ2PA1HYtiNfui3uOVpCP+NTJk1s5JEHXF/2YPRgYz0PsFOXhcwccYf7ESga2XKAWb VEkFq2VPwMy+MKediyEPxjjxezpofS/d6Nb8qC7nRgf1yp6hbYMnVbmPep/8dnq0j5sU WKtXaVt1HZTl4Su+B8SNvAvT98kIMVBznDjLlZevra8ip0w4QLd45VTXb2lx1SHweR4V vmVg== X-Gm-Message-State: AOAM533qJZC21rT137+cF/V4PLRBywfcogrkFCGbX6kJ2F93t2NtVUW0 HhhpzTAwgwXzafeQHGhbmUsqu6a+YSRPbg== X-Google-Smtp-Source: ABdhPJyiAHCtPR7HnagY9IE3JZtpuhEdKXDN8G79gQjHFmVsG0jmV9ga0qb/Vq7a2JJj6DQjjA0IvA== X-Received: by 2002:a05:6e02:1d0e:: with SMTP id i14mr24554ila.306.1639377122537; Sun, 12 Dec 2021 22:32:02 -0800 (PST) Received: from localhost.localdomain (097-069-216-153.res.spectrum.com. [97.69.216.153]) by smtp.gmail.com with ESMTPSA id f10sm7305408ils.13.2021.12.12.22.32.01 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sun, 12 Dec 2021 22:32:02 -0800 (PST) Sender: Eric Sunshine From: Eric Sunshine To: git@vger.kernel.org Cc: Jeff King , Elijah Newren , Fabian Stelzer , Eric Sunshine Subject: [PATCH 06/15] chainlint.sed: improve ?!AMP?! placement accuracy Date: Mon, 13 Dec 2021 01:30:50 -0500 Message-Id: <20211213063059.19424-7-sunshine@sunshineco.com> X-Mailer: git-send-email 2.34.1.397.gfae76fe5da In-Reply-To: <20211213063059.19424-1-sunshine@sunshineco.com> References: <20211213063059.19424-1-sunshine@sunshineco.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org When chainlint.sed detects a broken &&-chain, it places an ?!AMP?! annotation at the beginning of the line. However, this is an unusual location for programmers accustomed to error messages (from compilers, for instance) indicating the exact point of the problem. Therefore, relocate the ?!AMP?! annotation to the end of the line in order to better direct the programmer's attention to the source of the problem. Signed-off-by: Eric Sunshine --- t/chainlint.sed | 8 ++++---- t/chainlint/arithmetic-expansion.expect | 2 +- t/chainlint/block.expect | 2 +- t/chainlint/broken-chain.expect | 2 +- t/chainlint/case.expect | 4 ++-- t/chainlint/command-substitution.expect | 2 +- t/chainlint/cuddled.expect | 4 ++-- t/chainlint/for-loop.expect | 4 ++-- t/chainlint/here-doc-multi-line-command-subst.expect | 2 +- t/chainlint/here-doc-multi-line-string.expect | 2 +- t/chainlint/if-in-loop.expect | 6 +++--- t/chainlint/if-then-else.expect | 4 ++-- t/chainlint/inline-comment.expect | 2 +- t/chainlint/loop-in-if.expect | 6 +++--- t/chainlint/multi-line-string.expect | 2 +- t/chainlint/nested-cuddled-subshell.expect | 6 +++--- t/chainlint/nested-here-doc.expect | 2 +- t/chainlint/nested-subshell-comment.expect | 2 +- t/chainlint/pipe.expect | 2 +- t/chainlint/semicolon.expect | 2 +- t/chainlint/subshell-here-doc.expect | 2 +- t/chainlint/subshell-one-liner.expect | 4 ++-- t/chainlint/while-loop.expect | 4 ++-- 23 files changed, 38 insertions(+), 38 deletions(-) diff --git a/t/chainlint.sed b/t/chainlint.sed index 8a25c5b855..883a2b307c 100644 --- a/t/chainlint.sed +++ b/t/chainlint.sed @@ -236,7 +236,7 @@ s/.*\n// # line ends with pipe "...|" -- valid; not missing "&&" /|[ ]*$/bcont # missing end-of-line "&&" -- mark suspect -/&&[ ]*$/!s/^/?!AMP?!/ +/&&[ ]*$/!s/$/ ?!AMP?!/ :cont # retrieve and print previous line x @@ -303,7 +303,7 @@ bcase # that line legitimately lacks "&&" :else x -s/?!AMP?!// +s/ ?!AMP?!$// x bcont @@ -311,7 +311,7 @@ bcont # "suspect" from final contained line since that line legitimately lacks "&&" :done x -s/?!AMP?!// +s/ ?!AMP?!$// x # is 'done' or 'fi' cuddled with ")" to close subshell? /done.*)/bclose @@ -354,7 +354,7 @@ bblock # since that line legitimately lacks "&&" and exit subshell loop :clssolo x -s/?!AMP?!// +s/ ?!AMP?!$// p x s/^/>/ diff --git a/t/chainlint/arithmetic-expansion.expect b/t/chainlint/arithmetic-expansion.expect index 09457d3196..56cd5b69f5 100644 --- a/t/chainlint/arithmetic-expansion.expect +++ b/t/chainlint/arithmetic-expansion.expect @@ -4,6 +4,6 @@ baz >) && ( -?!AMP?! bar=$((42 + 1)) + bar=$((42 + 1)) ?!AMP?! baz >) diff --git a/t/chainlint/block.expect b/t/chainlint/block.expect index fed7e89ae8..6333237cb2 100644 --- a/t/chainlint/block.expect +++ b/t/chainlint/block.expect @@ -7,6 +7,6 @@ bar && { echo c -?!AMP?! } + } ?!AMP?! baz >) diff --git a/t/chainlint/broken-chain.expect b/t/chainlint/broken-chain.expect index 55b0f42a53..0960a8c7c0 100644 --- a/t/chainlint/broken-chain.expect +++ b/t/chainlint/broken-chain.expect @@ -1,6 +1,6 @@ ( foo && -?!AMP?! bar + bar ?!AMP?! baz && wop >) diff --git a/t/chainlint/case.expect b/t/chainlint/case.expect index 41f121fbbf..a4b92d4613 100644 --- a/t/chainlint/case.expect +++ b/t/chainlint/case.expect @@ -9,11 +9,11 @@ case "$x" in x) foo ;; *) bar ;; -?!AMP?! esac + esac ?!AMP?! foobar >) && ( case "$x" in 1) true;; esac && -?!AMP?! case "$y" in 2) false;; esac + case "$y" in 2) false;; esac ?!AMP?! foobar >) diff --git a/t/chainlint/command-substitution.expect b/t/chainlint/command-substitution.expect index ad4118e537..f276067b7b 100644 --- a/t/chainlint/command-substitution.expect +++ b/t/chainlint/command-substitution.expect @@ -4,6 +4,6 @@ baz >) && ( -?!AMP?! bar=$(gobble blocks) + bar=$(gobble blocks) ?!AMP?! baz >) diff --git a/t/chainlint/cuddled.expect b/t/chainlint/cuddled.expect index b506d46221..b6c4ed90a9 100644 --- a/t/chainlint/cuddled.expect +++ b/t/chainlint/cuddled.expect @@ -4,7 +4,7 @@ cd foo && >) && ( -?!AMP?!cd foo +cd foo ?!AMP?! bar >) && @@ -17,5 +17,5 @@ cd foo && > bar) && ( -?!AMP?!cd foo +cd foo ?!AMP?! > bar) diff --git a/t/chainlint/for-loop.expect b/t/chainlint/for-loop.expect index c33cf56ee7..dc209e21bd 100644 --- a/t/chainlint/for-loop.expect +++ b/t/chainlint/for-loop.expect @@ -1,9 +1,9 @@ ( for i in a b c do -?!AMP?! echo $i + echo $i ?!AMP?! cat -?!AMP?! done + done ?!AMP?! for i in a b c; do echo $i && cat $i diff --git a/t/chainlint/here-doc-multi-line-command-subst.expect b/t/chainlint/here-doc-multi-line-command-subst.expect index e5fb752d2f..3a35bb014c 100644 --- a/t/chainlint/here-doc-multi-line-command-subst.expect +++ b/t/chainlint/here-doc-multi-line-command-subst.expect @@ -1,5 +1,5 @@ ( x=$(bobble && -?!AMP?!>> wiffle) +>> wiffle) ?!AMP?! echo $x >) diff --git a/t/chainlint/here-doc-multi-line-string.expect b/t/chainlint/here-doc-multi-line-string.expect index 32038a070c..a3b9a5472d 100644 --- a/t/chainlint/here-doc-multi-line-string.expect +++ b/t/chainlint/here-doc-multi-line-string.expect @@ -1,4 +1,4 @@ ( -?!AMP?! cat && echo "multi-line string" + cat && echo "multi-line string" ?!AMP?! bap >) diff --git a/t/chainlint/if-in-loop.expect b/t/chainlint/if-in-loop.expect index 03d3ceb22d..7d91837269 100644 --- a/t/chainlint/if-in-loop.expect +++ b/t/chainlint/if-in-loop.expect @@ -3,10 +3,10 @@ do if false then -?!AMP?! echo "err" + echo "err" ?!AMP?! exit 1 -?!AMP?! fi + fi ?!AMP?! foo -?!AMP?! done + done ?!AMP?! bar >) diff --git a/t/chainlint/if-then-else.expect b/t/chainlint/if-then-else.expect index a80f5e6c75..3055d5606c 100644 --- a/t/chainlint/if-then-else.expect +++ b/t/chainlint/if-then-else.expect @@ -1,7 +1,7 @@ ( if test -n "" then -?!AMP?! echo very + echo very ?!AMP?! echo empty elif test -z "" then @@ -9,7 +9,7 @@ else echo foo && cat -?!AMP?! fi + fi ?!AMP?! echo poodle >) && ( diff --git a/t/chainlint/inline-comment.expect b/t/chainlint/inline-comment.expect index fc9f250ac4..3d655a32b0 100644 --- a/t/chainlint/inline-comment.expect +++ b/t/chainlint/inline-comment.expect @@ -1,6 +1,6 @@ ( foobar && -?!AMP?! barfoo + barfoo ?!AMP?! flibble "not a # comment" >) && diff --git a/t/chainlint/loop-in-if.expect b/t/chainlint/loop-in-if.expect index 088e622c31..cebd3ae95e 100644 --- a/t/chainlint/loop-in-if.expect +++ b/t/chainlint/loop-in-if.expect @@ -3,10 +3,10 @@ then while true do -?!AMP?! echo "pop" + echo "pop" ?!AMP?! echo "glup" -?!AMP?! done + done ?!AMP?! foo -?!AMP?! fi + fi ?!AMP?! bar >) diff --git a/t/chainlint/multi-line-string.expect b/t/chainlint/multi-line-string.expect index 2829516495..f1be2baf0a 100644 --- a/t/chainlint/multi-line-string.expect +++ b/t/chainlint/multi-line-string.expect @@ -1,6 +1,6 @@ ( x="line 1 line 2 line 3" && -?!AMP?! y="line 1 line2" + y="line 1 line2" ?!AMP?! foobar >) && ( diff --git a/t/chainlint/nested-cuddled-subshell.expect b/t/chainlint/nested-cuddled-subshell.expect index c2a59ffc33..aa522658ed 100644 --- a/t/chainlint/nested-cuddled-subshell.expect +++ b/t/chainlint/nested-cuddled-subshell.expect @@ -4,16 +4,16 @@ >> ) && (cd foo && bar -?!AMP?!>> ) +>> ) ?!AMP?! ( cd foo && >> bar) && ( cd foo && -?!AMP?!>> bar) +>> bar) ?!AMP?! (cd foo && >> bar) && (cd foo && -?!AMP?!>> bar) +>> bar) ?!AMP?! foobar >) diff --git a/t/chainlint/nested-here-doc.expect b/t/chainlint/nested-here-doc.expect index 0c9ef1cfc6..f9604d3fac 100644 --- a/t/chainlint/nested-here-doc.expect +++ b/t/chainlint/nested-here-doc.expect @@ -2,6 +2,6 @@ cat >foop && ( cat && -?!AMP?! cat + cat ?!AMP?! foobar >) diff --git a/t/chainlint/nested-subshell-comment.expect b/t/chainlint/nested-subshell-comment.expect index 15b68d4373..925e49bae9 100644 --- a/t/chainlint/nested-subshell-comment.expect +++ b/t/chainlint/nested-subshell-comment.expect @@ -6,6 +6,6 @@ # minor numbers of cows (or do they?) baz && snaff -?!AMP?!>> ) +>> ) ?!AMP?! fuzzy >) diff --git a/t/chainlint/pipe.expect b/t/chainlint/pipe.expect index 211b901dbc..ede6bcc607 100644 --- a/t/chainlint/pipe.expect +++ b/t/chainlint/pipe.expect @@ -3,6 +3,6 @@ bar | baz && fish | -?!AMP?! cow + cow ?!AMP?! sunder >) diff --git a/t/chainlint/semicolon.expect b/t/chainlint/semicolon.expect index 1d79384606..ffc87bdffb 100644 --- a/t/chainlint/semicolon.expect +++ b/t/chainlint/semicolon.expect @@ -1,5 +1,5 @@ ( -?!AMP?!?!SEMI?! cat foo ; echo bar +?!SEMI?! cat foo ; echo bar ?!AMP?! ?!SEMI?! cat foo ; echo bar >) && ( diff --git a/t/chainlint/subshell-here-doc.expect b/t/chainlint/subshell-here-doc.expect index 7e057aee42..9d3f25b3f5 100644 --- a/t/chainlint/subshell-here-doc.expect +++ b/t/chainlint/subshell-here-doc.expect @@ -1,6 +1,6 @@ ( echo wobba gorgo snoot wafta snurb && -?!AMP?! cat >bip + cat >bip ?!AMP?! echo >bop >) && ( diff --git a/t/chainlint/subshell-one-liner.expect b/t/chainlint/subshell-one-liner.expect index 51162821d7..ec77aa5b95 100644 --- a/t/chainlint/subshell-one-liner.expect +++ b/t/chainlint/subshell-one-liner.expect @@ -8,7 +8,7 @@ (foo || exit 1) && (foo || exit 1) | (foo || exit 1) >baz && -?!AMP?! (foo && bar) -?!AMP?!?!SEMI?! (foo && bar; baz) + (foo && bar) ?!AMP?! +?!SEMI?! (foo && bar; baz) ?!AMP?! foobar >) diff --git a/t/chainlint/while-loop.expect b/t/chainlint/while-loop.expect index 13cff2c0a5..f8b9fcf62b 100644 --- a/t/chainlint/while-loop.expect +++ b/t/chainlint/while-loop.expect @@ -1,9 +1,9 @@ ( while true do -?!AMP?! echo foo + echo foo ?!AMP?! cat -?!AMP?! done + done ?!AMP?! while true; do echo foo && cat bar From patchwork Mon Dec 13 06:30:51 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Sunshine X-Patchwork-Id: 12673117 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 597FEC433F5 for ; Mon, 13 Dec 2021 06:32:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232267AbhLMGcK (ORCPT ); Mon, 13 Dec 2021 01:32:10 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40106 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232241AbhLMGcE (ORCPT ); Mon, 13 Dec 2021 01:32:04 -0500 Received: from mail-il1-x12e.google.com (mail-il1-x12e.google.com [IPv6:2607:f8b0:4864:20::12e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 62E0CC061748 for ; Sun, 12 Dec 2021 22:32:04 -0800 (PST) Received: by mail-il1-x12e.google.com with SMTP id i13so3235866ilk.13 for ; Sun, 12 Dec 2021 22:32:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=cNkgleSHS5lkSjYgdZWp65JdZD79anPtZQGwgipfWAs=; b=GigN4b4akrDBCpp2dLAsxGxsnN1hZ3fITXTqU6Gr5IvTMcf/BPelVEh5EcCi6/mzqn 4WLmt5s2DqqZIxZngnRT1rAL55Q+ZPMnhk310X7nJRNtDWdDHQ2RnjR9KjwZ2xagSMkb 93iUml2QjJwv7lb18LK2MiY4tl9e1FEpMJz0nL2+er/C05unEmqmq8j6XEpeDG3Mt16d Va1/Hv1fYBgMJjSiviYvZ9McjkCcJFQ3YwsfBt9GC8he9AiNxm+UNlJjbRKfn70lNcbU K2L1LELEl7Hm356/C8GzJXcl6fvGl38OoS+AOZIsGs4JuMkEsNTDfvZx84EcP/b0zTx0 6iag== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=cNkgleSHS5lkSjYgdZWp65JdZD79anPtZQGwgipfWAs=; b=t1slQByeaPleIWOmNPBzv2gcEa2E0DgeWtW4K+WTh2hsmRmh2fi77Y+qkKcbmFMdxY yiIX1mXfVHA+2oGDjlgtth4atiCZLWrs+DveMG1UexHuqMv8crudHlV2qXSq8Eym4hhf 6TcoiHxnAhbwsQMhYRPvoR7tj8YsXxUsuN02AU2idt6akCktEBEQ+qhYBDtkW8fBQ9zE n08IQYc35Q7od2UdIOSFpDs95gSLQTMrVbwuYR2AIv+WK9VYiLyx6Uo5fCxcgaTTAkle yJ8q1BnWGkXSo+sRaWYE+KrCCQIN1FwigjPxnMQa37PmtI0wIB3lP9uA6etQmQvYStVK omjg== X-Gm-Message-State: AOAM532lMRkPulCQL3NMAuoBxZFsVjYbJo8Fj3cPLe/P1HQuMNfdXIYs SftxMHvaiKLS7NjCu5cZJsPRD3mdYq0+2Q== X-Google-Smtp-Source: ABdhPJzjyC7QhlIrTsuOpM8AlujnDbFf7Yve4CadCftxM4WnbK5ZrYrCuDmqpE7ju/qwait363ziDQ== X-Received: by 2002:a05:6e02:1583:: with SMTP id m3mr32883820ilu.294.1639377123474; Sun, 12 Dec 2021 22:32:03 -0800 (PST) Received: from localhost.localdomain (097-069-216-153.res.spectrum.com. [97.69.216.153]) by smtp.gmail.com with ESMTPSA id f10sm7305408ils.13.2021.12.12.22.32.02 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sun, 12 Dec 2021 22:32:02 -0800 (PST) Sender: Eric Sunshine From: Eric Sunshine To: git@vger.kernel.org Cc: Jeff King , Elijah Newren , Fabian Stelzer , Eric Sunshine Subject: [PATCH 07/15] chainlint.sed: improve ?!SEMI?! placement accuracy Date: Mon, 13 Dec 2021 01:30:51 -0500 Message-Id: <20211213063059.19424-8-sunshine@sunshineco.com> X-Mailer: git-send-email 2.34.1.397.gfae76fe5da In-Reply-To: <20211213063059.19424-1-sunshine@sunshineco.com> References: <20211213063059.19424-1-sunshine@sunshineco.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org When chainlint.sed detects commands separated by a semicolon rather than by `&&`, it places a ?!SEMI?! annotation at the beginning of the line. However, this is an unusual location for programmers accustomed to error messages (from compilers, for instance) indicating the exact point of the problem. Therefore, relocate the ?!SEMI?! annotation to the location of the semicolon in order to better direct the programmer's attention to the source of the problem. Signed-off-by: Eric Sunshine --- t/chainlint.sed | 4 ++-- t/chainlint/negated-one-liner.expect | 4 ++-- t/chainlint/one-liner.expect | 6 +++--- t/chainlint/semicolon.expect | 14 +++++++------- t/chainlint/subshell-one-liner.expect | 8 ++++---- 5 files changed, 18 insertions(+), 18 deletions(-) diff --git a/t/chainlint.sed b/t/chainlint.sed index 883a2b307c..60c2099c18 100644 --- a/t/chainlint.sed +++ b/t/chainlint.sed @@ -126,7 +126,7 @@ b # "&&" (but not ";" in a string) :oneline /;/{ - /"[^"]*;[^"]*"/!s/^/?!SEMI?!/ + /"[^"]*;[^"]*"/!s/;/; ?!SEMI?!/ } b @@ -230,7 +230,7 @@ s/.*\n// # string and not ";;" in one-liner "case...esac") /;/{ /;;/!{ - /"[^"]*;[^"]*"/!s/^/?!SEMI?!/ + /"[^"]*;[^"]*"/!s/;/; ?!SEMI?!/ } } # line ends with pipe "...|" -- valid; not missing "&&" diff --git a/t/chainlint/negated-one-liner.expect b/t/chainlint/negated-one-liner.expect index cf18429d03..60baf84b7a 100644 --- a/t/chainlint/negated-one-liner.expect +++ b/t/chainlint/negated-one-liner.expect @@ -1,5 +1,5 @@ ! (foo && bar) && ! (foo && bar) >baz && -?!SEMI?!! (foo; bar) && -?!SEMI?!! (foo; bar) >baz +! (foo; ?!SEMI?! bar) && +! (foo; ?!SEMI?! bar) >baz diff --git a/t/chainlint/one-liner.expect b/t/chainlint/one-liner.expect index c64058f7af..3b46554728 100644 --- a/t/chainlint/one-liner.expect +++ b/t/chainlint/one-liner.expect @@ -2,8 +2,8 @@ (foo && bar) | (foo && bar) >baz && -?!SEMI?!(foo; bar) && -?!SEMI?!(foo; bar) | -?!SEMI?!(foo; bar) >baz && +(foo; ?!SEMI?! bar) && +(foo; ?!SEMI?! bar) | +(foo; ?!SEMI?! bar) >baz && (foo "bar; baz") diff --git a/t/chainlint/semicolon.expect b/t/chainlint/semicolon.expect index ffc87bdffb..d2d804f5b0 100644 --- a/t/chainlint/semicolon.expect +++ b/t/chainlint/semicolon.expect @@ -1,20 +1,20 @@ ( -?!SEMI?! cat foo ; echo bar ?!AMP?! -?!SEMI?! cat foo ; echo bar + cat foo ; ?!SEMI?! echo bar ?!AMP?! + cat foo ; ?!SEMI?! echo bar >) && ( -?!SEMI?! cat foo ; echo bar && -?!SEMI?! cat foo ; echo bar + cat foo ; ?!SEMI?! echo bar && + cat foo ; ?!SEMI?! echo bar >) && ( echo "foo; bar" && -?!SEMI?! cat foo; echo bar + cat foo; ?!SEMI?! echo bar >) && ( -?!SEMI?! foo; + foo; ?!SEMI?! >) && ( cd foo && for i in a b c; do -?!SEMI?! echo; + echo; ?!SEMI?! > done) diff --git a/t/chainlint/subshell-one-liner.expect b/t/chainlint/subshell-one-liner.expect index ec77aa5b95..432217801b 100644 --- a/t/chainlint/subshell-one-liner.expect +++ b/t/chainlint/subshell-one-liner.expect @@ -2,13 +2,13 @@ (foo && bar) && (foo && bar) | (foo && bar) >baz && -?!SEMI?! (foo; bar) && -?!SEMI?! (foo; bar) | -?!SEMI?! (foo; bar) >baz && + (foo; ?!SEMI?! bar) && + (foo; ?!SEMI?! bar) | + (foo; ?!SEMI?! bar) >baz && (foo || exit 1) && (foo || exit 1) | (foo || exit 1) >baz && (foo && bar) ?!AMP?! -?!SEMI?! (foo && bar; baz) ?!AMP?! + (foo && bar; ?!SEMI?! baz) ?!AMP?! foobar >) From patchwork Mon Dec 13 06:30:52 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Sunshine X-Patchwork-Id: 12673119 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 77EECC433EF for ; Mon, 13 Dec 2021 06:32:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232279AbhLMGcN (ORCPT ); Mon, 13 Dec 2021 01:32:13 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40110 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232245AbhLMGcF (ORCPT ); Mon, 13 Dec 2021 01:32:05 -0500 Received: from mail-il1-x12f.google.com (mail-il1-x12f.google.com [IPv6:2607:f8b0:4864:20::12f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0875EC0613F8 for ; Sun, 12 Dec 2021 22:32:05 -0800 (PST) Received: by mail-il1-x12f.google.com with SMTP id v13so789243ilm.8 for ; Sun, 12 Dec 2021 22:32:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=CjcawDkWagOZ4PH55/UleBPB2dTtvFZJjqPUuLyBAAw=; b=l9gtGJ/cNNa3QRrxSeGEBTzO/J7+cb8si/3ZJMOZTeT9RsAxTZI0tE1Wz4nYX3ph3W oebC85+ggrwkg/2imdpebN3vmdM9tdEazuuogcFJebeM6xif6Bc4HuPTD8wbNNylaeHG VJiCvsebLR6nqFuRYj5SH1m/CPJmmbIACjWUNRr1dpHQoysgR4a/MuT2fDWyeXiuoJtm xMNcm6czgNT177IDojR6E8wlE8F1mezURWaf3r+GJygFUNSrro9zSsSNd1kb57EsRRay 3yKKR45IAR7VAz9aIILmcnE0KPMAAncS7ckQdKNLYJnOWpbT+1B2RJ3243gMe922iQ2a KU+g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=CjcawDkWagOZ4PH55/UleBPB2dTtvFZJjqPUuLyBAAw=; b=Wzdfv1EOTwtkhLg07tu1rqmr0fcPIili2bywqZPdqFqNO8lP08v/W3AO9Vx+n92EKB tNpgQaTqmQMnqx0pKphsHzLSrfh4kW2DokS8iuV89GWX8nggznxh2iHtasOkqmRAUEgh H2HhYHjt8ExOsyLk/V9B1UL+EFIwm/WojNe8aISZ0PcT+oX57rOppJa7iKGqGYcFO501 RV1fs+/siBj7I/jeQuJsYIFtExgCe8BphHKMNExypUNBo91Cob1+NpithzBApT7mSWrv FXlSmadYFivBEjgwJmkhOHTVHBBVSoEgpYiL90PJSqUBElKa5v7HK9oWsf8JAFBv3sH0 6DFw== X-Gm-Message-State: AOAM531Q7Fsz0kneXHLrQa5Zr3S93JsrT1Ex5Kro9wt9X835d/DAqCOk gaimxAQBY5ooyNGpae3j8T9LiFRy5SFp2g== X-Google-Smtp-Source: ABdhPJw5vIBVFt66+S+OYsT/IoDFB7FCSTOLeL6n4ngqXExNEKomNYhxQkU9/M8FW+KZ0GsiSS0iMw== X-Received: by 2002:a05:6e02:1648:: with SMTP id v8mr32284793ilu.157.1639377124194; Sun, 12 Dec 2021 22:32:04 -0800 (PST) Received: from localhost.localdomain (097-069-216-153.res.spectrum.com. [97.69.216.153]) by smtp.gmail.com with ESMTPSA id f10sm7305408ils.13.2021.12.12.22.32.03 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sun, 12 Dec 2021 22:32:03 -0800 (PST) Sender: Eric Sunshine From: Eric Sunshine To: git@vger.kernel.org Cc: Jeff King , Elijah Newren , Fabian Stelzer , Eric Sunshine Subject: [PATCH 08/15] chainlint.sed: tolerate harmless ";" at end of last line in block Date: Mon, 13 Dec 2021 01:30:52 -0500 Message-Id: <20211213063059.19424-9-sunshine@sunshineco.com> X-Mailer: git-send-email 2.34.1.397.gfae76fe5da In-Reply-To: <20211213063059.19424-1-sunshine@sunshineco.com> References: <20211213063059.19424-1-sunshine@sunshineco.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org chainlint.sed flags ";" when used as a command terminator since it breaks the &&-chain, thus can allow failures to go undetected. However, when a command terminated by ";" is the last command in the body of a compound statement, such as `command-2` in: if test $# -gt 1 then command-1 && command-2; fi then the ";" is harmless and the exit code from `command-2` is passed through untouched and becomes the exit code of the compound statement, as if the ";" was not present. Therefore, tolerate a trailing ";" in this position rather than complaining about broken &&-chain. Signed-off-by: Eric Sunshine --- t/chainlint.sed | 11 ++++++----- t/chainlint/semicolon.expect | 4 ++-- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/t/chainlint.sed b/t/chainlint.sed index 60c2099c18..91077b6e26 100644 --- a/t/chainlint.sed +++ b/t/chainlint.sed @@ -47,8 +47,9 @@ # "?!AMP?!" violation is removed from the "bar" line (retrieved from the "hold" # area) since the final statement of a subshell must not end with "&&". The # final line of a subshell may still break the &&-chain by using ";" internally -# to chain commands together rather than "&&", so "?!SEMI?!" is never removed -# from a line (even though "?!AMP?!" might be). +# to chain commands together rather than "&&", so "?!SEMI?!" is not removed +# from such a line; however, if the line ends with "?!SEMI?!", then the ";" is +# harmless and the annotation is removed. # # Care is taken to recognize the last _statement_ of a multi-line subshell, not # necessarily the last textual _line_ within the subshell, since &&-chaining @@ -303,7 +304,7 @@ bcase # that line legitimately lacks "&&" :else x -s/ ?!AMP?!$// +s/\( ?!SEMI?!\)* ?!AMP?!$// x bcont @@ -311,7 +312,7 @@ bcont # "suspect" from final contained line since that line legitimately lacks "&&" :done x -s/ ?!AMP?!$// +s/\( ?!SEMI?!\)* ?!AMP?!$// x # is 'done' or 'fi' cuddled with ")" to close subshell? /done.*)/bclose @@ -354,7 +355,7 @@ bblock # since that line legitimately lacks "&&" and exit subshell loop :clssolo x -s/ ?!AMP?!$// +s/\( ?!SEMI?!\)* ?!AMP?!$// p x s/^/>/ diff --git a/t/chainlint/semicolon.expect b/t/chainlint/semicolon.expect index d2d804f5b0..0e6389f532 100644 --- a/t/chainlint/semicolon.expect +++ b/t/chainlint/semicolon.expect @@ -11,10 +11,10 @@ cat foo; ?!SEMI?! echo bar >) && ( - foo; ?!SEMI?! + foo; >) && ( cd foo && for i in a b c; do - echo; ?!SEMI?! + echo; > done) From patchwork Mon Dec 13 06:30:53 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Sunshine X-Patchwork-Id: 12673121 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 DE73FC433F5 for ; Mon, 13 Dec 2021 06:32:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232284AbhLMGcO (ORCPT ); Mon, 13 Dec 2021 01:32:14 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40124 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232227AbhLMGcG (ORCPT ); Mon, 13 Dec 2021 01:32:06 -0500 Received: from mail-il1-x131.google.com (mail-il1-x131.google.com [IPv6:2607:f8b0:4864:20::131]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AE674C0613F8 for ; Sun, 12 Dec 2021 22:32:05 -0800 (PST) Received: by mail-il1-x131.google.com with SMTP id w1so14069108ilh.9 for ; Sun, 12 Dec 2021 22:32:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=zdbO7Uz2W700OsYWOOJ8CEkm4cOJGIvldeSXHWdNciQ=; b=odqqaV4WUXKry2PR0kYEgO15fvU4pjC/ke3vw153V/GmKfbReqaMI4OU7D0G0G7pb1 Ik2CH1mplcXk3hIwmx4CLITD4n7z12wvC6xXqX6uhy7s/VuJfk2SznGpnPMVIYTleas/ DsArzWSCERnMV3IgxNmD/pquxZZgpVCPlIOeFPENoKZIpR10o7fms/Pf1vlSlH/vEUAQ /R9hi/kdpOKsr8+qEHE5asceHPx3Qg0fGGRdj4V8XjqRStRoNZX0+i7VU5qwL6Hd8On2 QNC70T6Z3363bMU88okI5/xe0e/UYw3Iafy1uhSDybyU3Cnw/FQzkGhZbpzaPxta7VJF nrqw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=zdbO7Uz2W700OsYWOOJ8CEkm4cOJGIvldeSXHWdNciQ=; b=7V4b+T7n+HWWlgbXcPY3GR/lHlaqaey/sf2FRXqm+wOT+4UTcpypk3uafJx6ZGVCEo nHrlRgQi51Cu1NrVSCFeYUn5oX07bn7hUlx6Z7Zwi2rI+X71m5BHy4zcGvR1Ed6uzfiM N2Oed+XgAlHsyNwIU//yGcMbi3SL++Zz8NRvOqEEBrRukY+2gZrynhcU+VR+V44dqZre xcESdk7fb9tCgPiLWmKJXFibB3Cps5E6B29yY/zjYY1CB1dYzJPeY6Dgi1fFH8NBspKh QcinTXd8+G7R1SZfzVdzIPyN14JrmJVR8ClS/i/5F2RUkPsKcAt2xwvC2Hg+Mp5dJI/0 0Q4g== X-Gm-Message-State: AOAM53076P/iNMKaQXy1G8/w6MURuNz+yoqHoy4IV01FwTsmvI8UCnVZ S+BeCJrXj0hUB2cwiMk1tOiDudTXVJHVxA== X-Google-Smtp-Source: ABdhPJwn2W4q/Bqi5bnZROf+mz/tcxR2tDEZ35WhI1B0zC6nSLyJ3FNUt0JdhmXAHTfraNp1nn9Thw== X-Received: by 2002:a05:6e02:1c88:: with SMTP id w8mr32319457ill.318.1639377124862; Sun, 12 Dec 2021 22:32:04 -0800 (PST) Received: from localhost.localdomain (097-069-216-153.res.spectrum.com. [97.69.216.153]) by smtp.gmail.com with ESMTPSA id f10sm7305408ils.13.2021.12.12.22.32.04 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sun, 12 Dec 2021 22:32:04 -0800 (PST) Sender: Eric Sunshine From: Eric Sunshine To: git@vger.kernel.org Cc: Jeff King , Elijah Newren , Fabian Stelzer , Eric Sunshine Subject: [PATCH 09/15] chainlint.sed: drop unnecessary distinction between ?!AMP?! and ?!SEMI?! Date: Mon, 13 Dec 2021 01:30:53 -0500 Message-Id: <20211213063059.19424-10-sunshine@sunshineco.com> X-Mailer: git-send-email 2.34.1.397.gfae76fe5da In-Reply-To: <20211213063059.19424-1-sunshine@sunshineco.com> References: <20211213063059.19424-1-sunshine@sunshineco.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From inception, when chainlint.sed encountered a line using semicolon to separate commands rather than `&&`, it would insert a ?!SEMI?! annotation at the beginning of the line rather ?!AMP?! even though the &&-chain is also broken by the semicolon. Given a line such as: ?!SEMI?! cmd1; cmd2 && the ?!SEMI?! annotation makes it easier to see what the problem is than if the output had been: ?!AMP?! cmd1; cmd2 && which might confuse the test author into thinking that the linter is broken (since the line clearly ends with `&&`). However, now that the ?!AMP?! an ?!SEMI?! annotations are inserted at the point of breakage rather than at the beginning of the line, and taking into account that both represent a broken &&-chain, there is little reason to distinguish between the two. Using ?!AMP?! alone is sufficient to point the test author at the problem. For instance, in: cmd1; ?!AMP?! cmd2 && cmd3 it is clear that the &&-chain is broken between `cmd1` and `cmd2`. Likewise, in: cmd1 && cmd2 ?!AMP?! cmd3 it is clear that the &&-chain is broken between `cmd2` and `cmd3`. Finally, in: cmd1; ?!AMP?! cmd2 ?!AMP?! cmd3 it is clear that the &&-chain is broken between each command. Hence, there is no longer a good reason to make a distinction between a broken &&-chain due to a semicolon and a broken chain due to a missing `&&` at end-of-line. Therefore, drop the ?!SEMI?! annotation and use ?!AMP?! exclusively. Signed-off-by: Eric Sunshine --- t/chainlint.sed | 21 ++++++++++----------- t/chainlint/negated-one-liner.expect | 4 ++-- t/chainlint/one-liner.expect | 6 +++--- t/chainlint/semicolon.expect | 10 +++++----- t/chainlint/subshell-one-liner.expect | 8 ++++---- 5 files changed, 24 insertions(+), 25 deletions(-) diff --git a/t/chainlint.sed b/t/chainlint.sed index 91077b6e26..f5fcca09ca 100644 --- a/t/chainlint.sed +++ b/t/chainlint.sed @@ -24,9 +24,9 @@ # in order to avoid misinterpreting the ")" in constructs such as "x=$(...)" # and "case $x in *)" as ending the subshell. # -# Lines missing a final "&&" are flagged with "?!AMP?!", and lines which chain -# commands with ";" internally rather than "&&" are flagged "?!SEMI?!". A line -# may be flagged for both violations. +# Lines missing a final "&&" are flagged with "?!AMP?!", as are lines which +# chain commands with ";" internally rather than "&&". A line may be flagged +# for both violations. # # Detection of a missing &&-link in a multi-line subshell is complicated by the # fact that the last statement before the closing ")" must not end with "&&". @@ -47,9 +47,8 @@ # "?!AMP?!" violation is removed from the "bar" line (retrieved from the "hold" # area) since the final statement of a subshell must not end with "&&". The # final line of a subshell may still break the &&-chain by using ";" internally -# to chain commands together rather than "&&", so "?!SEMI?!" is not removed -# from such a line; however, if the line ends with "?!SEMI?!", then the ";" is -# harmless and the annotation is removed. +# to chain commands together rather than "&&", but an internal "?!AMP?!" is +# never removed from a line even though a line-ending "?!AMP?!" might be. # # Care is taken to recognize the last _statement_ of a multi-line subshell, not # necessarily the last textual _line_ within the subshell, since &&-chaining @@ -127,7 +126,7 @@ b # "&&" (but not ";" in a string) :oneline /;/{ - /"[^"]*;[^"]*"/!s/;/; ?!SEMI?!/ + /"[^"]*;[^"]*"/!s/;/; ?!AMP?!/ } b @@ -231,7 +230,7 @@ s/.*\n// # string and not ";;" in one-liner "case...esac") /;/{ /;;/!{ - /"[^"]*;[^"]*"/!s/;/; ?!SEMI?!/ + /"[^"]*;[^"]*"/!s/;/; ?!AMP?!/ } } # line ends with pipe "...|" -- valid; not missing "&&" @@ -304,7 +303,7 @@ bcase # that line legitimately lacks "&&" :else x -s/\( ?!SEMI?!\)* ?!AMP?!$// +s/\( ?!AMP?!\)* ?!AMP?!$// x bcont @@ -312,7 +311,7 @@ bcont # "suspect" from final contained line since that line legitimately lacks "&&" :done x -s/\( ?!SEMI?!\)* ?!AMP?!$// +s/\( ?!AMP?!\)* ?!AMP?!$// x # is 'done' or 'fi' cuddled with ")" to close subshell? /done.*)/bclose @@ -355,7 +354,7 @@ bblock # since that line legitimately lacks "&&" and exit subshell loop :clssolo x -s/\( ?!SEMI?!\)* ?!AMP?!$// +s/\( ?!AMP?!\)* ?!AMP?!$// p x s/^/>/ diff --git a/t/chainlint/negated-one-liner.expect b/t/chainlint/negated-one-liner.expect index 60baf84b7a..ad4c2d949e 100644 --- a/t/chainlint/negated-one-liner.expect +++ b/t/chainlint/negated-one-liner.expect @@ -1,5 +1,5 @@ ! (foo && bar) && ! (foo && bar) >baz && -! (foo; ?!SEMI?! bar) && -! (foo; ?!SEMI?! bar) >baz +! (foo; ?!AMP?! bar) && +! (foo; ?!AMP?! bar) >baz diff --git a/t/chainlint/one-liner.expect b/t/chainlint/one-liner.expect index 3b46554728..57a7a444c1 100644 --- a/t/chainlint/one-liner.expect +++ b/t/chainlint/one-liner.expect @@ -2,8 +2,8 @@ (foo && bar) | (foo && bar) >baz && -(foo; ?!SEMI?! bar) && -(foo; ?!SEMI?! bar) | -(foo; ?!SEMI?! bar) >baz && +(foo; ?!AMP?! bar) && +(foo; ?!AMP?! bar) | +(foo; ?!AMP?! bar) >baz && (foo "bar; baz") diff --git a/t/chainlint/semicolon.expect b/t/chainlint/semicolon.expect index 0e6389f532..54a08ce582 100644 --- a/t/chainlint/semicolon.expect +++ b/t/chainlint/semicolon.expect @@ -1,14 +1,14 @@ ( - cat foo ; ?!SEMI?! echo bar ?!AMP?! - cat foo ; ?!SEMI?! echo bar + cat foo ; ?!AMP?! echo bar ?!AMP?! + cat foo ; ?!AMP?! echo bar >) && ( - cat foo ; ?!SEMI?! echo bar && - cat foo ; ?!SEMI?! echo bar + cat foo ; ?!AMP?! echo bar && + cat foo ; ?!AMP?! echo bar >) && ( echo "foo; bar" && - cat foo; ?!SEMI?! echo bar + cat foo; ?!AMP?! echo bar >) && ( foo; diff --git a/t/chainlint/subshell-one-liner.expect b/t/chainlint/subshell-one-liner.expect index 432217801b..4b44632b09 100644 --- a/t/chainlint/subshell-one-liner.expect +++ b/t/chainlint/subshell-one-liner.expect @@ -2,13 +2,13 @@ (foo && bar) && (foo && bar) | (foo && bar) >baz && - (foo; ?!SEMI?! bar) && - (foo; ?!SEMI?! bar) | - (foo; ?!SEMI?! bar) >baz && + (foo; ?!AMP?! bar) && + (foo; ?!AMP?! bar) | + (foo; ?!AMP?! bar) >baz && (foo || exit 1) && (foo || exit 1) | (foo || exit 1) >baz && (foo && bar) ?!AMP?! - (foo && bar; ?!SEMI?! baz) ?!AMP?! + (foo && bar; ?!AMP?! baz) ?!AMP?! foobar >) From patchwork Mon Dec 13 06:30:54 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Sunshine X-Patchwork-Id: 12673123 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 537FCC433FE for ; Mon, 13 Dec 2021 06:32:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232298AbhLMGcQ (ORCPT ); Mon, 13 Dec 2021 01:32:16 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40132 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232253AbhLMGcH (ORCPT ); Mon, 13 Dec 2021 01:32:07 -0500 Received: from mail-il1-x12a.google.com (mail-il1-x12a.google.com [IPv6:2607:f8b0:4864:20::12a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C9CD6C061751 for ; Sun, 12 Dec 2021 22:32:06 -0800 (PST) Received: by mail-il1-x12a.google.com with SMTP id 15so14117898ilq.2 for ; Sun, 12 Dec 2021 22:32:06 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=QCSoY7ggtnhfI+VwdAzKV6um1gZRYM13kmApTd0s+7I=; b=gv3FB8x+q3BqHJjaZZ6XrtWFDMm+ZaD3U7el5k3cONIKnwo1vgwYePny9grabraQDQ J7NFfltOQt1viCAUXBEATXxUccGEy14Pt0laovOt/N329RQU0OPF4/yUlB3GIZdZUM+V PfujcsIFYlGLYI86wG3uAR+xM8GtWpNDEHMldaXpcJLSJAOaDx3/jJfRMWx6/nyPQNDH 9JyOGRTGoHVl7Wxa9CJ9HBC/3fsXjMnZyG62W/9yoIwfn8kb2vw5kQbSKBPOOl4UM5HL CrL0VS4/kAma4yyhVn2i3RU4QcmJWcCfoBD5+soYvkoTCguLiY+ujGWwcsWX+dXBgdHJ 9F4A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=QCSoY7ggtnhfI+VwdAzKV6um1gZRYM13kmApTd0s+7I=; b=kIDwmfZXVQsRfeVj/LfY/vpv4WLZt3MC2zHiWsPFbu72bHNobbMl0z6dRnT4BI7bMw PwBEJrvK7RiX5gcnXHloN0k86R2aOm7KKUR3W2M7lIJbbVi8De0VL1o1AUA+aj3+mYwG OoUC31dzX+z8TnyqRTEhirD1QIi5g50BG0f7tY061RHetwTnMgyDtiF1hK8TW5O/YmHC YMQTX/d/e0I8FRXeFHTt9jm4iC5yFm5MUEt4Ra02Ezjn+XTIGhdl0nD95GPM2yDQcF5D TIYPBNsWhG4rhrDDO1v33pM+hhOWA8uo9qLTFv5EsC2FmhJ8tPUXzBcA6+DFxn7WvYzs Q6SQ== X-Gm-Message-State: AOAM533eKG78+kfvriyIkeFbzCt3B6l1TaQN9p0TFxUuotj6wBPC6KuN wHu25nXlijsQ8rQYQ5WqFlLCydZuCzrUuQ== X-Google-Smtp-Source: ABdhPJyE+Z5+EEMsL8jPK5yt9Ku9Re/HPI9OHwC8ozAhsMhMgJXVt7nNgPOwe8GVzQOKjRPutW4v/A== X-Received: by 2002:a92:ca07:: with SMTP id j7mr33510641ils.36.1639377125662; Sun, 12 Dec 2021 22:32:05 -0800 (PST) Received: from localhost.localdomain (097-069-216-153.res.spectrum.com. [97.69.216.153]) by smtp.gmail.com with ESMTPSA id f10sm7305408ils.13.2021.12.12.22.32.04 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sun, 12 Dec 2021 22:32:05 -0800 (PST) Sender: Eric Sunshine From: Eric Sunshine To: git@vger.kernel.org Cc: Jeff King , Elijah Newren , Fabian Stelzer , Eric Sunshine Subject: [PATCH 10/15] chainlint.sed: drop subshell-closing ">" annotation Date: Mon, 13 Dec 2021 01:30:54 -0500 Message-Id: <20211213063059.19424-11-sunshine@sunshineco.com> X-Mailer: git-send-email 2.34.1.397.gfae76fe5da In-Reply-To: <20211213063059.19424-1-sunshine@sunshineco.com> References: <20211213063059.19424-1-sunshine@sunshineco.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org chainlint.sed inserts a ">" annotation at the beginning of a line to signal that its heuristics have identified an end-of-subshell. This was useful as a debugging aid during development of the script, but it has no value to test writers and might even confuse them into thinking that the linter is misbehaving by inserting line-noise into the shell code it is validating. Moreover, its presence also potentially makes it difficult to reuse the chainlint self-test "expect" output should a more capable linter ever be developed. Therefore, drop the ">" annotation. Signed-off-by: Eric Sunshine --- t/chainlint.sed | 9 --------- t/chainlint/arithmetic-expansion.expect | 4 ++-- t/chainlint/bash-array.expect | 4 ++-- t/chainlint/blank-line.expect | 2 +- t/chainlint/block.expect | 2 +- t/chainlint/broken-chain.expect | 2 +- t/chainlint/case.expect | 6 +++--- .../close-nested-and-parent-together.expect | 2 +- t/chainlint/close-subshell.expect | 16 ++++++++-------- t/chainlint/command-substitution.expect | 4 ++-- t/chainlint/comment.expect | 2 +- t/chainlint/complex-if-in-cuddled-loop.expect | 2 +- t/chainlint/cuddled-if-then-else.expect | 2 +- t/chainlint/cuddled-loop.expect | 2 +- t/chainlint/cuddled.expect | 10 +++++----- t/chainlint/exit-loop.expect | 6 +++--- t/chainlint/exit-subshell.expect | 2 +- t/chainlint/for-loop.expect | 2 +- t/chainlint/here-doc-close-subshell.expect | 2 +- .../here-doc-multi-line-command-subst.expect | 4 ++-- t/chainlint/here-doc-multi-line-string.expect | 2 +- t/chainlint/if-in-loop.expect | 2 +- t/chainlint/if-then-else.expect | 4 ++-- t/chainlint/incomplete-line.expect | 2 +- t/chainlint/inline-comment.expect | 4 ++-- t/chainlint/loop-in-if.expect | 2 +- ...multi-line-nested-command-substitution.expect | 10 +++++----- t/chainlint/multi-line-string.expect | 4 ++-- t/chainlint/nested-cuddled-subshell.expect | 14 +++++++------- t/chainlint/nested-here-doc.expect | 2 +- t/chainlint/nested-subshell-comment.expect | 4 ++-- t/chainlint/nested-subshell.expect | 6 +++--- t/chainlint/p4-filespec.expect | 2 +- t/chainlint/pipe.expect | 2 +- t/chainlint/semicolon.expect | 10 +++++----- t/chainlint/subshell-here-doc.expect | 4 ++-- t/chainlint/subshell-one-liner.expect | 2 +- t/chainlint/t7900-subtree.expect | 6 +++--- t/chainlint/while-loop.expect | 2 +- 39 files changed, 80 insertions(+), 89 deletions(-) diff --git a/t/chainlint.sed b/t/chainlint.sed index f5fcca09ca..2689e13636 100644 --- a/t/chainlint.sed +++ b/t/chainlint.sed @@ -76,12 +76,6 @@ # newline, thus the closing here-doc tag has been found. The closing tag line # and the "<...>" prefix on the target line are then discarded, leaving just # the target line "cat >out". -# -# To facilitate regression testing (and manual debugging), a ">" annotation is -# applied to the line containing ")" which closes a subshell, ">>" to a line -# closing a nested subshell, and ">>>" to a line closing both at once. This -# makes it easy to detect whether the heuristics correctly identify -# end-of-subshell. #------------------------------------------------------------------------------ # incomplete line -- slurp up next line @@ -337,7 +331,6 @@ n x bnstslrp :nstcl -s/^/>>/ # is it "))" which closes nested and parent subshells? /)[ ]*)/bslurp bchkchn @@ -357,7 +350,6 @@ x s/\( ?!AMP?!\)* ?!AMP?!$// p x -s/^/>/ b # found closing "...)" -- exit subshell loop @@ -365,5 +357,4 @@ b x p x -s/^/>/ b diff --git a/t/chainlint/arithmetic-expansion.expect b/t/chainlint/arithmetic-expansion.expect index 56cd5b69f5..46ee1046af 100644 --- a/t/chainlint/arithmetic-expansion.expect +++ b/t/chainlint/arithmetic-expansion.expect @@ -2,8 +2,8 @@ foo && bar=$((42 + 1)) && baz ->) && +) && ( bar=$((42 + 1)) ?!AMP?! baz ->) +) diff --git a/t/chainlint/bash-array.expect b/t/chainlint/bash-array.expect index c4a830d1c1..4c34eaee45 100644 --- a/t/chainlint/bash-array.expect +++ b/t/chainlint/bash-array.expect @@ -2,9 +2,9 @@ foo && bar=(gumbo stumbo wumbo) && baz ->) && +) && ( foo && bar=${#bar[@]} && baz ->) +) diff --git a/t/chainlint/blank-line.expect b/t/chainlint/blank-line.expect index 3be939ed38..f76fde1ffb 100644 --- a/t/chainlint/blank-line.expect +++ b/t/chainlint/blank-line.expect @@ -1,4 +1,4 @@ ( nothing && something ->) +) diff --git a/t/chainlint/block.expect b/t/chainlint/block.expect index 6333237cb2..da60257ebc 100644 --- a/t/chainlint/block.expect +++ b/t/chainlint/block.expect @@ -9,4 +9,4 @@ echo c } ?!AMP?! baz ->) +) diff --git a/t/chainlint/broken-chain.expect b/t/chainlint/broken-chain.expect index 0960a8c7c0..cfb58fb6b9 100644 --- a/t/chainlint/broken-chain.expect +++ b/t/chainlint/broken-chain.expect @@ -3,4 +3,4 @@ bar ?!AMP?! baz && wop ->) +) diff --git a/t/chainlint/case.expect b/t/chainlint/case.expect index a4b92d4613..31f280d8ce 100644 --- a/t/chainlint/case.expect +++ b/t/chainlint/case.expect @@ -4,16 +4,16 @@ *) bar ;; esac && foobar ->) && +) && ( case "$x" in x) foo ;; *) bar ;; esac ?!AMP?! foobar ->) && +) && ( case "$x" in 1) true;; esac && case "$y" in 2) false;; esac ?!AMP?! foobar ->) +) diff --git a/t/chainlint/close-nested-and-parent-together.expect b/t/chainlint/close-nested-and-parent-together.expect index 2a910f9d66..5ef509eb49 100644 --- a/t/chainlint/close-nested-and-parent-together.expect +++ b/t/chainlint/close-nested-and-parent-together.expect @@ -1,4 +1,4 @@ ( cd foo && (bar && ->>> baz)) + baz)) diff --git a/t/chainlint/close-subshell.expect b/t/chainlint/close-subshell.expect index 184688718a..0f87db9ae6 100644 --- a/t/chainlint/close-subshell.expect +++ b/t/chainlint/close-subshell.expect @@ -1,25 +1,25 @@ ( foo ->) && +) && ( bar ->) >out && +) >out && ( baz ->) 2>err && +) 2>err && ( boo ->) ) | wuzzle && +) | wuzzle && ( bop ->) | fazz fozz && +) | fazz fozz && ( bup ->) | +) | fuzzle && ( yop ->) +) diff --git a/t/chainlint/command-substitution.expect b/t/chainlint/command-substitution.expect index f276067b7b..c72e4df9e7 100644 --- a/t/chainlint/command-substitution.expect +++ b/t/chainlint/command-substitution.expect @@ -2,8 +2,8 @@ foo && bar=$(gobble) && baz ->) && +) && ( bar=$(gobble blocks) ?!AMP?! baz ->) +) diff --git a/t/chainlint/comment.expect b/t/chainlint/comment.expect index 3be939ed38..f76fde1ffb 100644 --- a/t/chainlint/comment.expect +++ b/t/chainlint/comment.expect @@ -1,4 +1,4 @@ ( nothing && something ->) +) diff --git a/t/chainlint/complex-if-in-cuddled-loop.expect b/t/chainlint/complex-if-in-cuddled-loop.expect index 9674b88cf2..b8aa626ed0 100644 --- a/t/chainlint/complex-if-in-cuddled-loop.expect +++ b/t/chainlint/complex-if-in-cuddled-loop.expect @@ -6,5 +6,5 @@ for i in a b c; do else echo >file fi -> done) && + done) && test ! -f file diff --git a/t/chainlint/cuddled-if-then-else.expect b/t/chainlint/cuddled-if-then-else.expect index ab2a026fbc..4e089b087a 100644 --- a/t/chainlint/cuddled-if-then-else.expect +++ b/t/chainlint/cuddled-if-then-else.expect @@ -3,5 +3,5 @@ if test -z ""; then echo empty else echo bizzy -> fi) && + fi) && echo foobar diff --git a/t/chainlint/cuddled-loop.expect b/t/chainlint/cuddled-loop.expect index 8c0260d7f1..7932303763 100644 --- a/t/chainlint/cuddled-loop.expect +++ b/t/chainlint/cuddled-loop.expect @@ -1,5 +1,5 @@ ( while read x do foobar bop || exit 1 -> done ) && +) && ( cd foo ?!AMP?! bar ->) && +) && ( cd foo && -> bar) && + bar) && ( cd foo && -> bar) && + bar) && ( cd foo ?!AMP?! -> bar) + bar) diff --git a/t/chainlint/exit-loop.expect b/t/chainlint/exit-loop.expect index 84d8bdebc0..f76aa60466 100644 --- a/t/chainlint/exit-loop.expect +++ b/t/chainlint/exit-loop.expect @@ -5,7 +5,7 @@ bar && baz done ->) && +) && ( while true do @@ -13,7 +13,7 @@ bar && baz done ->) && +) && ( i=0 && while test $i -lt 10 @@ -21,4 +21,4 @@ echo $i || exit i=$(($i + 1)) done ->) +) diff --git a/t/chainlint/exit-subshell.expect b/t/chainlint/exit-subshell.expect index bf78454f74..da80339f78 100644 --- a/t/chainlint/exit-subshell.expect +++ b/t/chainlint/exit-subshell.expect @@ -2,4 +2,4 @@ foo || exit 1 bar && baz ->) +) diff --git a/t/chainlint/for-loop.expect b/t/chainlint/for-loop.expect index dc209e21bd..b74df064c5 100644 --- a/t/chainlint/for-loop.expect +++ b/t/chainlint/for-loop.expect @@ -8,4 +8,4 @@ echo $i && cat $i done ->) +) diff --git a/t/chainlint/here-doc-close-subshell.expect b/t/chainlint/here-doc-close-subshell.expect index f011e335e5..e748526570 100644 --- a/t/chainlint/here-doc-close-subshell.expect +++ b/t/chainlint/here-doc-close-subshell.expect @@ -1,2 +1,2 @@ ( -> cat) + cat) diff --git a/t/chainlint/here-doc-multi-line-command-subst.expect b/t/chainlint/here-doc-multi-line-command-subst.expect index 3a35bb014c..f1248f8ade 100644 --- a/t/chainlint/here-doc-multi-line-command-subst.expect +++ b/t/chainlint/here-doc-multi-line-command-subst.expect @@ -1,5 +1,5 @@ ( x=$(bobble && ->> wiffle) ?!AMP?! + wiffle) ?!AMP?! echo $x ->) +) diff --git a/t/chainlint/here-doc-multi-line-string.expect b/t/chainlint/here-doc-multi-line-string.expect index a3b9a5472d..7e883b252e 100644 --- a/t/chainlint/here-doc-multi-line-string.expect +++ b/t/chainlint/here-doc-multi-line-string.expect @@ -1,4 +1,4 @@ ( cat && echo "multi-line string" ?!AMP?! bap ->) +) diff --git a/t/chainlint/if-in-loop.expect b/t/chainlint/if-in-loop.expect index 7d91837269..03b82a3e58 100644 --- a/t/chainlint/if-in-loop.expect +++ b/t/chainlint/if-in-loop.expect @@ -9,4 +9,4 @@ foo done ?!AMP?! bar ->) +) diff --git a/t/chainlint/if-then-else.expect b/t/chainlint/if-then-else.expect index 3055d5606c..debcf7b756 100644 --- a/t/chainlint/if-then-else.expect +++ b/t/chainlint/if-then-else.expect @@ -11,10 +11,10 @@ cat fi ?!AMP?! echo poodle ->) && +) && ( if test -n ""; then echo very && echo empty fi ->) +) diff --git a/t/chainlint/incomplete-line.expect b/t/chainlint/incomplete-line.expect index 2f3ebabdc2..ffac8f9018 100644 --- a/t/chainlint/incomplete-line.expect +++ b/t/chainlint/incomplete-line.expect @@ -1,4 +1,4 @@ line 1 line 2 line 3 line 4 && ( line 5 line 6 line 7 line 8 ->) +) diff --git a/t/chainlint/inline-comment.expect b/t/chainlint/inline-comment.expect index 3d655a32b0..f6b42757d2 100644 --- a/t/chainlint/inline-comment.expect +++ b/t/chainlint/inline-comment.expect @@ -2,8 +2,8 @@ foobar && barfoo ?!AMP?! flibble "not a # comment" ->) && +) && ( cd foo && -> flibble "not a # comment") + flibble "not a # comment") diff --git a/t/chainlint/loop-in-if.expect b/t/chainlint/loop-in-if.expect index cebd3ae95e..e1be42376c 100644 --- a/t/chainlint/loop-in-if.expect +++ b/t/chainlint/loop-in-if.expect @@ -9,4 +9,4 @@ foo fi ?!AMP?! bar ->) +) diff --git a/t/chainlint/multi-line-nested-command-substitution.expect b/t/chainlint/multi-line-nested-command-substitution.expect index 59b6c8b850..300058341b 100644 --- a/t/chainlint/multi-line-nested-command-substitution.expect +++ b/t/chainlint/multi-line-nested-command-substitution.expect @@ -3,16 +3,16 @@ x=$( echo bar | cat ->> ) && + ) && echo ok ->) | +) | sort && ( bar && x=$(echo bar | cat ->> ) && + ) && y=$(echo baz | ->> fip) && + fip) && echo fail ->) +) diff --git a/t/chainlint/multi-line-string.expect b/t/chainlint/multi-line-string.expect index f1be2baf0a..ab0dadf748 100644 --- a/t/chainlint/multi-line-string.expect +++ b/t/chainlint/multi-line-string.expect @@ -2,8 +2,8 @@ x="line 1 line 2 line 3" && y="line 1 line2" ?!AMP?! foobar ->) && +) && ( echo "xyz" "abc def ghi" && barfoo ->) +) diff --git a/t/chainlint/nested-cuddled-subshell.expect b/t/chainlint/nested-cuddled-subshell.expect index aa522658ed..2a86885ee6 100644 --- a/t/chainlint/nested-cuddled-subshell.expect +++ b/t/chainlint/nested-cuddled-subshell.expect @@ -1,19 +1,19 @@ ( (cd foo && bar ->> ) && + ) && (cd foo && bar ->> ) ?!AMP?! + ) ?!AMP?! ( cd foo && ->> bar) && + bar) && ( cd foo && ->> bar) ?!AMP?! + bar) ?!AMP?! (cd foo && ->> bar) && + bar) && (cd foo && ->> bar) ?!AMP?! + bar) ?!AMP?! foobar ->) +) diff --git a/t/chainlint/nested-here-doc.expect b/t/chainlint/nested-here-doc.expect index f9604d3fac..2a51205d32 100644 --- a/t/chainlint/nested-here-doc.expect +++ b/t/chainlint/nested-here-doc.expect @@ -4,4 +4,4 @@ cat >foop && cat && cat ?!AMP?! foobar ->) +) diff --git a/t/chainlint/nested-subshell-comment.expect b/t/chainlint/nested-subshell-comment.expect index 925e49bae9..9138cf386d 100644 --- a/t/chainlint/nested-subshell-comment.expect +++ b/t/chainlint/nested-subshell-comment.expect @@ -6,6 +6,6 @@ # minor numbers of cows (or do they?) baz && snaff ->> ) ?!AMP?! + ) ?!AMP?! fuzzy ->) +) diff --git a/t/chainlint/nested-subshell.expect b/t/chainlint/nested-subshell.expect index c8165ad19e..41a48adaa2 100644 --- a/t/chainlint/nested-subshell.expect +++ b/t/chainlint/nested-subshell.expect @@ -3,10 +3,10 @@ ( echo a && echo b ->> ) >file && + ) >file && cd foo && ( echo a echo b ->> ) >file ->) + ) >file +) diff --git a/t/chainlint/p4-filespec.expect b/t/chainlint/p4-filespec.expect index 98b3d881fd..1290fd1ff2 100644 --- a/t/chainlint/p4-filespec.expect +++ b/t/chainlint/p4-filespec.expect @@ -1,4 +1,4 @@ ( p4 print -1 //depot/fiddle#42 >file && foobar ->) +) diff --git a/t/chainlint/pipe.expect b/t/chainlint/pipe.expect index ede6bcc607..2cfc028297 100644 --- a/t/chainlint/pipe.expect +++ b/t/chainlint/pipe.expect @@ -5,4 +5,4 @@ fish | cow ?!AMP?! sunder ->) +) diff --git a/t/chainlint/semicolon.expect b/t/chainlint/semicolon.expect index 54a08ce582..05141a96cf 100644 --- a/t/chainlint/semicolon.expect +++ b/t/chainlint/semicolon.expect @@ -1,20 +1,20 @@ ( cat foo ; ?!AMP?! echo bar ?!AMP?! cat foo ; ?!AMP?! echo bar ->) && +) && ( cat foo ; ?!AMP?! echo bar && cat foo ; ?!AMP?! echo bar ->) && +) && ( echo "foo; bar" && cat foo; ?!AMP?! echo bar ->) && +) && ( foo; ->) && +) && ( cd foo && for i in a b c; do echo; -> done) + done) diff --git a/t/chainlint/subshell-here-doc.expect b/t/chainlint/subshell-here-doc.expect index 9d3f25b3f5..b7250ca753 100644 --- a/t/chainlint/subshell-here-doc.expect +++ b/t/chainlint/subshell-here-doc.expect @@ -2,9 +2,9 @@ echo wobba gorgo snoot wafta snurb && cat >bip ?!AMP?! echo >bop ->) && +) && ( cat >bup && cat >bup3 && meep ->) +) diff --git a/t/chainlint/subshell-one-liner.expect b/t/chainlint/subshell-one-liner.expect index 4b44632b09..b7015361bf 100644 --- a/t/chainlint/subshell-one-liner.expect +++ b/t/chainlint/subshell-one-liner.expect @@ -11,4 +11,4 @@ (foo && bar) ?!AMP?! (foo && bar; ?!AMP?! baz) ?!AMP?! foobar ->) +) diff --git a/t/chainlint/t7900-subtree.expect b/t/chainlint/t7900-subtree.expect index f769244ef6..215aca01c2 100644 --- a/t/chainlint/t7900-subtree.expect +++ b/t/chainlint/t7900-subtree.expect @@ -1,10 +1,10 @@ ( chks="sub1sub2sub3sub4" && chks_sub=$(cat | sed "s,^,sub dir/," ->>) && +) && chkms="main-sub1main-sub2main-sub3main-sub4" && chkms_sub=$(cat | sed "s,^,sub dir/," ->>) && +) && subfiles=$(git ls-files) && check_equal "$subfiles" "$chkms$chks" ->) +) diff --git a/t/chainlint/while-loop.expect b/t/chainlint/while-loop.expect index f8b9fcf62b..e2813b378e 100644 --- a/t/chainlint/while-loop.expect +++ b/t/chainlint/while-loop.expect @@ -8,4 +8,4 @@ echo foo && cat bar done ->) +) From patchwork Mon Dec 13 06:30:55 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Sunshine X-Patchwork-Id: 12673125 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 CD25CC433F5 for ; Mon, 13 Dec 2021 06:32:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232268AbhLMGcR (ORCPT ); Mon, 13 Dec 2021 01:32:17 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40138 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232248AbhLMGcH (ORCPT ); Mon, 13 Dec 2021 01:32:07 -0500 Received: from mail-il1-x130.google.com (mail-il1-x130.google.com [IPv6:2607:f8b0:4864:20::130]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 27481C0617A2 for ; Sun, 12 Dec 2021 22:32:07 -0800 (PST) Received: by mail-il1-x130.google.com with SMTP id i13so3235915ilk.13 for ; Sun, 12 Dec 2021 22:32:07 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=6E58MIW/2W+ewUn8HNh40biFKgvMgBcrxH/UBIAPcA8=; b=TGs5ghwjzEb1zMg3Q4sDrwsnUfmHLz217su7wojRvEIwxETbIxGwJTjJObQ0k1DFzf nks807PnBOP9BQIzkicUwajLUs1OhWxTddTOc7v2aO8bN1G6Cix5+oICsLoGawguCEDG H9S8Nu5vhswE0eFBhzKmgV4PJthVXaBIfSwLwKYMv9RJoMKXN9MxqBHA5aDaZSJGzbIh 2E4wo4Ipm+4+H/bLSWMQV+e2gS8PLpcYCenk775FSMpnYPXV2+JOa87G4egkkjIhRFJi di8iM6S/qw0Mo4qVwwNP84Visk+mcTBK3Rc1hlIjRisb22jmaTlc76lrq/o2m8pJhjSx /dYw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=6E58MIW/2W+ewUn8HNh40biFKgvMgBcrxH/UBIAPcA8=; b=6S3oQX5/3mYER5hXCMH1sPnb9DNuIOe2un+zApxKavzPBjGaODmiGRTwgGCwNDUvp5 EjKqVPDiEQyDoC+w1nc/jwb03hnLuaBygFGEUC1Jo8oMa1xSVTH9wSQtxCD4bOv4WWY/ Wzp8c0BjOu3z+C8UtC77nz9EaO4mRbDhl5RkfJKSaSDvWyFM+f3wt8WKuAzhr2LEI8KF wnynp338Il69bZX8Wn7C2RXV9iU7Hwl6ljXUGxuBGJOdZrcobdkLbg9tsMCaA73B9xg/ aAXuv3NfU1ruXe0oguSLB+igQ6BrHJne1mSOqjslvVmguUlB0kHG4Ff/hz0IGCtHXZ/o jXow== X-Gm-Message-State: AOAM530JNeYxITxmFohIKsLYvssc9aAxs/HDtkN7/jLnttBq+XFi7FJN aHsyYHOdVwa5NA19NE6rUm19Go0BvX3CaA== X-Google-Smtp-Source: ABdhPJxwsV8iHP7qYUVl+U5R8grvphnBgwP+s5FJN5Wc1olue6q5W3/+nK5Lilch0EO7Z0qLY9VJzA== X-Received: by 2002:a05:6e02:1a08:: with SMTP id s8mr31971418ild.309.1639377126317; Sun, 12 Dec 2021 22:32:06 -0800 (PST) Received: from localhost.localdomain (097-069-216-153.res.spectrum.com. [97.69.216.153]) by smtp.gmail.com with ESMTPSA id f10sm7305408ils.13.2021.12.12.22.32.05 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sun, 12 Dec 2021 22:32:06 -0800 (PST) Sender: Eric Sunshine From: Eric Sunshine To: git@vger.kernel.org Cc: Jeff King , Elijah Newren , Fabian Stelzer , Eric Sunshine Subject: [PATCH 11/15] chainlint.sed: make here-doc "<<-" operator recognition more POSIX-like Date: Mon, 13 Dec 2021 01:30:55 -0500 Message-Id: <20211213063059.19424-12-sunshine@sunshineco.com> X-Mailer: git-send-email 2.34.1.397.gfae76fe5da In-Reply-To: <20211213063059.19424-1-sunshine@sunshineco.com> References: <20211213063059.19424-1-sunshine@sunshineco.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org According to POSIX, "<<" and "<<-" are distinct shell operators. For the latter to be recognized, no whitespace is allowed before the "-", though whitespace is allowed after the operator. However, the chainlint patterns which identify here-docs are both too loose and too tight, incorrectly allowing whitespace between "<<" and "-" but disallowing it between "-" and the here-doc tag. Fix the patterns to better match POSIX. Signed-off-by: Eric Sunshine --- t/chainlint.sed | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/t/chainlint.sed b/t/chainlint.sed index 2689e13636..b382746526 100644 --- a/t/chainlint.sed +++ b/t/chainlint.sed @@ -88,8 +88,8 @@ # here-doc -- swallow it to avoid false hits within its body (but keep the # command to which it was attached) -/<<[ ]*[-\\'"]*[A-Za-z0-9_]/ { - s/^\(.*\)<<[ ]*[-\\'"]*\([A-Za-z0-9_][A-Za-z0-9_]*\)['"]*/<\2>\1<\1<\1<\1< X-Patchwork-Id: 12673127 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 506CDC433F5 for ; Mon, 13 Dec 2021 06:32:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232314AbhLMGcV (ORCPT ); Mon, 13 Dec 2021 01:32:21 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40176 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232285AbhLMGcO (ORCPT ); Mon, 13 Dec 2021 01:32:14 -0500 Received: from mail-il1-x130.google.com (mail-il1-x130.google.com [IPv6:2607:f8b0:4864:20::130]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EC6B5C061372 for ; Sun, 12 Dec 2021 22:32:07 -0800 (PST) Received: by mail-il1-x130.google.com with SMTP id s11so14126198ilv.3 for ; Sun, 12 Dec 2021 22:32:07 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Hn1CKW6++4/5+8GA6JoFYuRpEbYwp+GZI9pe0gFC6nM=; b=KbYzQodEBPTeJNlhjw0fPHQnrPkpyoZX2CvQaz7gaJhHkgYX3IlTTXMHBuu2SKT55J eX4US6u35I8FnhAc2poFifD1SUQP0zn9d7aALAo89lcP3kx4PS8vc/iOokFQnC6W1dew bI7FojgeAeE2Fp3PI6iFLnGNQWskWYGYAataTVKZMr4JF8UfGkuNryPBZbI+7cH+3v8d bWhckydrksDd+PPy/X0ixeZtE6Giu9gqAOFctjHD7BqP2KXOxtHb2ZKmAXkw2u7+gFu6 mDnNfRbJmKutEVKHqNHxG2tpyj2cuYbXlHQQe1qNlIiBB/rd53K5NbBJXvEWutal/1Oc lKaw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=Hn1CKW6++4/5+8GA6JoFYuRpEbYwp+GZI9pe0gFC6nM=; b=xigupVHvzGru6KXnuyk4YTENnF6qzXrcH8vdrRQCHY2piHSDzA/xv6kwPgGbqo4g1s Rx0JCmSqw9Vi77HRxViDX1DMgz6MpAoj0Qi9dHsY5HvjZhiimyaPcC2H4wTznnrd8e/w EP6vbFdMohO2R1JWVjjHIFJsI5TVH+lKDnLzl9k0e4eIixHK+Ci3TDIZze9E8ymxgmnY XWBEfXWRNllZl88tzEOPanPEvoCBWfBjb9k7t3sOIREGN2G8kKgJcwSLovWKoqlIHe2d LEhnGPv9woaK4FdsBBE0QNYrA9V9R/9A48PxMGuSamKEI/dqYv7HWqeP65MQc6G5Nd2K YRtw== X-Gm-Message-State: AOAM533oPKbUpF6JFlPiAjkSnV/0JDqamatxomPc/n6gLFq8F6RUWBiC 6Y7DsjndImYKmdDOdClsebZNUEnqokdgNQ== X-Google-Smtp-Source: ABdhPJysLIJi1c+B+BLYmsYXLzdJzUU9HTy6vAQpJHNtoaTPwN5woXFyKSh2ZnQHcOAJ4PF7FvqKLg== X-Received: by 2002:a92:c244:: with SMTP id k4mr29454456ilo.169.1639377127085; Sun, 12 Dec 2021 22:32:07 -0800 (PST) Received: from localhost.localdomain (097-069-216-153.res.spectrum.com. [97.69.216.153]) by smtp.gmail.com with ESMTPSA id f10sm7305408ils.13.2021.12.12.22.32.06 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sun, 12 Dec 2021 22:32:06 -0800 (PST) Sender: Eric Sunshine From: Eric Sunshine To: git@vger.kernel.org Cc: Jeff King , Elijah Newren , Fabian Stelzer , Eric Sunshine Subject: [PATCH 12/15] chainlint.sed: don't mistake `<< word` in string as here-doc operator Date: Mon, 13 Dec 2021 01:30:56 -0500 Message-Id: <20211213063059.19424-13-sunshine@sunshineco.com> X-Mailer: git-send-email 2.34.1.397.gfae76fe5da In-Reply-To: <20211213063059.19424-1-sunshine@sunshineco.com> References: <20211213063059.19424-1-sunshine@sunshineco.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Tighten here-doc recognition to prevent it from being fooled by text which looks like a here-doc operator but happens merely to be the content of a string, such as this real-world case from t7201: echo "<<<<<<< ours" && echo ourside && echo "=======" && echo theirside && echo ">>>>>>> theirs" This problem went unnoticed because chainlint.sed is not a real parser, but rather applies heuristics to pretend to understand shell code. In this case, it saw what it thought was a here-doc operator (`<< ours`), and fell off the end of the test looking for the closing tag "ours" which it never found, thus swallowed the remainder of the test without checking it for &&-chain breakage. Signed-off-by: Eric Sunshine --- t/chainlint.sed | 8 ++++++-- t/chainlint/not-heredoc.expect | 14 ++++++++++++++ t/chainlint/not-heredoc.test | 16 ++++++++++++++++ 3 files changed, 36 insertions(+), 2 deletions(-) create mode 100644 t/chainlint/not-heredoc.expect create mode 100644 t/chainlint/not-heredoc.test diff --git a/t/chainlint.sed b/t/chainlint.sed index b382746526..2f786f890d 100644 --- a/t/chainlint.sed +++ b/t/chainlint.sed @@ -89,6 +89,7 @@ # here-doc -- swallow it to avoid false hits within its body (but keep the # command to which it was attached) /<<-*[ ]*[\\'"]*[A-Za-z0-9_]/ { + /"[^"]*<<[^"]*"/bnotdoc s/^\(.*\)<<-*[ ]*[\\'"]*\([A-Za-z0-9_][A-Za-z0-9_]*\)['"]*/<\2>\1<]*>// s/\n.*$// } +:notdoc # one-liner "(...) &&" /^[ ]*!*[ ]*(..*)[ ]*&&[ ]*$/boneline @@ -151,8 +153,10 @@ s/.*\n// /"[^'"]*'[^'"]*"/!bsqstr } :folded -# here-doc -- swallow it -/<<-*[ ]*[\\'"]*[A-Za-z0-9_]/bheredoc +# here-doc -- swallow it (but not "<<" in a string) +/<<-*[ ]*[\\'"]*[A-Za-z0-9_]/{ + /"[^"]*<<[^"]*"/!bheredoc +} # comment or empty line -- discard since final non-comment, non-empty line # before closing ")", "done", "elsif", "else", or "fi" will need to be # re-visited to drop "suspect" marking since final line of those constructs diff --git a/t/chainlint/not-heredoc.expect b/t/chainlint/not-heredoc.expect new file mode 100644 index 0000000000..2e9bb135fe --- /dev/null +++ b/t/chainlint/not-heredoc.expect @@ -0,0 +1,14 @@ +echo "<<<<<<< ours" && +echo ourside && +echo "=======" && +echo theirside && +echo ">>>>>>> theirs" && + +( + echo "<<<<<<< ours" && + echo ourside && + echo "=======" && + echo theirside && + echo ">>>>>>> theirs" ?!AMP?! + poodle +) >merged diff --git a/t/chainlint/not-heredoc.test b/t/chainlint/not-heredoc.test new file mode 100644 index 0000000000..9aa57346cd --- /dev/null +++ b/t/chainlint/not-heredoc.test @@ -0,0 +1,16 @@ +# LINT: "<< ours" inside string is not here-doc +echo "<<<<<<< ours" && +echo ourside && +echo "=======" && +echo theirside && +echo ">>>>>>> theirs" && + +( +# LINT: "<< ours" inside string is not here-doc + echo "<<<<<<< ours" && + echo ourside && + echo "=======" && + echo theirside && + echo ">>>>>>> theirs" + poodle +) >merged From patchwork Mon Dec 13 06:30:57 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Sunshine X-Patchwork-Id: 12673129 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 F1C51C433EF for ; Mon, 13 Dec 2021 06:32:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232224AbhLMGcW (ORCPT ); Mon, 13 Dec 2021 01:32:22 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40178 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232290AbhLMGcP (ORCPT ); Mon, 13 Dec 2021 01:32:15 -0500 Received: from mail-il1-x12b.google.com (mail-il1-x12b.google.com [IPv6:2607:f8b0:4864:20::12b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C0EE8C061201 for ; Sun, 12 Dec 2021 22:32:08 -0800 (PST) Received: by mail-il1-x12b.google.com with SMTP id v13so789342ilm.8 for ; Sun, 12 Dec 2021 22:32:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=7bsOSnyGX0H/4cgERmdUVUrE6yzLyDfJPjeeswTetlo=; b=cYm3yhCHTAZ+Tg0UkZl0adfYBViqxNtsWov9xWwD/9DIPDTt+HsCeIrPPHX0ZUp2vI hyAJIDDaso7OIrkGHbEQwGSzE2VbM0W9gbRZdw1oZWEEn4duW7xBpabiGs0Ud2kvzvbk hVD18gSQ3fdc0m09uCQTqZU9FyB2jbA5IKJ4YoVlrdOt7Fap3wH7jKL9HsDFmOwNMqlx efrUekQLfdPXU2shswvEFnPsHos2OvpKDr2hGfeu5Yq7x8WOiEWCApAA1OfbwnFeVhfK Vr0Mb25hDIZiMmQ2ElRUQgZg/2jVXGruEzxUnbxeOGOpHIR2qsKZ69j70lSXBQ1O25GT k0Aw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=7bsOSnyGX0H/4cgERmdUVUrE6yzLyDfJPjeeswTetlo=; b=najR7E+c3q7K2vkfCZI7drovzlP1LBnQ7sdzkLxFgovf3ztSX0wDhDelG1d8F1miOZ SJaVYbPHgzurRPN83rnAwO+HaC0XUdxDS+K8GWAeFfJQIYy290ku9w/Tv4Q6tPrehHCq dzQ31PU9WU1WQGQkN9nLg/Hou1B1XDSnkErkh/tRjiyuWKw9Kwyh7w4Xf0WIB/aRmTfg g4AlThGDtaxQ3l9h7RR9kfMNun0yNQuYnEUjr94rpjWJvWwBHPk39pIIUWpWbkgeWRYa iZyCAObVsxX5VzE47qJ2Ue9Dv/cdVbohKhWm8ap+hFpy3P1+0dT1lkoxdVfateMpopX3 6Cwg== X-Gm-Message-State: AOAM53148tn068Wb4F1VI2e7wSj9KNg/amRrKNSxbjPrrB+1ClkwYw8R F7OYY+PPpP0cbwi5C/8rgdI0Rq70vlPXdA== X-Google-Smtp-Source: ABdhPJzREDr1lzrBtavlKnq5ziQ/8PP8j6TVPKowzC9+zfm1XfPF/ivMX+Tqy5SQxZH4iPqHFl2cuw== X-Received: by 2002:a05:6e02:16cd:: with SMTP id 13mr3812371ilx.136.1639377127845; Sun, 12 Dec 2021 22:32:07 -0800 (PST) Received: from localhost.localdomain (097-069-216-153.res.spectrum.com. [97.69.216.153]) by smtp.gmail.com with ESMTPSA id f10sm7305408ils.13.2021.12.12.22.32.07 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sun, 12 Dec 2021 22:32:07 -0800 (PST) Sender: Eric Sunshine From: Eric Sunshine To: git@vger.kernel.org Cc: Jeff King , Elijah Newren , Fabian Stelzer , Eric Sunshine Subject: [PATCH 13/15] chainlint.sed: stop throwing away here-doc tags Date: Mon, 13 Dec 2021 01:30:57 -0500 Message-Id: <20211213063059.19424-14-sunshine@sunshineco.com> X-Mailer: git-send-email 2.34.1.397.gfae76fe5da In-Reply-To: <20211213063059.19424-1-sunshine@sunshineco.com> References: <20211213063059.19424-1-sunshine@sunshineco.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org The purpose of chainlint is to highlight problems it finds in test code by inserting annotations at the location of each problem. Arbitrarily eliding bits of the code it is checking is not helpful, yet this is exactly what chainlint.sed does by cavalierly and unnecessarily dropping the here-doc operator and tag; i.e. `cat < --- t/chainlint.sed | 24 ++++++++++++------- t/chainlint/for-loop.expect | 2 +- t/chainlint/here-doc-close-subshell.expect | 2 +- .../here-doc-multi-line-command-subst.expect | 2 +- t/chainlint/here-doc-multi-line-string.expect | 2 +- t/chainlint/here-doc.expect | 8 +++---- t/chainlint/if-then-else.expect | 2 +- t/chainlint/nested-here-doc.expect | 6 ++--- t/chainlint/subshell-here-doc.expect | 10 ++++---- t/chainlint/t7900-subtree.expect | 4 ++-- t/chainlint/while-loop.expect | 2 +- 11 files changed, 35 insertions(+), 29 deletions(-) diff --git a/t/chainlint.sed b/t/chainlint.sed index 2f786f890d..0e575c0c62 100644 --- a/t/chainlint.sed +++ b/t/chainlint.sed @@ -62,20 +62,20 @@ # receives similar treatment. # # Swallowing here-docs with arbitrary tags requires a bit of finesse. When a -# line such as "cat <out" is seen, the here-doc tag is moved to the front -# of the line enclosed in angle brackets as a sentinel, giving "cat >out". +# line such as "cat <cat <\n\1$/ is attempted to see if # the content inside "<...>" matches the entirety of the newly-read line. For # instance, if the next line read is "some data", when concatenated with the -# target line, it becomes "cat >out\nsome data", and a match is attempted +# target line, it becomes "cat <cat >out\nEOF", +# encountered, it is appended to the target line giving "cat <" does match the text following the # newline, thus the closing here-doc tag has been found. The closing tag line # and the "<...>" prefix on the target line are then discarded, leaving just -# the target line "cat >out". +# the target line "cat <\1<\1\2/ :hered N /^<\([^>]*\)>.*\n[ ]*\1[ ]*$/!{ @@ -238,6 +237,7 @@ s/.*\n// :cont # retrieve and print previous line x +s/?!HERE?!/<\1<\1?!HERE?!\2\3/ :hdocsub N /^<\([^>]*\)>.*\n[ ]*\1[ ]*$/!{ @@ -293,6 +292,7 @@ bfolded # found "case ... in" -- pass through untouched :case x +s/?!HERE?!/<foo && +cat <<-Arbitrary_Tag_42 >foo && -cat >boo && +cat <boo && -horticulture +horticulture <foop && +cat <foop && ( - cat && - cat ?!AMP?! + cat <<-INPUT_END && + cat <<-EOT ?!AMP?! foobar ) diff --git a/t/chainlint/subshell-here-doc.expect b/t/chainlint/subshell-here-doc.expect index b7250ca753..029d129299 100644 --- a/t/chainlint/subshell-here-doc.expect +++ b/t/chainlint/subshell-here-doc.expect @@ -1,10 +1,10 @@ ( - echo wobba gorgo snoot wafta snurb && - cat >bip ?!AMP?! - echo >bop + echo wobba gorgo snoot wafta snurb <<-EOF && + cat <bip ?!AMP?! + echo <<-EOF >bop ) && ( - cat >bup && - cat >bup3 && + cat <<-ARBITRARY >bup && + cat <<-ARBITRARY3 >bup3 && meep ) diff --git a/t/chainlint/t7900-subtree.expect b/t/chainlint/t7900-subtree.expect index 215aca01c2..1cccc7bf7e 100644 --- a/t/chainlint/t7900-subtree.expect +++ b/t/chainlint/t7900-subtree.expect @@ -1,9 +1,9 @@ ( chks="sub1sub2sub3sub4" && - chks_sub=$(cat | sed "s,^,sub dir/," + chks_sub=$(cat < X-Patchwork-Id: 12673131 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 D5785C433EF for ; Mon, 13 Dec 2021 06:32:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232340AbhLMGcZ (ORCPT ); Mon, 13 Dec 2021 01:32:25 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40192 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232297AbhLMGcQ (ORCPT ); Mon, 13 Dec 2021 01:32:16 -0500 Received: from mail-io1-xd30.google.com (mail-io1-xd30.google.com [IPv6:2607:f8b0:4864:20::d30]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C314EC061D60 for ; Sun, 12 Dec 2021 22:32:09 -0800 (PST) Received: by mail-io1-xd30.google.com with SMTP id q72so17300028iod.12 for ; Sun, 12 Dec 2021 22:32:09 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=mmhBWxqwjpgfEcyMowsTQ3vctc/dSWgSEKmTOODaLMQ=; b=jqWC7ndI8zCB3gOm0ODFwzapPU/nqDq7JFKisEqPUwvkv18GeBeva+V6GwdVzBMaUB f41fTgmcLFvCg+YXKoY7GhB0s0mJR7CDVMVUG4BcoKHrCxpz2TTpfCZ/oHW4yGNx1lQm 78/4FA2+fxAc2Q3CiyAz4AERp6+lP7X+HVC2CJ3r75sfFuGObbNFBCoN3jXN9YQqo1oJ rGBAzk2j0OvovPL02VU6SGPH4AC7TXO73na/DL9sw1aTI/0p/37RIalnSMP/o3qjhKmF Xo8wlhA1NmSMsMwn9wVIqhZvS9nIpFxipAqhEOb6uY1jc6Q3cvECAUGcb3NgEbf3vGuE 19JQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=mmhBWxqwjpgfEcyMowsTQ3vctc/dSWgSEKmTOODaLMQ=; b=kCpZwme2/XS6fygmcOsNwpdw9PzHQ24CHbcL31kYUTc+fp4M+NBF5faMGoiqEEku4k vjuora5GlTAJA52xPILLtkwLfL+r3RhCaUAyOeeyQHIKJdpU49kh34dugeD59+QCgVqn 72ReEpoOnKTZ34ool2NgTaWEPHTg5GoKO1gzLsQHPQBfGwElEezF87gf8hh62PpzcyYL bk7WQ85pEVONNeglYeMD6eNGB4QfgvAUAYB76XeZPjqBZVzPHaQ+z2/buY2losnHC4vr WKItUDCvwVkfcp5WJazGGshPlFSbpNZg1/cjvdRgyNpa8WaAzaO2GEzFGgQsonBK0wxf l11Q== X-Gm-Message-State: AOAM5334QmzrRSSP6FGup7qg5Tzfwv+pKS9JWm48ZUm7My0qaZAaPI8e sityNKmV10PB9hlJFmq3TgvjBlfb4Xim5Q== X-Google-Smtp-Source: ABdhPJy3Pk/nzZ0WjZYRBtEE5sLf4iA9ZcbInbtFK+IaHGjg3JWqXAJdTpV+MH0qO+SBohNBFay6OQ== X-Received: by 2002:a05:6602:14cd:: with SMTP id b13mr32581103iow.203.1639377128648; Sun, 12 Dec 2021 22:32:08 -0800 (PST) Received: from localhost.localdomain (097-069-216-153.res.spectrum.com. [97.69.216.153]) by smtp.gmail.com with ESMTPSA id f10sm7305408ils.13.2021.12.12.22.32.07 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sun, 12 Dec 2021 22:32:08 -0800 (PST) Sender: Eric Sunshine From: Eric Sunshine To: git@vger.kernel.org Cc: Jeff King , Elijah Newren , Fabian Stelzer , Eric Sunshine Subject: [PATCH 14/15] chainlint.sed: swallow comments consistently Date: Mon, 13 Dec 2021 01:30:58 -0500 Message-Id: <20211213063059.19424-15-sunshine@sunshineco.com> X-Mailer: git-send-email 2.34.1.397.gfae76fe5da In-Reply-To: <20211213063059.19424-1-sunshine@sunshineco.com> References: <20211213063059.19424-1-sunshine@sunshineco.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org When checking for broken a &&-chain, chainlint.sed knows that the final statement in a subshell should not end with `&&`, so it takes care to make a distinction between the final line which is an actual statement and any lines which may be mere comments preceding the closing ')'. As such, it swallows comment lines so that they do not interfere with the &&-chain check. However, since `sed` does not provide any sort of real recursion, chainlint.sed only checks &&-chains in subshells one level deep; it doesn't do any checking in deeper subshells or in `{...}` blocks within subshells. Furthermore, on account of potential implementation complexity, it doesn't check &&-chains within `case` arms. Due to an oversight, it also doesn't swallow comments inside deep subshells, `{...}` blocks, or `case` statements, which makes its output inconsistent (swallowing comments in some cases but not others). Unfortunately, this inconsistency seeps into the chainlint self-test "expect" files, which potentially makes it difficult to reuse the self-tests should a more capable chainlint ever be developed. Therefore, teach chainlint.sed to consistently swallow comments in all cases. Signed-off-by: Eric Sunshine --- t/chainlint.sed | 21 +++++++++++++++++++-- t/chainlint/block-comment.expect | 6 ++++++ t/chainlint/block-comment.test | 8 ++++++++ t/chainlint/case-comment.expect | 8 ++++++++ t/chainlint/case-comment.test | 11 +++++++++++ t/chainlint/nested-subshell-comment.expect | 2 -- 6 files changed, 52 insertions(+), 4 deletions(-) create mode 100644 t/chainlint/block-comment.expect create mode 100644 t/chainlint/block-comment.test create mode 100644 t/chainlint/case-comment.expect create mode 100644 t/chainlint/case-comment.test diff --git a/t/chainlint.sed b/t/chainlint.sed index 0e575c0c62..b1505ef2cd 100644 --- a/t/chainlint.sed +++ b/t/chainlint.sed @@ -294,6 +294,12 @@ bfolded x s/?!HERE?!/< X-Patchwork-Id: 12673133 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 CDAC4C433F5 for ; Mon, 13 Dec 2021 06:32:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232317AbhLMGc3 (ORCPT ); Mon, 13 Dec 2021 01:32:29 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40174 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232272AbhLMGcU (ORCPT ); Mon, 13 Dec 2021 01:32:20 -0500 Received: from mail-il1-x12a.google.com (mail-il1-x12a.google.com [IPv6:2607:f8b0:4864:20::12a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 39428C0698C5 for ; Sun, 12 Dec 2021 22:32:10 -0800 (PST) Received: by mail-il1-x12a.google.com with SMTP id a11so14109008ilj.6 for ; Sun, 12 Dec 2021 22:32:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=O8Ez1BvzXJtluEwIyI2ASZiFObjiY0yXIEqHMO+W82s=; b=MQX5mK1lgJZ2WsvbcVERQiFcUeNhFbWY6CFE88Ka8sf2ajy+d6DQpPQHTRS/vJTisP YCAfXDP9FNJae6jOo7hUm5Q4EaBNbBFwfLuSyU4hxFAS4dTjZwj/34G8CXLk18+Ifgft r7OuVKJ9rnF0+tkyka8xiHJ9pK82yuvDsj0FjnUzPVx0o77pt5rBLxU8A8BuutazLV/+ Cso2unRi4z4Y6DdroObyNIZcJ8NeXmpdBXR0fCPKtu87SrMi1fqJ9aTbYOsyIvdPmOqm XVf19XfDqZ6o1QRsTQvqx5lwmQ5lCLnLK9JvyVglp1kY3GipwjgXxZeppFK/QM9gYk2c ELEg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=O8Ez1BvzXJtluEwIyI2ASZiFObjiY0yXIEqHMO+W82s=; b=b8S1+2dJ8q7sUWQ9LHkRf/MFNIBEvPUflTxE2SOjwlPNQDwW8JqrFUS3NcSPEiTWpM Zt3N9y3ll6ZwWvWRAUas8jCiuqKvuX0khmtmNDQdusMXO9Ie8CU6XjJMwitz2uHXEwtJ xyW/iYqvYcBsO01xmJoF4/Z9hi8sdNLieifqEFh54Wu2czzM4GU+6Fv88CrRbXk+Q2Rz HazZd2b+UnQfozE5VER3Fc8PTuPgwFnyO6aZcz+j0Ax829rSh7GUA+NrKG5EbyX2Hj9z 7W/0OY4kU8j/hCX4JVWel3iiMXGILAtDxr9LN2nGsnxx/I9Xjd8w5GlhKwlngCulWcT5 36yA== X-Gm-Message-State: AOAM5330UQNui/Z47B4lYmQrrwN16lM4M4YJycb16WiU399dUxdgUlYb 6fcZ1Vi3TOlOg4viJA268yOE7V8inuuWcA== X-Google-Smtp-Source: ABdhPJzVVFsgQj6/+fijI0MywWhdp9deXtL43+GkAFMOrJ4QGacWrMTQaj4d8IFxzOhmg14sbTrwJw== X-Received: by 2002:a92:1a0f:: with SMTP id a15mr5749867ila.49.1639377129284; Sun, 12 Dec 2021 22:32:09 -0800 (PST) Received: from localhost.localdomain (097-069-216-153.res.spectrum.com. [97.69.216.153]) by smtp.gmail.com with ESMTPSA id f10sm7305408ils.13.2021.12.12.22.32.08 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sun, 12 Dec 2021 22:32:09 -0800 (PST) Sender: Eric Sunshine From: Eric Sunshine To: git@vger.kernel.org Cc: Jeff King , Elijah Newren , Fabian Stelzer , Eric Sunshine Subject: [PATCH 15/15] chainlint.sed: stop splitting "(..." into separate lines "(" and "..." Date: Mon, 13 Dec 2021 01:30:59 -0500 Message-Id: <20211213063059.19424-16-sunshine@sunshineco.com> X-Mailer: git-send-email 2.34.1.397.gfae76fe5da In-Reply-To: <20211213063059.19424-1-sunshine@sunshineco.com> References: <20211213063059.19424-1-sunshine@sunshineco.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Because `sed` is line-oriented, for ease of implementation, when chainlint.sed encounters an opening subshell in which the first command is cuddled with the "(", it splits the line into two lines: one containing only "(", and the other containing whatever follows "(". This allows chainlint.sed to get by with a single set of regular expressions for matching shell statements rather than having to duplicate each expression (one set for matching non-cuddled statements, and one set for matching cuddled statements). However, although syntactically and semantically immaterial, this transformation has no value to test authors and might even confuse them into thinking that the linter is misbehaving by inserting (whitespace) line-noise into the shell code it is validating. Moreover, it also allows an implementation detail of chainlint.sed to seep into the chainlint self-test "expect" files, which potentially makes it difficult to reuse the self-tests should a more capable chainlint ever be developed. To address these concerns, stop splitting cuddled "(..." into two lines. Note that, as an implementation artifact, due to sed's line-oriented nature, this change inserts a blank line at output time just before the "(..." line is emitted. It would be possible to suppress this blank line but doing so would add a fair bit of complexity to chainlint.sed. Therefore, rather than suppressing the extra blank line, the Makefile's `check-chainlint` target which runs the chainlint self-tests is instead modified to ignore blank lines when comparing chainlint output against the self-test "expect" output. This is a reasonable compromise for two reasons. First, the purpose of the chainlint self-tests is to verify that the ?!AMP?! annotations are being correctly added; precise whitespace is immaterial. Second, by necessity, chainlint.sed itself already throws away all blank lines within subshells since, when checking for a broken &&-chain, it needs to check the final _statement_ in a subshell, not the final _line_ (which might be blank), thus it has never made any attempt to precisely reproduce blank lines in its output. Signed-off-by: Eric Sunshine --- t/Makefile | 4 +- t/chainlint.sed | 38 ++++++++++++------- .../close-nested-and-parent-together.expect | 3 +- t/chainlint/complex-if-in-cuddled-loop.expect | 3 +- t/chainlint/cuddled-if-then-else.expect | 3 +- t/chainlint/cuddled-loop.expect | 3 +- t/chainlint/cuddled.expect | 12 ++---- t/chainlint/inline-comment.expect | 3 +- t/chainlint/semicolon.expect | 3 +- 9 files changed, 37 insertions(+), 35 deletions(-) diff --git a/t/Makefile b/t/Makefile index f4ae40be46..46cd5fc527 100644 --- a/t/Makefile +++ b/t/Makefile @@ -72,8 +72,8 @@ clean-chainlint: check-chainlint: @mkdir -p '$(CHAINLINTTMP_SQ)' && \ sed -e '/^# LINT: /d' $(patsubst %,chainlint/%.test,$(CHAINLINTTESTS)) >'$(CHAINLINTTMP_SQ)'/tests && \ - cat $(patsubst %,chainlint/%.expect,$(CHAINLINTTESTS)) >'$(CHAINLINTTMP_SQ)'/expect && \ - $(CHAINLINT) '$(CHAINLINTTMP_SQ)'/tests >'$(CHAINLINTTMP_SQ)'/actual && \ + sed -e '/^[ ]*$$/d' $(patsubst %,chainlint/%.expect,$(CHAINLINTTESTS)) >'$(CHAINLINTTMP_SQ)'/expect && \ + $(CHAINLINT) '$(CHAINLINTTMP_SQ)'/tests | grep -v '^[ ]*$$' >'$(CHAINLINTTMP_SQ)'/actual && \ diff -u '$(CHAINLINTTMP_SQ)'/expect '$(CHAINLINTTMP_SQ)'/actual test-lint: test-lint-duplicates test-lint-executable test-lint-shell-syntax \ diff --git a/t/chainlint.sed b/t/chainlint.sed index b1505ef2cd..dc4ce37cb5 100644 --- a/t/chainlint.sed +++ b/t/chainlint.sed @@ -131,11 +131,15 @@ b h bnextln } -# "(..." line -- split off and stash "(", then process "..." as its own line +# "(..." line -- "(" opening subshell cuddled with command; temporarily replace +# "(" with sentinel "^" and process the line as if "(" had been seen solo on +# the preceding line; this temporary replacement prevents several rules from +# accidentally thinking "(" introduces a nested subshell; "^" is changed back +# to "(" at output time x -s/.*/(/ +s/.*// x -s/(// +s/(/^/ bslurp :nextln @@ -168,12 +172,12 @@ s/.*\n// /"[^"]*#[^"]*"/!s/[ ]#.*$// } # one-liner "case ... esac" -/^[ ]*case[ ]*..*esac/bchkchn +/^[ ^]*case[ ]*..*esac/bchkchn # multi-line "case ... esac" -/^[ ]*case[ ]..*[ ]in/bcase +/^[ ^]*case[ ]..*[ ]in/bcase # multi-line "for ... done" or "while ... done" -/^[ ]*for[ ]..*[ ]in/bcont -/^[ ]*while[ ]/bcont +/^[ ^]*for[ ]..*[ ]in/bcont +/^[ ^]*while[ ]/bcont /^[ ]*do[ ]/bcont /^[ ]*do[ ]*$/bcont /;[ ]*do/bcont @@ -184,7 +188,7 @@ s/.*\n// /||[ ]*exit[ ]/bcont /||[ ]*exit[ ]*$/bcont # multi-line "if...elsif...else...fi" -/^[ ]*if[ ]/bcont +/^[ ^]*if[ ]/bcont /^[ ]*then[ ]/bcont /^[ ]*then[ ]*$/bcont /;[ ]*then/bcont @@ -197,15 +201,15 @@ s/.*\n// /^[ ]*fi[ ]*[<>|]/bdone /^[ ]*fi[ ]*)/bdone # nested one-liner "(...) &&" -/^[ ]*(.*)[ ]*&&[ ]*$/bchkchn +/^[ ^]*(.*)[ ]*&&[ ]*$/bchkchn # nested one-liner "(...)" -/^[ ]*(.*)[ ]*$/bchkchn +/^[ ^]*(.*)[ ]*$/bchkchn # nested one-liner "(...) >x" (or "2>x" or "|]/bchkchn +/^[ ^]*(.*)[ ]*[0-9]*[<>|]/bchkchn # nested multi-line "(...\n...)" -/^[ ]*(/bnest +/^[ ^]*(/bnest # multi-line "{...\n...}" -/^[ ]*{/bblock +/^[ ^]*{/bblock # closing ")" on own line -- exit subshell /^[ ]*)/bclssolo # "$((...))" -- arithmetic expansion; not closing ")" @@ -237,6 +241,7 @@ s/.*\n// :cont # retrieve and print previous line x +s/^\([ ]*\)^/\1(/ s/?!HERE?!/<