git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: "René Scharfe" <l.s.r@web.de>
To: "Ævar Arnfjörð Bjarmason" <avarab@gmail.com>, git@vger.kernel.org
Cc: "Junio C Hamano" <gitster@pobox.com>,
	"Eric Sunshine" <sunshine@sunshineco.com>,
	"Torsten Bögershausen" <tboegi@web.de>
Subject: Re: [PATCH v3 7/8] tests: don't lose "git" exit codes in "! ( git ... | grep )"
Date: Fri, 2 Dec 2022 19:31:00 +0100	[thread overview]
Message-ID: <3304ac3c-0d45-7293-bd7f-08f374786dcc@web.de> (raw)
In-Reply-To: <patch-v3-7.8-307f25db831-20221202T114733Z-avarab@gmail.com>

Am 02.12.22 um 12:52 schrieb Ævar Arnfjörð Bjarmason:
> Change tests that would lose the "git" exit code via a negation
> pattern to:
>
> - In the case of "t0055-beyond-symlinks.sh" compare against the
>   expected output instead.
>
> - For "t3700-add.sh" use "sed -n" to print the expected "bad" part,
>   and use "test_must_be_empty" to assert that it's not there.
>
>   We can also remove a repeated invocation of "git ls-files" for the
>   last test that's being modified in that file, and search the
>   existing "files" output instead.
>
> Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
> ---
>  t/t0055-beyond-symlinks.sh | 14 ++++++++++++--
>  t/t3700-add.sh             | 18 +++++++++++++-----
>  2 files changed, 25 insertions(+), 7 deletions(-)
>
> diff --git a/t/t0055-beyond-symlinks.sh b/t/t0055-beyond-symlinks.sh
> index 6bada370225..c3eb1158ef9 100755
> --- a/t/t0055-beyond-symlinks.sh
> +++ b/t/t0055-beyond-symlinks.sh
> @@ -15,12 +15,22 @@ test_expect_success SYMLINKS setup '
>
>  test_expect_success SYMLINKS 'update-index --add beyond symlinks' '
>  	test_must_fail git update-index --add c/d &&
> -	! ( git ls-files | grep c/d )
> +	cat >expect <<-\EOF &&
> +	a
> +	b/d
> +	EOF
> +	git ls-files >actual &&
> +	test_cmp expect actual
>  '

Hmm, this makes the test depend on the other files.  Adding more of them
for a different test now requires updating this test as well.  Why not
handle it like you did in t3700 below?

>
>  test_expect_success SYMLINKS 'add beyond symlinks' '
>  	test_must_fail git add c/d &&
> -	! ( git ls-files | grep c/d )
> +	cat >expect <<-\EOF &&
> +	a
> +	b/d
> +	EOF
> +	git ls-files >actual &&
> +	test_cmp expect actual
>  '

Same here.

>
>  test_done
> diff --git a/t/t3700-add.sh b/t/t3700-add.sh
> index 51afbd7b24a..82dd768944f 100755
> --- a/t/t3700-add.sh
> +++ b/t/t3700-add.sh
> @@ -106,24 +106,32 @@ test_expect_success '.gitignore test setup' '
>
>  test_expect_success '.gitignore is honored' '
>  	git add . &&
> -	! (git ls-files | grep "\\.ig")
> +	git ls-files >files &&
> +	sed -n "/\\.ig/p" <files >actual &&
> +	test_must_be_empty actual
>  '

You use sed instead of grep because no match is expected and sed returns
0 even then, while grep would exit with code 1, correct?  OK.

Can we use that, though?  I.e. how about this?

	git ls-files >files &&
	test_expect_code 1 grep "\\.ig" files

It would print the unexpected lines in verbose mode like this:

	expecting success of 3700.12 '.gitignore is honored':
		git add . &&
		git ls-files >files &&
		echo foo.ig >files &&	# inject bogus value
		test_expect_code 1 grep "\\.ig" files

	foo.ig
	test_expect_code: command exited with 0, we wanted 1 grep \.ig files

Or can we trust ls-files' own filtering?

	git ls-files "*.ig" >actual &&
	test_must_be_empty actual

Both variants are shorter and should be slightly faster, which can
matter if we use that pattern more widely.

