git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: tr/pty-all (Re: What's cooking in git.git (Dec 2011, #04; Tue, 13))

From
Jeff King <peff@peff.net>
Date
Dec 14, 2011, 23:07 UTC
Message-ID
<20111214230713.GA13128@sigill.intra.peff.net>
In-Reply-To
<201112141717.15021.trast@student.ethz.ch>
On Wed, Dec 14, 2011 at 05:17:14PM +0100, Thomas Rast wrote:
Show 5 quoted lines
> > I also find Jeff's patch [3] appealing.
> 
> Me too, though wonder whether feeding a file full of garbage wouldn't
> be better, so as to trip up commands that try to read only from a
> non-tty stdin.

Interesting idea. Instead of getting an immediate EOF from /dev/null, they'll get some junk which they may or may not complain about. I played around with this a bit, redirecting test stdin from a file with:

  This is a garbage file that will be connected to the stdin of each
  test.

(with the hope that when you see that in an error message, it will be obvious what has happened).

It turns out that shortlog (the one bug of this type in the test suite) doesn't care at all. It will happily chew on that garbage and behave just the same as if it had been given /dev/null.

There is also the minor issue that if there are multiple invocations of the input-chewing command, the first one will eat all of the input, and subsequent ones will just get the equivalent of /dev/null anyway. I.e.:

  test_expect_success 'git shortlog $foo' ;# will eat all of our stdin
  test_expect_success 'git shortlog $bar' ;# sees immediate EOF

That may not matter, though, as you would hope for the first invocation to complain, at which point you fix it, revealing the failures in later tests (or if you're clever, noticing in the first place that they all have the same bug).

You can make this somewhat more robust by redirecting stdin for _test_eval (so each test gets a fresh descriptor to the garbage file). However, that disallows redirecting a specific test's stdin in the test script, like:

  test_expect_success 'some test' '
    cat >expect &&
    some_command >actual &&
    test_cmp expect actual
  ' <<\EOF
  the expected
  data
  EOF

This construct probably seems silly at first, but see how it is used in t6006:

  test_format author %an%n%ae%n%ad%n%aD%n%at <<\EOF
  commit ...
  A U Thor
  author@example.com
  ... etc ...
  EOF

where test_format is a generic function that just gobbles stdin into the "expect" file. As it turns out, test_format actually runs the "cat" outside of the "test_expect_success", but quite often we put it inside. So maybe it isn't worth caring about. You could also argue that the whole thing should just be inside a test_expect_success.

-Peff
Previous: Junio C HamanoNext: Jeff King
Message 5 of 12 in “What's cooking in git.git (Dec 2011, #04; Tue, 13)”
  1. Junio C HamanoDec 14, 2011
  2. tr/pty-all (Re: What's cooking in git.git (Dec 2011, #04; Tue, 13))Jonathan Nieder, Dec 14, 2011
  3. Thomas RastDec 14, 2011
  4. Junio C HamanoDec 14, 2011
  5. Jeff KingDec 14, 2011
  6. Jeff KingDec 14, 2011
  7. Jonathan NiederDec 14, 2011
  8. Jeff KingDec 15, 2011
  9. Jeff KingDec 15, 2011
  10. Junio C HamanoDec 15, 2011
  11. Jeff KingDec 15, 2011
  12. Junio C HamanoDec 15, 2011

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.