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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Wed, Dec 14, 2011 at 05:17:14PM +0100, Thomas Rast wrote:

> > 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@xxxxxxxxxxx
  ... 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
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]