IPC-Run

 view release on metacpan or  search on metacpan

t/pty.t  view on Meta::CPAN

#!/usr/bin/perl

=pod

=head1 NAME

pty.t - Test suite for IPC::Run's pty (pseudo-terminal) support

=head1 DESCRIPTION

This test suite starts off with a test that seems to cause a deadlock
on freebsd: \@cmd, '<pty<', ... '>', ..., '2>'... 

This seems to cause the child process entry in the process table to
hang around after the child exits.  Both output pipes are closed, but
the PID is still valid so IPC::Run::finish() thinks it's still alive and
the whole shebang deadlocks waiting for the child to exit.

This is a very rare corner condition, so I'm not patching in a fix yet.
One fix might be to hack IPC::Run to close the master pty when all outputs
from the child are closed.  That's a hack, not sure what to do about it.

This problem needs to be reproduced in a standalone script and investigated
further, but I have not the time.

=cut

use strict;
use warnings;

BEGIN {
    $|  = 1;
    $^W = 1;
    if ( $ENV{PERL_CORE} ) {
        chdir '../lib/IPC/Run' if -d '../lib/IPC/Run';
        unshift @INC, 'lib', '../..';
        $^X = '../../../t/' . $^X;
    }
}

use Test::More;

BEGIN {
    if ( eval { require IO::Pty; } ) {
        plan tests => 37;
    }
    else {
        plan skip_all => "IO::Pty not installed";
    }
}

use IPC::Run::Debug qw( _map_fds );
use IPC::Run qw( start pump finish );

select STDERR;
select STDOUT;

sub pty_warn {
    warn "\nWARNING: $_[0].\nWARNING: '<pty<', '>pty>' $_[1] not work.\n\n";
}

if ( $^O !~ /Win32/ ) {

    #   my $min = 0.9;
    for ( eval { require IO::Pty; IO::Pty->VERSION } ) {
        s/_//g if defined;
        if ( !defined ) {
            pty_warn "IO::Pty not found", "will";
        }
        elsif ( $_ == 0.02 ) {
            pty_warn "IO::Pty v$_ has spurious warnings, try 0.9 or later", "may";
        }
        elsif ( $_ < 1.00 ) {
            pty_warn "IO::Pty 1.00 is strongly recommended", "may";
        }
    }



( run in 2.536 seconds using v1.01-cache-2.11-cpan-5a3173703d6 )