BEGIN {
chdir
't'
if
-d
't'
; };
BEGIN {
use
lib
'../lib'
; };
?
'no_plan'
: (
skip_all
=>
"No interactive tests from harness"
);
my
$Class
=
'IPC::Cmd'
;
my
$Child
= File::Spec->catfile(
qw[src child.pl]
);
my
@FDs
= 0..20;
my
$IsWin32
= $^O eq
'MSWin32'
;
use_ok(
$Class
,
'run'
);
$IPC::Cmd::DEBUG
= 1;
my
$Have_IPC_Run
=
$Class
->can_use_ipc_run;
my
$Have_IPC_Open3
=
$Class
->can_use_ipc_open3;
my
@Conf
= (
[
$Have_IPC_Run
,
$Have_IPC_Open3
],
[ 0,
$Have_IPC_Open3
],
[ 0, 0 ]
);
my
@Opened
;
{
for
(
@FDs
) {
my
$fh
;
my
$rv
=
open
$fh
,
"<&$_"
;
push
@Opened
,
$_
if
$rv
;
}
diag(
"Opened FDs: @Opened"
);
cmp_ok(
scalar
(
@Opened
),
'>='
, 3,
"At least 3 FDs are opened"
);
}
for
my
$aref
(
@Conf
) {
local
$IPC::Cmd::USE_IPC_RUN
=
$aref
->[0];
local
$IPC::Cmd::USE_IPC_RUN
=
$aref
->[0];
local
$IPC::Cmd::USE_IPC_OPEN3
=
$aref
->[1];
local
$IPC::Cmd::USE_IPC_OPEN3
=
$aref
->[1];
diag(
"Config: IPC::Run = $aref->[0] IPC::Open3 = $aref->[1]"
);
ok( -t STDIN,
"STDIN attached to a tty"
);
for
my
$cmd
(
qq[$^X $Child]
,
qq[$^X $Child | $^X -neprint]
) {
diag(
"Please enter some input. It will be echo'd back to you"
);
my
$buffer
;
my
$ok
= run(
command
=>
$cmd
,
verbose
=> 1,
buffer
=> \
$buffer
);
ok(
$ok
,
" Command '$cmd' ran successfully"
);
SKIP: {
skip
"No buffers available"
, 1
unless
$Class
->can_capture_buffer;
ok(
defined
$buffer
,
" Input captured"
);
}
}
}
{
my
%open
=
map
{
$_
=> 1 }
@Opened
;
for
(
@FDs
) {
my
$fh
;
my
$rv
=
open
$fh
,
"<&=$_"
;
if
(
$open
{
$_
} ) {
ok(
$rv
,
"FD $_ opened"
);
ok(
$fh
,
" FH indeed opened"
);
is(
fileno
(
$fh
),
$_
,
" Opened at the correct fileno($_)"
);
}
else
{
ok( !
$rv
,
"FD $_ not opened"
);
ok( !(
fileno
(
$fh
)),
" FH indeed closed"
);
}
}
}