diff options
Diffstat (limited to 't/basic.t')
-rw-r--r-- | t/basic.t | 47 |
1 files changed, 39 insertions, 8 deletions
@@ -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; |