From: Eric Sunshine <sunshine@sunshineco.com>
To: Denton Liu <liu.denton@gmail.com>
Cc: Git Mailing List <git@vger.kernel.org>
Subject: Re: [PATCH 04/16] t2018: teach do_checkout() to accept `!` arg
Date: Sat, 28 Dec 2019 03:34:03 -0500 [thread overview]
Message-ID: <CAPig+cT242CjL9S0OcS1Pbsgf-u1N=SQzNfLdao03LU2OGEciQ@mail.gmail.com> (raw)
In-Reply-To: <4eab751a3cf00bbffaf4b1084928dad264fa1572.1577454401.git.liu.denton@gmail.com>
On Fri, Dec 27, 2019 at 8:47 AM Denton Liu <liu.denton@gmail.com> wrote:
> Before, we were running `test_must_fail do_checkout`. However,
> `test_must_fail` should only be used on git commands. Teach
> do_checkout() to accept `!` as a potential first argument which will
> prepend `test_must_fail` to the enclosed git command and skips the
> remainder of the function.
There's a grammatical problem here. s/skips/skip/ is one way to fix it.
Use imperative mood when writing commit messages. Drop words such as
"before" and "were". For instance:
Stop using test_must_fail() with non-Git commands because...
(Same comment applies to pretty much all commit messages in this series.)
> This increases the granularity of the test as, instead of blindly
> checking that do_checkout() failed, we check that only the specific
> expected invocation of git fails.
This may be a case of trying to describe in prose too much of what is
better described by the code itself. As a reviewer, I spent more time
trying to figure out what this was saying that I did merely looking at
the code and comprehending why the two checks following the
git-checkout invocation should be skipped. Consequently, I lean toward
dropping "...and skips the remainder..." through the end of the commit
message.
More below...
> Signed-off-by: Denton Liu <liu.denton@gmail.com>
> ---
> diff --git a/t/t2018-checkout-branch.sh b/t/t2018-checkout-branch.sh
> @@ -13,6 +13,12 @@ test_description='checkout'
> #
> # If <checkout options> is not specified, "git checkout" is run with -b.
> do_checkout () {
> + should_fail= &&
> + if test "x$1" = "x!"
> + then
> + should_fail=test_must_fail &&
> + shift
> + fi &&
You forgot to update the function comment to talk about the new
optional "!" argument.
> @@ -26,10 +32,13 @@ do_checkout () {
> - git checkout $opts $exp_branch $exp_sha &&
> + $should_fail git checkout $opts $exp_branch $exp_sha &&
If I read this literally, it says that the git checkout should always
fail. A more wisely chosen variable name would help to alleviate this
problem.
When you start parameterizing the actual invocation of a command like
this (I'm not talking about the command arguments which are also
parameterized), the abstraction level and cognitive load increase...
> - test $exp_ref = $(git rev-parse --symbolic-full-name HEAD) &&
> - test $exp_sha = $(git rev-parse --verify HEAD)
> + if test -z "$should_fail"
> + then
> + test $exp_ref = $(git rev-parse --symbolic-full-name HEAD) &&
> + test $exp_sha = $(git rev-parse --verify HEAD)
> + fi
> }
You could reduce the cognitive load by making the code easier to
understand at-a-glance (though at the cost of a minor bit of
duplication) by structuring it instead like this:
if test -n "$should_fail"
then
test_must_fail git checkout $opts $exp_branch $exp_sha
else
git checkout $opts $exp_branch $exp_sha &&
test $exp_ref = $(git rev-parse --symbolic-full-name HEAD) &&
test $exp_sha = $(git rev-parse --verify HEAD)
fi
where 'should_fail' is either empty or non-empty depending upon
whether "!" was supplied as an argument. (And, when coded this way,
"should_fail" is a reasonable variable name.)
next prev parent reply other threads:[~2019-12-28 8:34 UTC|newest]
Thread overview: 54+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-12-27 13:47 [PATCH 00/16] t: replace incorrect test_must_fail usage (part 2) Denton Liu
2019-12-27 13:47 ` [PATCH 01/16] t2018: remove trailing space from test description Denton Liu
2019-12-27 13:47 ` [PATCH 02/16] t2018: add space between function name and () Denton Liu
2019-12-27 21:03 ` Eric Sunshine
2019-12-27 13:47 ` [PATCH 03/16] t2018: use test_must_fail for failing git commands Denton Liu
2019-12-28 7:55 ` Eric Sunshine
2019-12-30 20:30 ` Jakub Narebski
2019-12-27 13:47 ` [PATCH 04/16] t2018: teach do_checkout() to accept `!` arg Denton Liu
2019-12-28 8:34 ` Eric Sunshine [this message]
2019-12-27 13:47 ` [PATCH 05/16] t2018: don't lose return code of git commands Denton Liu
2019-12-27 21:42 ` Eric Sunshine
2020-01-01 8:48 ` Denton Liu
2020-01-01 9:21 ` Eric Sunshine
2020-01-02 18:26 ` Junio C Hamano
2019-12-27 13:47 ` [PATCH 06/16] t2018: replace "sha" with "oid" Denton Liu
2019-12-27 13:47 ` [PATCH 07/16] t3030: use test_path_is_missing() Denton Liu
2019-12-27 13:47 ` [PATCH 08/16] t3310: extract common no_notes_merge_left() Denton Liu
2019-12-28 7:20 ` Eric Sunshine
2019-12-30 20:38 ` Jakub Narebski
2019-12-27 13:47 ` [PATCH 09/16] t3415: stop losing return codes of git commands Denton Liu
2019-12-27 13:47 ` [PATCH 10/16] t3415: increase granularity of test_auto_{fixup,squash}() Denton Liu
2019-12-27 13:47 ` [PATCH 11/16] t3419: stop losing return code of git command Denton Liu
2019-12-27 13:47 ` [PATCH 12/16] t3504: don't use `test_must_fail test_cmp` Denton Liu
2019-12-27 20:39 ` Johannes Sixt
2019-12-27 22:48 ` Junio C Hamano
2019-12-27 13:47 ` [PATCH 13/16] t3507: fix indentation Denton Liu
2019-12-27 13:47 ` [PATCH 14/16] t3507: use test_path_is_missing() Denton Liu
2019-12-27 13:47 ` [PATCH 15/16] t4124: only mark git command with test_must_fail Denton Liu
2019-12-27 13:47 ` [PATCH 16/16] t4124: let sed open its own files Denton Liu
2019-12-30 22:52 ` Jakub Narebski
2019-12-30 23:27 ` Junio C Hamano
2020-01-01 8:24 ` Denton Liu
2020-01-01 8:33 ` Eric Sunshine
2020-01-01 8:53 ` Denton Liu
2020-01-07 4:52 ` [PATCH v2 00/16] t: replace incorrect test_must_fail usage (part 2) Denton Liu
2020-01-07 4:52 ` [PATCH v2 01/16] t2018: remove trailing space from test description Denton Liu
2020-01-07 4:52 ` [PATCH v2 02/16] t2018: add space between function name and () Denton Liu
2020-01-07 4:53 ` [PATCH v2 03/16] t2018: improve style of if-statement Denton Liu
2020-01-07 4:53 ` [PATCH v2 04/16] t2018: use test_expect_code for failing git commands Denton Liu
2020-01-12 10:50 ` Eric Sunshine
2020-01-26 20:23 ` [PATCH v3] t2018: be more discerning when checking for expected exit codes Denton Liu
2020-01-07 4:53 ` [PATCH v2 05/16] t2018: teach do_checkout() to accept `!` arg Denton Liu
2020-01-07 4:53 ` [PATCH v2 06/16] t2018: don't lose return code of git commands Denton Liu
2020-01-07 4:53 ` [PATCH v2 07/16] t2018: replace "sha" with "oid" Denton Liu
2020-01-07 4:53 ` [PATCH v2 08/16] t3030: use test_path_is_missing() Denton Liu
2020-01-07 4:53 ` [PATCH v2 09/16] t3310: extract common notes_merge_files_gone() Denton Liu
2020-01-07 4:53 ` [PATCH v2 10/16] t3415: stop losing return codes of git commands Denton Liu
2020-01-07 4:53 ` [PATCH v2 11/16] t3415: increase granularity of test_auto_{fixup,squash}() Denton Liu
2020-01-07 4:53 ` [PATCH v2 12/16] t3419: stop losing return code of git command Denton Liu
2020-01-07 4:53 ` [PATCH v2 13/16] t3504: do check for conflict marker after failed cherry-pick Denton Liu
2020-01-07 4:53 ` [PATCH v2 14/16] t3507: fix indentation Denton Liu
2020-01-07 4:53 ` [PATCH v2 15/16] t3507: use test_path_is_missing() Denton Liu
2020-01-07 4:53 ` [PATCH v2 16/16] t4124: only mark git command with test_must_fail Denton Liu
2020-01-10 21:45 ` [PATCH v2 00/16] t: replace incorrect test_must_fail usage (part 2) Eric Sunshine
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='CAPig+cT242CjL9S0OcS1Pbsgf-u1N=SQzNfLdao03LU2OGEciQ@mail.gmail.com' \
--to=sunshine@sunshineco.com \
--cc=git@vger.kernel.org \
--cc=liu.denton@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).