diff options
author | doy <doy@tozt.net> | 2009-02-05 00:18:48 -0500 |
---|---|---|
committer | doy <doy@tozt.net> | 2009-02-05 00:18:48 -0500 |
commit | d4bcc9ec0f929a76b02291efe94730889b3f349b (patch) | |
tree | 48fd512d0d46f93902b4e0192043e61d2473b650 /t | |
parent | ca117293a75de1d36189ed9af1450da4d8de993c (diff) | |
download | io-pty-easy-d4bcc9ec0f929a76b02291efe94730889b3f349b.tar.gz io-pty-easy-d4bcc9ec0f929a76b02291efe94730889b3f349b.zip |
add a couple tests for write(), some failing
Diffstat (limited to 't')
-rw-r--r-- | t/010-read-write.t | 34 |
1 files changed, 33 insertions, 1 deletions
diff --git a/t/010-read-write.t b/t/010-read-write.t index 7cd0ada..80f5f1e 100644 --- a/t/010-read-write.t +++ b/t/010-read-write.t @@ -1,7 +1,7 @@ #!perl use strict; use warnings; -use Test::More tests => 2; +use Test::More tests => 5; use IO::Pty::Easy; my $pty = IO::Pty::Easy->new; @@ -10,6 +10,38 @@ $pty->spawn("$^X -ple ''"); $pty->write("testing\n"); like($pty->read, qr/testing/, "basic read/write testing"); is($pty->read(0.1), undef, "read returns undef on timeout"); +$pty->kill; + +$pty->spawn("$^X -e 'sleep(1) while 1'"); +eval { + local $SIG{ALRM} = sub { + is($pty->write("should fail", 0.1), undef, + "write returns undef on timeout"); + $SIG{ALRM} = 'DEFAULT'; + alarm 1; + }; + alarm 1; + $pty->write('a'x(1024*1024)); +}; +$pty->kill; +$pty->close; + +# create an entirely new pty to clear the input buffer +$pty = IO::Pty::Easy->new; +$pty->spawn("$^X -e 'sleep(1) while 1'"); +my $result = "wrong"; +$result = eval { + local $SIG{ALRM} = sub { die "alarm\n" }; + alarm 2; + my $write_result = $pty->write('a'x(1024*1024), 0.1); + defined($write_result) ? "wrong" : "right"; +}; +TODO: { + local $TODO = "need to figure this one out"; + is($result, "right", "write times out properly even on the first call"); + isnt($@, "alarm\n", "write times out properly even on the first call"); +} + # if the perl script ends with a subprocess still running, the test will exit # with the exit status of the signal that the subprocess dies with, so we have # to kill the subprocess before exiting. |