git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jeff King <peff@peff.net>
To: "SZEDER Gábor" <szeder.dev@gmail.com>
Cc: git@vger.kernel.org, Junio C Hamano <gitster@pobox.com>
Subject: Re: [PATCH 08/10] t: forbid piping into 'test_i18ngrep'
Date: Fri, 26 Jan 2018 13:41:51 -0500	[thread overview]
Message-ID: <20180126184151.GD27618@sigill.intra.peff.net> (raw)
In-Reply-To: <20180126123708.21722-9-szeder.dev@gmail.com>

On Fri, Jan 26, 2018 at 01:37:06PM +0100, SZEDER Gábor wrote:

> When checking a git command's output with 'test_i18ngrep', it's
> tempting to conveniently pipe the git command's standard output into
> 'test_i18ngrep'.  Unfortunately, this is an anti-pattern, because it
> hides the git command's exit code, and the test could continue even if
> the command exited with error.
> 
> Add a bit of linting to 'test_i18ngrep' to detect when data is fed to
> its standard input and to error out with a "bug in the test script"
> message.
> 
> Note that this change will also forbid cases where 'test_i18ngrep'
> would legitimately read its standard input, e.g.
> 
>   - when its standard input is redirected from a file, or
> 
>   - when a git command's standard output is first written to an
>     intermediate file, which is then preprocessed by a non-git command
>     before the results are piped into 'test_i18ngrep'.
> 
> See two of the previous patches for the only such cases we had in our
> test suite.  However, reliably preventing this antipattern is arguably
> more important than supporting these cases, which can be worked around
> by only minor inconveniences.

The idea seems reasonable to me. Let's think about what the escape hatch
looks like to work around it if you need to.

I guess you've got:

  cat >file &&
  test_i18ngrep ... file

which is not too bad.

You've also got:

  test_i18ngrep ... -

though that relies on the underlying grep understanding "-" (which is in
POSIX, though with a rather vague "if the implementations supports it").
And it wouldn't work with the "read" test in this patch.

