|
BEGIN{ $ENV {PERL_ANYEVENT_MODEL} = 'Perl' }
BAIL_OUT 'OS unsupported' if $^O eq 'MSWin32' ;
my $proc = spawn [ 'perl' , '-e' , '$|=1; warn "starting\n"; my $line = <STDIN>; print("$line");' ];
my $timeout = AnyEvent->timer(
after => 10,
cb => sub {
diag 'timeout reached' ;
$proc ->signal( 'KILL' );
die 'timeout reached' ;
},
);
ok $proc ->launch, 'launch' ;
ok $proc -> send ( 'hello world' ), 'send' ;
my $msgs = [
$proc -> recv ,
$proc -> recv ,
];
ok(( grep { $_ eq 'starting' } @$msgs ), 'recv: str overload' );
ok(( grep { $_ eq 'hello world' } @$msgs ), 'recv: str overload' );
ok(( grep { $_ ->stdout } @$msgs ), 'msg->stdout' );
ok(( grep { $_ ->stderr } @$msgs ), 'msg->stderr' );
$proc ->terminate(10);
$proc -> join ;
undef $timeout ;
done_testing;
|