IPC-Run
view release on metacpan or search on metacpan
t/close_stdin.t view on Meta::CPAN
$h->close_stdin;
eval { $h->close_stdin };
is( $@, '', "calling close_stdin twice does not throw" );
$h->finish;
ok(1, "finish after double close_stdin succeeds");
}
## Test 5: close_stdin followed by finish works correctly
{
my $in = "test\n";
my $out = '';
my $h = start \@echoer, \$in, \$out, timeout(5);
pump $h until $in eq '';
$h->close_stdin;
# Now finish should work without accumulating unbounded output
$h->finish;
is( $out, "test$nl", "close_stdin + finish produces correct output" );
}
## Test 6: file descriptor leak check
{
my $fd_map_before = _map_fds;
my ( $in, $out ) = ( '', '' );
my $h = start \@echoer, \$in, \$out, timeout(5);
$in = "fd check\n";
pump $h until $in eq '';
$h->close_stdin;
while ( $h->pumpable ) {
$h->pump;
}
$h->finish;
is( _map_fds, $fd_map_before, "no file descriptor leak after close_stdin" );
}
## Test 7: close_stdin with pipeline (multiple children)
{
my @upper = ( $^X, '-pe', '$_ = uc' );
my ( $in, $out ) = ( '', '' );
my $h = start \@echoer, \$in, '|', \@upper, \$out, timeout(5);
$in = "pipeline test\n";
pump $h until $in eq '';
$h->close_stdin;
while ( $h->pumpable ) {
$h->pump;
}
$h->finish;
is( $out, "PIPELINE TEST$nl", "close_stdin works with pipelines" );
}
## Test 8: close_stdin with multi-line streaming pattern
{
my @counter = ( $^X, '-e', '
$| = 1;
my $count = 0;
while (<STDIN>) {
$count++;
print "line $count\n";
}
print "total: $count\n";
' );
my ( $in, $out ) = ( '', '' );
my $h = start \@counter, \$in, \$out, timeout(5);
# Feed lines one at a time
for my $i ( 1 .. 5 ) {
$in = "input $i\n";
pump $h until $in eq '';
}
# Close stdin to trigger the "total" line
$h->close_stdin;
my $collected = '';
while ( $h->pumpable ) {
$h->pump;
$collected .= $out;
$out = '';
}
$h->finish;
like( $collected, qr/total: 5/, "child received all input before close_stdin" );
like( $collected, qr/line 5/, "all lines processed" );
}
( run in 0.623 second using v1.01-cache-2.11-cpan-140bd7fdf52 )