git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "SZEDER Gábor" <szeder.dev@gmail.com>
To: "Nguyễn Thái Ngọc Duy" <pclouds@gmail.com>
Cc: git@vger.kernel.org, "Taylor Blau" <me@ttaylorr.com>,
	"Junio C Hamano" <gitster@pobox.com>,
	"Ævar Arnfjörð" <avarab@gmail.com>
Subject: Re: [PATCH v2 1/2] t1300: extract and use test_cmp_config()
Date: Sun, 30 Sep 2018 14:31:16 +0200	[thread overview]
Message-ID: <20180930123116.GI23446@localhost> (raw)
In-Reply-To: <20180929153005.10599-2-pclouds@gmail.com>

On Sat, Sep 29, 2018 at 05:30:04PM +0200, Nguyễn Thái Ngọc Duy wrote:
> In many config-related tests it's common to check if a config variable
> has expected value and we want to print the differences when the test
> fails. Doing it the normal way is three lines of shell code. Let's add
> a function do to all this (and a little more).
> 
> This function has uses outside t1300 as well but I'm not going to
> convert them all. And it will be used in the next commit where
> per-worktree config feature is introduced.
> 
> Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
> ---
>  t/t1300-config.sh       | 79 ++++++++++-------------------------------
>  t/test-lib-functions.sh | 24 +++++++++++++
>  2 files changed, 43 insertions(+), 60 deletions(-)
> 
> diff --git a/t/t1300-config.sh b/t/t1300-config.sh
> index cdf1fed5d1..00c2b0f0eb 100755
> --- a/t/t1300-config.sh
> +++ b/t/t1300-config.sh
> @@ -76,15 +76,11 @@ EOF

>  test_expect_success 'unset type specifiers may be reset to conflicting ones' '
> -	echo 1048576 >expect &&
> -	git config --type=bool --no-type --type=int core.big >actual &&
> -	test_cmp expect actual
> +	test_cmp_config 1048576 --type=bool --no-type --type=int core.big
>  '
>  
>  test_expect_success '--type rejects unknown specifiers' '
> diff --git a/t/test-lib-functions.sh b/t/test-lib-functions.sh
> index d82fac9d79..4cd7fb8fdf 100644
> --- a/t/test-lib-functions.sh
> +++ b/t/test-lib-functions.sh
> @@ -747,6 +747,30 @@ test_cmp() {
>  	$GIT_TEST_CMP "$@"
>  }
>  
> +# similar to test_cmp but $2 is a config key instead of actual value

This doesn't describe very well the function's parameters: $1
specifies the expected value (as opposed to the file containing the
expected value), and the rest can be all kinds of 'git config'
options, not just a second argument with the config key; e.g. see call
in the above hunk.

Perheps only a brief description and a usage string like this would
sufficiently cover everything?

  # Check that the given config key has the expected value.
  #
  #   test_cmp_config [-C <dir>] <expected-value>
  #                   [<git-config-options>...] <config-key>

> +# it can also accept -C to read from a different repo, e.g.
> +#
> +#     test_cmp_config -C xyz foo core.bar
> +#
> +# is sort of equivalent of

I think this comment should outright say that "is a better alternative
to", because it provides useful output on failure, and because it
doesn't hide 'git config's exit code.

Note that this second point does make a bit of a difference:

  test_cmp_config "" nonexisting.variable

would fail, because

  $ git config nonexisting.variable ; echo $?
  1

and the &&-chain.  However,

  test "" = "$(git config nonexisting.variable)"

would still succeed, because the non-zero exit code is ignored.

I consider this a benefit, as it will protect us from a typo in the
name of a set but empty variable, even though we won't get any error
message.

> +#
> +#     test "foo" = "$(git -C xyz core.bar)"
> +

Nit: unnecessary empty line.

> +test_cmp_config() {
> +	if [ "$1" = "-C" ]
> +	then
> +		shift &&
> +		GD="-C $1" &&
> +		shift
> +	else
> +		GD=
> +	fi &&

I think you could now safely declare GD as local.  The test balloon
01d3a526ad (t0000: check whether the shell supports the "local"
keyword, 2017-10-26) has been out there for 4 releases / almost a
year, and we haven't heard about any issues, and the upcoming hash
translation test helpers use 'local' as well.

> +	echo "$1" >expected &&
> +	shift &&
> +	git $GD config "$@" >actual &&
> +	test_cmp expected actual
> +}
> +
>  # test_cmp_bin - helper to compare binary files
>  
>  test_cmp_bin() {
> -- 
> 2.19.0.341.g3acb95d729
>

  parent reply	other threads:[~2018-09-30 12:31 UTC|newest]

Thread overview: 34+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-09-23 17:04 [PATCH] worktree: add per-worktree config files Nguyễn Thái Ngọc Duy
2018-09-23 20:47 ` Eric Sunshine
2018-09-24 14:21 ` Taylor Blau
2018-09-25 15:57   ` Duy Nguyen
2018-09-29 13:53   ` Duy Nguyen
2018-09-25 21:26 ` Junio C Hamano
2018-09-26 15:48   ` Duy Nguyen
2018-09-26 17:40     ` Junio C Hamano
2018-09-27 15:24     ` Wherefor worktrees? Marc Branchaud
2018-09-27 16:36       ` Duy Nguyen
2018-09-26 18:25 ` [PATCH] worktree: add per-worktree config files Ævar Arnfjörð Bjarmason
2018-09-27 17:24   ` Duy Nguyen
2018-09-27 18:34     ` Ævar Arnfjörð Bjarmason
2018-09-27 18:49       ` Duy Nguyen
2018-09-29  6:36       ` Duy Nguyen
2018-09-29 15:30 ` [PATCH v2 0/2] Per-worktree " Nguyễn Thái Ngọc Duy
2018-09-29 15:30   ` [PATCH v2 1/2] t1300: extract and use test_cmp_config() Nguyễn Thái Ngọc Duy
2018-09-30  4:05     ` Eric Sunshine
2018-09-30 12:31     ` SZEDER Gábor [this message]
2018-09-29 15:30   ` [PATCH v2 2/2] worktree: add per-worktree config files Nguyễn Thái Ngọc Duy
2018-09-30  4:32     ` Eric Sunshine
2018-09-30  7:15       ` Duy Nguyen
2018-09-30  7:24         ` Eric Sunshine
2018-09-30  7:36           ` Duy Nguyen
2018-10-02 16:06   ` [PATCH v3 0/2] Per-worktree " Nguyễn Thái Ngọc Duy
2018-10-02 16:06     ` [PATCH v3 1/2] t1300: extract and use test_cmp_config() Nguyễn Thái Ngọc Duy
2018-10-03  7:46       ` Eric Sunshine
2018-10-02 16:06     ` [PATCH v3 2/2] worktree: add per-worktree config files Nguyễn Thái Ngọc Duy
2018-10-21 14:02     ` [PATCH v4 0/2] Per-worktree " Nguyễn Thái Ngọc Duy
2018-10-21 14:02       ` [PATCH v4 1/2] t1300: extract and use test_cmp_config() Nguyễn Thái Ngọc Duy
2018-10-21 14:02       ` [PATCH v4 2/2] worktree: add per-worktree config files Nguyễn Thái Ngọc Duy
2018-10-22  4:54         ` Junio C Hamano
2018-10-22 14:32           ` Duy Nguyen
2018-10-25  9:16             ` Junio C Hamano

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=20180930123116.GI23446@localhost \
    --to=szeder.dev@gmail.com \
    --cc=avarab@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=me@ttaylorr.com \
    --cc=pclouds@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.
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).