git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Eric Sunshine <sunshine@sunshineco.com>
To: AbdAlRahman Gad <abdobngad@gmail.com>
Cc: git@vger.kernel.org
Subject: Re: [PATCH v4 2/8] [Newcomer] t7004: Do not lose exit status to pipe
Date: Mon, 5 Aug 2024 23:13:37 -0400	[thread overview]
Message-ID: <CAPig+cS6-gqZbJSz3wBcummyycJVudKybVZW=D33WHk-Fa9ytQ@mail.gmail.com> (raw)
In-Reply-To: <20240805235917.190699-3-abdobngad@gmail.com>

On Mon, Aug 5, 2024 at 8:00 PM AbdAlRahman Gad <abdobngad@gmail.com> wrote:
> Split "test-tool ... | sed" pipeline into two commands to avoid losing
> exit status from test-tool.
>
> Signed-off-by: AbdAlRahman Gad <abdobngad@gmail.com>
> ---
> diff --git a/t/t7004-tag.sh b/t/t7004-tag.sh
> @@ -97,7 +97,8 @@ test_expect_success 'creating a tag with --create-reflog should create reflog' '
> -       test-tool ref-store main for-each-reflog-ent refs/tags/tag_with_reflog1 | sed -e "s/^.* //" >actual &&
> +       test-tool ref-store main for-each-reflog-ent refs/tags/tag_with_reflog1 >actual.body &&
> +       sed -e "s/^.*   //" actual.body >actual &&

It's not just `test_tool` we care about; we also (importantly) don't
want to see `git` itself upstream of a pipe, and there are many such
instances remaining in this script. Here are some common examples:

    test $(git tag -l | wc -l) -eq 0 &&
    git cat-file tag "$1" | sed -e "/BEGIN PGP/q"
    git tag -l | grep "^tag-one-line" >actual &&
    forged=$(git cat-file tag ... | sed -e ... | git mktag) &&
    git tag -l --no-sort "foo*" | sort >actual &&

By the way, these days, rather than:

    test $(git tag -l | wc -l) -eq 0 &&

we would say:

    test_stdout_line_count = 0 git tag -l &&

which nicely avoids placing `git` upstream of a pipe.

  reply	other threads:[~2024-08-06  3:13 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-08-05 23:59 [PATCH v4 0/8] t7004: Modernize the style AbdAlRahman Gad
2024-08-05 23:59 ` [PATCH v4 1/8] [Newcomer] t7004: Remove space after redirect operators AbdAlRahman Gad
2024-08-05 23:59 ` [PATCH v4 2/8] [Newcomer] t7004: Do not lose exit status to pipe AbdAlRahman Gad
2024-08-06  3:13   ` Eric Sunshine [this message]
2024-08-06  8:38     ` AbdAlRahman Gad
2024-08-06 18:05       ` Eric Sunshine
2024-08-05 23:59 ` [PATCH v4 3/8] [Newcomer] t7004: One command per line AbdAlRahman Gad
2024-08-05 23:59 ` [PATCH v4 4/8] [Newcomer] t7004: Do not prepare things outside test_expect_success AbdAlRahman Gad
2024-08-06  3:29   ` Eric Sunshine
2024-08-06  8:41     ` AbdAlRahman Gad
2024-08-05 23:59 ` [PATCH v4 5/8] [Newcomer] t7004: Use indented here-doc AbdAlRahman Gad
2024-08-05 23:59 ` [PATCH v4 6/8] [Newcomer] t7004: Description on the same line as test_expect_success AbdAlRahman Gad
2024-08-05 23:59 ` [PATCH v4 7/8] [Newcomer] t7004: test Description and test body seperated with backslash AbdAlRahman Gad
2024-08-05 23:59 ` [PATCH v4 8/8] [Newcomer] t7004: Use single quotes instead of double quotes AbdAlRahman Gad
2024-08-06  3:02   ` Eric Sunshine
2024-08-06 10:10     ` AbdAlRahman Gad
2024-08-06 17:21       ` Eric Sunshine
2024-08-06 16:35     ` Junio C Hamano
2024-08-06 17:11       ` Eric Sunshine
2024-08-06  0:45 ` [PATCH v4 0/8] t7004: Modernize the style Junio C Hamano
2024-08-06  8:44   ` AbdAlRahman Gad

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAPig+cS6-gqZbJSz3wBcummyycJVudKybVZW=D33WHk-Fa9ytQ@mail.gmail.com' \
    --to=sunshine@sunshineco.com \
    --cc=abdobngad@gmail.com \
    --cc=git@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).