> diff --git a/t/test-lib-functions.sh b/t/test-lib-functions.sh
> index 92ed02937..e381d50d0 100644
> --- a/t/test-lib-functions.sh
> +++ b/t/test-lib-functions.sh
> @@ -719,6 +719,10 @@ test_i18ncmp () {
>  # under GETTEXT_POISON this pretends that the command produced expected
>  # results.
>  test_i18ngrep () {
> +	( read line ) &&
> +	error "bug in the test script: data on test_i18ngrep's stdin;" \
> +	      "perhaps a git command's output is piped into it?"
> +

This seems kind of hacky compared to just seeing if there is a file
argument. But I suppose that is hard to do, since we just pass through
the arguments to grep.

Though looking at our test_18ngrep invocations, they are simple enough
that would just ask "are there two non-option arguments at the end of
the command line". The exception is "-e", but IMHO we could just drop
that. It serves no purpose unless you're trying to hide a "-" at the
start of your pattern, and in fact we used to ban it since sysv grep
didn't understand it (e.g., aadbe44f883).

-Peff

  parent reply	other threads:[~2018-01-26 18:42 UTC|newest]

Thread overview: 49+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-01-26 12:36 [PATCH 00/10] 'test_i18ngrep'-related fixes and improvements SZEDER Gábor
2018-01-26 12:36 ` [PATCH 01/10] t5541: add 'test_i18ngrep's missing filename parameter SZEDER Gábor
2018-01-26 18:23   ` Jeff King
2018-01-26 18:23     ` Jeff King
2018-01-26 12:37 ` [PATCH 02/10] t5812: " SZEDER Gábor
2018-01-26 18:27   ` Jeff King
2018-02-07 13:53     ` SZEDER Gábor
2018-02-07 14:38       ` Jeff King
2018-01-30  9:50   ` Simon Ruderich
2018-01-26 12:37 ` [PATCH 03/10] t6022: don't run 'git merge' upstream of a pipe SZEDER Gábor
2018-01-26 12:37 ` [PATCH 04/10] t4001: don't run 'git status' " SZEDER Gábor
2018-01-26 12:37 ` [PATCH 05/10] t5510: consolidate 'grep' and 'test_i18ngrep' patterns SZEDER Gábor
2018-01-26 18:16   ` Junio C Hamano
2018-01-26 19:20     ` SZEDER Gábor
2018-01-26 19:23       ` Junio C Hamano
2018-01-26 12:37 ` [PATCH 06/10] t5536: let 'test_i18ngrep' read the file without redirection SZEDER Gábor
2018-01-26 12:37 ` [PATCH 07/10] t: move 'test_i18ncmp' and 'test_i18ngrep' to 'test-lib-functions.sh' SZEDER Gábor
2018-01-26 18:19   ` Junio C Hamano
2018-01-26 18:32     ` Jeff King
2018-01-26 19:08     ` SZEDER Gábor
2018-01-26 12:37 ` [PATCH 08/10] t: forbid piping into 'test_i18ngrep' SZEDER Gábor
2018-01-26 18:24   ` Junio C Hamano
2018-01-26 18:39     ` Junio C Hamano
2018-01-26 18:43       ` Jeff King
2018-01-26 18:51     ` SZEDER Gábor
2018-01-26 19:19       ` Junio C Hamano
2018-01-26 18:41   ` Jeff King [this message]
2018-01-26 12:37 ` [PATCH 09/10] t: make sure that 'test_i18ngrep' got enough parameters SZEDER Gábor
2018-01-26 18:47   ` Jeff King
2018-01-26 22:07   ` Eric Sunshine
2018-01-26 12:37 ` [PATCH 10/10] t: make 'test_i18ngrep' more informative on failure SZEDER Gábor
2018-01-26 18:50   ` Jeff King
2018-01-26 19:23     ` SZEDER Gábor
2018-01-26 19:25       ` Jeff King
2018-01-26 20:26         ` SZEDER Gábor
2018-01-26 20:32           ` Jeff King
2018-01-26 18:51 ` [PATCH 00/10] 'test_i18ngrep'-related fixes and improvements Jeff King
2018-02-08 15:56 ` [PATCH v2 0/9] " SZEDER Gábor
2018-02-08 15:56   ` [PATCH v2 1/9] t5541: add 'test_i18ngrep's missing filename parameter SZEDER Gábor
2018-02-08 15:56   ` [PATCH v2 2/9] t5812: " SZEDER Gábor
2018-02-08 15:56   ` [PATCH v2 3/9] t6022: don't run 'git merge' upstream of a pipe SZEDER Gábor
2018-02-08 15:56   ` [PATCH v2 4/9] t4001: don't run 'git status' " SZEDER Gábor
2018-02-08 15:56   ` [PATCH v2 5/9] t5510: consolidate 'grep' and 'test_i18ngrep' patterns SZEDER Gábor
2018-02-08 15:56   ` [PATCH v2 6/9] t5536: let 'test_i18ngrep' read the file without redirection SZEDER Gábor
2018-02-08 15:56   ` [PATCH v2 7/9] t: move 'test_i18ncmp' and 'test_i18ngrep' to 'test-lib-functions.sh' SZEDER Gábor
2018-02-08 15:56   ` [PATCH v2 8/9] t: validate 'test_i18ngrep's parameters SZEDER Gábor
2018-02-08 16:34     ` Jeff King
2018-02-08 15:56   ` [PATCH v2 9/9] t: make 'test_i18ngrep' more informative on failure SZEDER Gábor
2018-02-08 16:36   ` [PATCH v2 0/9] 'test_i18ngrep'-related fixes and improvements Jeff King

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=20180126184151.GD27618@sigill.intra.peff.net \
    --to=peff@peff.net \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=szeder.dev@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).