summaryrefslogtreecommitdiffstats
path: root/t/basic.t
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2012-03-07 03:00:03 -0600
committerJesse Luehrs <doy@tozt.net>2012-03-07 03:00:03 -0600
commitf9005e892729261fb9c10d370f161fa1f4fd7393 (patch)
tree550c710bec43f3310a9da442373c94f34e0073d4 /t/basic.t
parente1b070276d8c8beb0dcc76bc2c2ac070564e0c24 (diff)
downloadterm-filter-f9005e892729261fb9c10d370f161fa1f4fd7393.tar.gz
term-filter-f9005e892729261fb9c10d370f161fa1f4fd7393.zip
few more tweaks to make these tests more reliable
Diffstat (limited to 't/basic.t')
-rw-r--r--t/basic.t47
1 files changed, 39 insertions, 8 deletions
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;