From: "Ævar Arnfjörð Bjarmason" <avarab@gmail.com>
To: Derrick Stolee <derrickstolee@github.com>
Cc: Elijah Newren via GitGitGadget <gitgitgadget@gmail.com>,
git@vger.kernel.org, Elijah Newren <newren@gmail.com>
Subject: Re: [PATCH v2 2/2] revision: allow --ancestry-path to take an argument
Date: Thu, 18 Aug 2022 17:50:50 +0200 [thread overview]
Message-ID: <220818.86ilmp8rzn.gmgdl@evledraar.gmail.com> (raw)
In-Reply-To: <ee4a7a7f-d646-6357-233a-1fefde5607bf@github.com>
On Thu, Aug 18 2022, Derrick Stolee wrote:
> On 8/18/2022 2:17 AM, Elijah Newren via GitGitGadget wrote:
>> +test_expect_success 'rev-list --ancestry-path=F D..M' '
>> + test_write_lines E F J L M >expect &&
>> + git rev-list --ancestry-path=F --format=%s D..M |
>> + sed -e "/^commit /d" |
>> + sort >actual &&
>> + test_cmp expect actual
>> +'
>
> These tests follow the patterns from other tests in this file, but
> it also has bad patterns. Specifically, the 'git rev-list' command
> is fed directly into a pipe. I include a patch below that applies
> directly on this one to rewrite these tests. If you want, you could
> rebase to have that test refactor happen before you add your new
> --ancestry-path=<X> option tests.
Thanks, I was going to comment on the same, but your solution is much
better (I was just going to suggest using intermediate files).
> [...]
> -test_expect_success 'rev-list --ancestry-path D..M -- M.t' '
> - echo M >expect &&
> - git rev-list --ancestry-path --format=%s D..M -- M.t |
> - sed -e "/^commit /d" >actual &&
> - test_cmp expect actual
> -'
> +test_ancestry () {
> + args=$1
> + expected=$2
Maybe add &&-chaining here (we do it in some cases, but I'm not sure
when such assignments would ever fail).
> + test_expect_success "rev-list $args" "
> + test_write_lines $expected >expect &&
> + git rev-list --format=%s $args >raw &&
> +
> + if test -n \"$expected\"
Aren't you making things harder for yourself here than required by using
""-quoting for the body of the test.
We eval it into existence, so you can use ''-quotes, and then you don't
need to escape e.g. the "" quotes here for expected, no?
> + then
> + sed -e \"/^commit /d\" raw | sort >actual &&
nit for debuggability (and not correctness), maybe using intermediate
files here would be nicer? And then perhaps call them "actual" and
"actual.sorted".
> + test_cmp expect actual || return 1
No need for a "return 1" here when we're not in a loop. It's redundant,
and makes the -x output on failure confusing ("why didn't I fail on the
test_cmp, but on this stray return?...").
...
> + else
> + test_must_be_empty raw
...which would also allow you to extract much of this if/else at the
cost of not using test_must_be_empty, i.e. just make the "expected"
empty unless "$expected" is provided. Just a thought/nit, we could also
leave this as-is :)
Also does the "compare rev" part of this want test_cmp_rev instead?
next prev parent reply other threads:[~2022-08-18 15:58 UTC|newest]
Thread overview: 29+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-08-17 2:48 [PATCH 0/2] Allow --ancestry-path to take an argument Elijah Newren via GitGitGadget
2022-08-17 2:48 ` [PATCH 1/2] rev-list-options.txt: fix simple typo Elijah Newren via GitGitGadget
2022-08-17 2:48 ` [PATCH 2/2] revision: allow --ancestry-path to take an argument Elijah Newren via GitGitGadget
2022-08-17 22:42 ` Junio C Hamano
2022-08-18 4:01 ` Elijah Newren
2022-08-18 6:17 ` [PATCH v2 0/2] Allow " Elijah Newren via GitGitGadget
2022-08-18 6:17 ` [PATCH v2 1/2] rev-list-options.txt: fix simple typo Elijah Newren via GitGitGadget
2022-08-18 6:17 ` [PATCH v2 2/2] revision: allow --ancestry-path to take an argument Elijah Newren via GitGitGadget
2022-08-18 15:30 ` Derrick Stolee
2022-08-18 15:50 ` Ævar Arnfjörð Bjarmason [this message]
2022-08-18 16:51 ` Derrick Stolee
2022-08-18 16:56 ` Eric Sunshine
2022-08-19 1:12 ` Elijah Newren
2022-08-19 2:45 ` Ævar Arnfjörð Bjarmason
2022-08-18 16:53 ` Eric Sunshine
2022-08-19 1:01 ` Elijah Newren
2022-08-18 22:24 ` Jonathan Tan
2022-08-19 1:23 ` Elijah Newren
2022-08-19 17:25 ` Jonathan Tan
2022-08-18 16:32 ` [PATCH v2 0/2] Allow " Junio C Hamano
2022-08-19 4:28 ` [PATCH v3 0/3] " Elijah Newren via GitGitGadget
2022-08-19 4:28 ` [PATCH v3 1/3] rev-list-options.txt: fix simple typo Elijah Newren via GitGitGadget
2022-08-19 4:28 ` [PATCH v3 2/3] t6019: modernize tests with helper Derrick Stolee via GitGitGadget
2022-08-19 4:28 ` [PATCH v3 3/3] revision: allow --ancestry-path to take an argument Elijah Newren via GitGitGadget
2022-08-19 17:54 ` Junio C Hamano
2022-08-20 0:10 ` Elijah Newren
2022-08-19 12:53 ` [PATCH v3 0/3] Allow " Derrick Stolee
2022-08-19 21:08 ` Junio C Hamano
2022-08-20 0:13 ` Elijah Newren
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
List information: http://vger.kernel.org/majordomo-info.html
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=220818.86ilmp8rzn.gmgdl@evledraar.gmail.com \
--to=avarab@gmail.com \
--cc=derrickstolee@github.com \
--cc=git@vger.kernel.org \
--cc=gitgitgadget@gmail.com \
--cc=newren@gmail.com \
/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.
Code repositories for project(s) associated with this public inbox
https://80x24.org/mirrors/git.git
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 read-only IMAP folder(s) and NNTP newsgroup(s).