use
5.10.0;
BEGIN {
if
( $^O eq
'MSWin32'
) {
plan
skip_all
=>
"MSWin32: Expect not available."
;
}
}
eval
"use Expect"
;
if
( $@ ) {
plan
skip_all
=> $@;
}
my
$type
=
'hide_cursor'
;
my
$exp
;
eval
{
$exp
= Expect->new();
$exp
->raw_pty( 1 );
$exp
->log_stdout( 0 );
$exp
->slave->set_winsize( 24, 80,
undef
,
undef
);
my
$command
= $^X;
my
$script
= catfile
$RealBin
,
'Z_choose.pl'
;
my
@parameters
= (
$script
,
$type
);
-r
$script
or
die
"$script is NOT readable"
;
$exp
->spawn(
$command
,
@parameters
) or
die
"Spawn '$command @parameters' NOT ok $!"
;
1;
}
or plan
skip_all
=> $@;
my
$a_ref
= Z_Data_Test_Choose::return_test_data(
$type
);
my
$ref
=
shift
@$a_ref
;
my
$expected
=
$ref
->{expected};
my
$ret
=
$exp
->expect( 2,
[
'Your choice: '
=>
sub
{
$exp
->
send
(
"\r"
);
'exp_continue'
;
}
],
[
$expected
=>
sub
{} ],
);
ok(
$ret
,
'matched something'
);
my
$result
=
$exp
->match();
$result
=
''
if
!
defined
$result
;
ok(
$result
eq
$expected
,
"expected: '$expected', got: '$result'"
);
$exp
->hard_close();
done_testing();