(Didn't measure here, but from a recent foray into t3920 on Windows I
took home that removing commands has a small, but measurable impact there:
https://lore.kernel.org/git/203cb627-2423-8a35-d280-9f9ffc66e072@web.de/T/#u)

>
>  test_expect_success 'error out when attempting to add ignored ones without -f' '
>  	test_must_fail git add a.?? &&
> -	! (git ls-files | grep "\\.ig")
> +	git ls-files >files &&
> +	sed -n "/\\.ig/p" <files >actual &&
> +	test_must_be_empty actual
>  '
>
>  test_expect_success 'error out when attempting to add ignored ones without -f' '
>  	test_must_fail git add d.?? &&
> -	! (git ls-files | grep "\\.ig")
> +	git ls-files >files &&
> +	sed -n "/\\.ig/p" <files >actual &&
> +	test_must_be_empty actual
>  '
>
>  test_expect_success 'error out when attempting to add ignored ones but add others' '
>  	touch a.if &&
>  	test_must_fail git add a.?? &&
> -	! (git ls-files | grep "\\.ig") &&
> -	(git ls-files | grep a.if)
> +	git ls-files >files &&
> +	sed -n "/\\.ig/p" <files >actual &&
> +	test_must_be_empty actual &&
> +	grep a.if files
>  '
>
>  test_expect_success 'add ignored ones with -f' '

  reply	other threads:[~2022-12-02 18:31 UTC|newest]

Thread overview: 83+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-07-21  6:51 [PATCH 0/6] tests: fix ignored & hidden exit codes Ævar Arnfjörð Bjarmason
2022-07-21  6:51 ` [PATCH 1/6] diff tests: fix ignored exit codes in t4023 Ævar Arnfjörð Bjarmason
2022-07-21  6:51 ` [PATCH 2/6] t/lib-patch-mode.sh: fix ignored "git" exit codes Ævar Arnfjörð Bjarmason
2022-07-21  6:51 ` [PATCH 3/6] auto-crlf tests: check "git checkout" exit code Ævar Arnfjörð Bjarmason
2022-07-21  6:51 ` [PATCH 4/6] test-lib-functions: add and use test_cmp_cmd Ævar Arnfjörð Bjarmason
2022-07-21  6:51 ` [PATCH 5/6] merge tests: don't ignore "rev-parse" exit code in helper Ævar Arnfjörð Bjarmason
2022-07-21  6:51 ` [PATCH 6/6] log tests: don't use "exit 1" outside a sub-shell Ævar Arnfjörð Bjarmason
2022-12-02  0:06 ` [PATCH v2 0/8] tests: fix ignored & hidden exit codes Ævar Arnfjörð Bjarmason
2022-12-02  0:06   ` [PATCH v2 1/8] log tests: don't use "exit 1" outside a sub-shell Ævar Arnfjörð Bjarmason
2022-12-02  1:02     ` Eric Sunshine
2022-12-02  1:48       ` Junio C Hamano
2022-12-02  2:45         ` Ævar Arnfjörð Bjarmason
2022-12-02  9:03           ` Eric Sunshine
2022-12-02 10:02             ` Ævar Arnfjörð Bjarmason
2022-12-07  6:09               ` Eric Sunshine
2022-12-02  3:24       ` Junio C Hamano
2022-12-02  0:06   ` [PATCH v2 2/8] auto-crlf tests: check "git checkout" exit code Ævar Arnfjörð Bjarmason
2022-12-02  1:02     ` René Scharfe
2022-12-02  1:10       ` Eric Sunshine
2022-12-02  5:59       ` Torsten Bögershausen
2022-12-02  6:03         ` Eric Sunshine
2022-12-02  0:06   ` [PATCH v2 3/8] diff tests: fix ignored exit codes in t4023 Ævar Arnfjörð Bjarmason
2022-12-02  2:02     ` Junio C Hamano
2022-12-02  0:06   ` [PATCH v2 4/8] test-lib-functions: add and use test_cmp_cmd Ævar Arnfjörð Bjarmason
2022-12-02  1:30     ` René Scharfe
2022-12-02  1:33     ` Eric Sunshine
2022-12-02  1:45       ` Eric Sunshine
2022-12-02  1:52         ` Eric Sunshine
2022-12-02  3:41         ` Junio C Hamano
2022-12-02  0:06   ` [PATCH v2 5/8] t/lib-patch-mode.sh: fix ignored "git" exit codes Ævar Arnfjörð Bjarmason
2022-12-02  1:31     ` René Scharfe
2022-12-02  0:06   ` [PATCH v2 6/8] merge tests: don't ignore "rev-parse" exit code in helper Ævar Arnfjörð Bjarmason
2022-12-02  1:41     ` René Scharfe
2022-12-02  0:06   ` [PATCH v2 7/8] tests: use "test_cmp_cmd" instead of "test" in sub-shells Ævar Arnfjörð Bjarmason
2022-12-02  0:06   ` [PATCH v2 8/8] tests: use "test_cmp_cmd" in misc tests Ævar Arnfjörð Bjarmason
2022-12-02  2:19     ` Junio C Hamano
2022-12-02 11:52   ` [PATCH v3 0/8] tests: fix ignored & hidden exit codes Ævar Arnfjörð Bjarmason
2022-12-02 11:52     ` [PATCH v3 1/8] merge tests: don't ignore "rev-parse" exit code in helper Ævar Arnfjörð Bjarmason
2022-12-05  0:24       ` Junio C Hamano
2022-12-02 11:52     ` [PATCH v3 2/8] auto-crlf tests: don't lose exit code in loops and outside tests Ævar Arnfjörð Bjarmason
2022-12-02 15:59       ` René Scharfe
2022-12-02 11:52     ` [PATCH v3 3/8] diff tests: fix ignored exit codes in t4023 Ævar Arnfjörð Bjarmason
2022-12-05  0:26       ` Junio C Hamano
2022-12-02 11:52     ` [PATCH v3 4/8] t/lib-patch-mode.sh: fix ignored exit codes Ævar Arnfjörð Bjarmason
2022-12-02 15:59       ` René Scharfe
2022-12-04  0:45       ` Eric Sunshine
2022-12-02 11:52     ` [PATCH v3 5/8] tests: use "test_cmp" instead of "test" in sub-shells Ævar Arnfjörð Bjarmason
2022-12-05  0:39       ` Junio C Hamano
2022-12-02 11:52     ` [PATCH v3 6/8] tests: don't lose 'test <str> = $(cmd ...)"' exit code Ævar Arnfjörð Bjarmason
2022-12-02 11:52     ` [PATCH v3 7/8] tests: don't lose "git" exit codes in "! ( git ... | grep )" Ævar Arnfjörð Bjarmason
2022-12-02 18:31       ` René Scharfe [this message]
2022-12-02 11:52     ` [PATCH v3 8/8] tests: don't lose mist "git" exit codes Ævar Arnfjörð Bjarmason
2022-12-04  0:40       ` Eric Sunshine
2022-12-05  0:45         ` Junio C Hamano
2022-12-19 10:19     ` [PATCH v4 0/6] tests: fix ignored & hidden " Ævar Arnfjörð Bjarmason
2022-12-19 10:19       ` [PATCH v4 1/6] auto-crlf tests: don't lose exit code in loops and outside tests Ævar Arnfjörð Bjarmason
2022-12-19 12:07         ` René Scharfe
2022-12-19 10:19       ` [PATCH v4 2/6] t/lib-patch-mode.sh: fix ignored exit codes Ævar Arnfjörð Bjarmason
2022-12-20  0:09         ` Junio C Hamano
2022-12-27 16:40         ` Phillip Wood
2022-12-27 18:14           ` Ævar Arnfjörð Bjarmason
2022-12-19 10:19       ` [PATCH v4 3/6] tests: don't lose exit status with "(cd ...; test <op> $(git ...))" Ævar Arnfjörð Bjarmason
2022-12-20  0:20         ` Junio C Hamano
2022-12-19 10:19       ` [PATCH v4 4/6] tests: don't lose exit status with "test <op> $(git ...)" Ævar Arnfjörð Bjarmason
2022-12-26  1:14         ` Junio C Hamano
2022-12-19 10:19       ` [PATCH v4 5/6] tests: don't lose "git" exit codes in "! ( git ... | grep )" Ævar Arnfjörð Bjarmason
2022-12-26  1:18         ` Junio C Hamano
2022-12-27 16:44         ` Phillip Wood
2022-12-27 17:13           ` Phillip Wood
2022-12-27 23:16           ` Junio C Hamano
2022-12-19 10:19       ` [PATCH v4 6/6] tests: don't lose misc "git" exit codes Ævar Arnfjörð Bjarmason
2022-12-27 16:46         ` Phillip Wood
2022-12-27 18:18           ` Ævar Arnfjörð Bjarmason
2022-12-27 23:17           ` Junio C Hamano
2022-12-20  0:06       ` [PATCH v4 0/6] tests: fix ignored & hidden " Junio C Hamano
2023-02-06 22:44       ` [PATCH v5 " Ævar Arnfjörð Bjarmason
2023-02-06 22:44         ` [PATCH v5 1/6] auto-crlf tests: don't lose exit code in loops and outside tests Ævar Arnfjörð Bjarmason
2023-02-06 22:44         ` [PATCH v5 2/6] t/lib-patch-mode.sh: fix ignored exit codes Ævar Arnfjörð Bjarmason
2023-02-06 22:44         ` [PATCH v5 3/6] tests: don't lose exit status with "(cd ...; test <op> $(git ...))" Ævar Arnfjörð Bjarmason
2023-02-06 22:44         ` [PATCH v5 4/6] tests: don't lose exit status with "test <op> $(git ...)" Ævar Arnfjörð Bjarmason
2023-02-06 22:44         ` [PATCH v5 5/6] tests: don't lose "git" exit codes in "! ( git ... | grep )" Ævar Arnfjörð Bjarmason
2023-02-06 22:44         ` [PATCH v5 6/6] tests: don't lose misc "git" exit codes Ævar Arnfjörð Bjarmason
2023-02-06 23:33         ` [PATCH v5 0/6] tests: fix ignored & hidden " 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

  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=3304ac3c-0d45-7293-bd7f-08f374786dcc@web.de \
    --to=l.s.r@web.de \
    --cc=avarab@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=sunshine@sunshineco.com \
    --cc=tboegi@web.de \
    /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).