git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/3] test-terminal: give the child an empty stdin TTY
@ 2011-12-12 18:09 Thomas Rast
  2011-12-12 18:09 ` [PATCH 2/3] test-terminal: set output terminals to raw mode Thomas Rast
                   ` (3 more replies)
  0 siblings, 4 replies; 16+ messages in thread
From: Thomas Rast @ 2011-12-12 18:09 UTC (permalink / raw)
  To: git; +Cc: Junio C Hamano, Jeff King, Jonathan Nieder, Michael Haggerty

So far, test-terminal.perl did not care at all about the stdin (that
is, leave it as-is).  This mostly works well, but git-shortlog is a
problem:

* It takes decisions based on isatty(0).  (No test checks this, but
  compare 'git shortlog </dev/null' with 'git shortlog' in a
  terminal.)

* It reads all of stdin if !isatty(0) and no arguments were passed.

Because of the latter, t7006.58ff cause unexpected results if you do:

  git rev-list <range> |
  while read sha; do
    git checkout sha
    make test
  done

If t7006 runs during any 'make test' run, the next 'read sha' will
fail (git-shortlog ate all of stdin already) and the while loop stops
immediately.  In particular, this loop will only ever successfully
test *one* revision.

To fix this, change test-terminal.perl to open a third PTY for stdin,
send an EOF (Ctrl-D) immediately and close it later.  Since this may
not be portable, we use POSIX::Termios to set it to Ctrl-D.

Noticed-by: Michael Haggerty <mhagger@alum.mit.edu>
Signed-off-by: Thomas Rast <trast@student.ethz.ch>
---
 t/test-terminal.perl |   22 +++++++++++++++++++---
 1 files changed, 19 insertions(+), 3 deletions(-)

diff --git a/t/test-terminal.perl b/t/test-terminal.perl
index ee01eb9..87b5a8c 100755
--- a/t/test-terminal.perl
+++ b/t/test-terminal.perl
@@ -4,14 +4,16 @@
 use warnings;
 use IO::Pty;
 use File::Copy;
+use POSIX ();
 
-# Run @$argv in the background with stdio redirected to $out and $err.
+# Run @$argv in the background with stdio redirected from $in and to $out and $err.
 sub start_child {
-	my ($argv, $out, $err) = @_;
+	my ($argv, $in, $out, $err) = @_;
 	my $pid = fork;
 	if (not defined $pid) {
 		die "fork failed: $!"
 	} elsif ($pid == 0) {
+		open STDIN, "<&", $in;
 		open STDOUT, ">&", $out;
 		open STDERR, ">&", $err;
 		close $out;
@@ -64,13 +66,27 @@ sub copy_stdio {
 		or exit 1;
 }
 
+sub set_default_eof_char {
+	my $fd = fileno shift;
+	my $termios = POSIX::Termios->new;
+	$termios->getattr($fd);
+	$termios->setcc(&POSIX::VEOF, 4);
+	$termios->setattr($fd, &POSIX::TCSANOW)
+		or die "Termios::setattr failed: $!";
+}
+
 if ($#ARGV < 1) {
 	die "usage: test-terminal program args";
 }
+my $master_in = new IO::Pty;
 my $master_out = new IO::Pty;
 my $master_err = new IO::Pty;
-my $pid = start_child(\@ARGV, $master_out->slave, $master_err->slave);
+set_default_eof_char($master_in->slave);
+my $pid = start_child(\@ARGV, $master_in->slave, $master_out->slave, $master_err->slave);
+close $master_in->slave;
 close $master_out->slave;
 close $master_err->slave;
+print $master_in "\cD";
 copy_stdio($master_out, $master_err);
+close $master_in;
 exit(finish_child($pid));
-- 
1.7.8.431.g2abf2

^ permalink raw reply related	[flat|nested] 16+ messages in thread

end of thread, other threads:[~2011-12-13  5:10 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-12-12 18:09 [PATCH 1/3] test-terminal: give the child an empty stdin TTY Thomas Rast
2011-12-12 18:09 ` [PATCH 2/3] test-terminal: set output terminals to raw mode Thomas Rast
2011-12-12 18:23   ` Jonathan Nieder
2011-12-12 19:01     ` Thomas Rast
2011-12-13  5:09       ` Jonathan Nieder
2011-12-12 18:09 ` [PATCH 3/3] t/lib-terminal: test test-terminal's sanity Thomas Rast
2011-12-12 18:25   ` Jonathan Nieder
2011-12-12 18:19 ` [PATCH 1/3] test-terminal: give the child an empty stdin TTY Jonathan Nieder
2011-12-12 18:34   ` Thomas Rast
2011-12-12 19:05     ` Jonathan Nieder
2011-12-12 20:06       ` Junio C Hamano
2011-12-12 19:07 ` Junio C Hamano
2011-12-12 19:14   ` Thomas Rast
2011-12-12 19:16   ` Jeff King
2011-12-12 20:38     ` Junio C Hamano
2011-12-12 23:25     ` Jonathan Nieder

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).