diff options
Diffstat (limited to 't/basic.t')
-rw-r--r-- | t/basic.t | 49 |
1 files changed, 36 insertions, 13 deletions
@@ -4,35 +4,41 @@ use warnings; use Test::More; use Test::Requires 'Test::TCP', 'IO::Pty::Easy'; +use IO::Select; + use App::Termcast; pipe(my $cread, my $swrite); pipe(my $sread, my $cwrite); +alarm 60; + test_tcp( client => sub { my $port = shift; close $swrite; close $sread; { sysread($cread, my $buf, 1) } - my $inc = join ':', grep { !ref } @INC; my $client_script = <<EOF; - BEGIN { \@INC = split /:/, '$inc' } use App::Termcast; no warnings 'redefine'; local *App::Termcast::_termsize = sub { return (80, 24) }; use warnings 'redefine'; - my \$tc = App::Termcast->new(host => '127.0.0.1', port => $port, - user => 'test', password => 'tset'); - \$tc->run('$^X', "-e", "print 'foo'"); + my \$tc = App::Termcast->new( + host => '127.0.0.1', + port => $port, + user => 'test', + password => 'tset', + ); + \$tc->run(\$^X, '-e', "print 'foo'"); EOF my $pty = IO::Pty::Easy->new; - $pty->spawn("$^X", "-e", $client_script); + $pty->spawn($^X, (map {; '-I', $_ } @INC), '-e', $client_script); syswrite($cwrite, 'a'); { sysread($cread, my $buf, 1) } - is($pty->read, 'foo', 'got the right thing on stdout'); + is(full_read($pty), 'foo', 'got the right thing on stdout'); }, server => sub { my $port = shift; @@ -45,17 +51,34 @@ EOF syswrite($swrite, 'a'); my $client = $sock->accept; { sysread($sread, my $buf, 1) } - my $login; - $client->recv($login, 4096); - is($login, + is(full_read($client), "hello test tset\n\e\[H\x00{\"geometry\":[80,24]}\xff\e\[H\e\[2J", "got the correct login info"); $client->send("hello, test\n"); - my $output; - $client->recv($output, 4096); - is($output, "foo", 'sent the right data to the server'); + is(full_read($client), "foo"); syswrite($swrite, 'a'); + sleep 1 while $client->connected; }, ); +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; |