From f9005e892729261fb9c10d370f161fa1f4fd7393 Mon Sep 17 00:00:00 2001 From: Jesse Luehrs Date: Wed, 7 Mar 2012 03:00:03 -0600 Subject: few more tweaks to make these tests more reliable --- t/basic.t | 47 +++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 39 insertions(+), 8 deletions(-) (limited to 't/basic.t') diff --git a/t/basic.t b/t/basic.t index 4c72512..ae51826 100644 --- a/t/basic.t +++ b/t/basic.t @@ -4,6 +4,7 @@ use warnings; use Test::More; use IO::Pty::Easy; +use IO::Select; my $pty = IO::Pty::Easy->new(handle_pty_size => 0); @@ -24,15 +25,45 @@ $pty->spawn($^X, (map {; '-I', $_ } @INC), '-e', $script); alarm 60; $pty->write("foo\n"); -is($pty->read(undef, 5), "foo$crlf"); -is($pty->read(undef, 5), "foo$crlf"); +is(full_read($pty), "foo${crlf}foo${crlf}"); $pty->write("bar\nbaz\n"); -is($pty->read(undef, 5), "bar$crlf"); -is($pty->read(undef, 5), "baz$crlf"); -is($pty->read(undef, 5), "bar$crlf"); -is($pty->read(undef, 5), "baz$crlf"); +like( + full_read($pty), + qr{ + ^ + bar \Q$crlf\E + (?: + bar \Q$crlf\E + baz \Q$crlf\E + | + baz \Q$crlf\E + bar \Q$crlf\E + ) + baz \Q$crlf\E + $ + }mx, +); $pty->write("\n"); -is($pty->read(undef, 2), "$crlf"); -is($pty->read(undef, 6), "done\n"); +is(full_read($pty), "${crlf}done\n"); + +sub full_read { + my ($fh) = @_; + + my $select = IO::Select->new($fh); + return if $select->has_exception(0.1); + + 1 while !$select->can_read(1); + + my $ret; + while ($select->can_read(1)) { + my $new; + sysread($fh, $new, 4096); + last unless defined($new) && length($new); + $ret .= $new; + return $ret if $select->has_exception(0.1); + } + + return $ret; +} done_testing; -- cgit v1.2.3-54-g00ecf