1use 5.10.0; 2use warnings; 3use strict; 4use Test::More; 5use FindBin qw( $RealBin ); 6use File::Spec::Functions qw( catfile ); 7 8BEGIN { 9 if ( $^O eq 'MSWin32' ) { 10 plan skip_all => "MSWin32: Expect not available."; 11 } 12 #if ( ! $ENV{TESTS_USING_EXPECT_OK} ) { 13 # plan skip_all => "Environment variable 'TESTS_USING_EXPECT_OK' not enabled."; 14 #} 15} 16 17eval "use Expect"; 18if ( $@ ) { 19 plan skip_all => $@; 20} 21 22use lib $RealBin; 23use Z_Data_Test_Choose; 24 25my $type = 'hide_cursor'; 26 27my $exp; 28eval { 29 $exp = Expect->new(); 30 $exp->raw_pty( 1 ); 31 $exp->log_stdout( 0 ); 32 $exp->slave->set_winsize( 24, 80, undef, undef ); 33 34 my $command = $^X; 35 my $script = catfile $RealBin, 'Z_choose.pl'; 36 my @parameters = ( $script, $type ); 37 38 -r $script or die "$script is NOT readable"; 39 $exp->spawn( $command, @parameters ) or die "Spawn '$command @parameters' NOT ok $!"; 40 1; 41} 42or plan skip_all => $@; 43 44 45 46my $a_ref = Z_Data_Test_Choose::return_test_data( $type ); 47my $ref = shift @$a_ref; 48 49my $expected = $ref->{expected}; 50my $ret = $exp->expect( 2, 51 [ 'Your choice: ' => sub { 52 $exp->send( "\r" ); 53 'exp_continue'; 54 } 55 ], 56 [ $expected => sub {} ], 57); 58 59ok( $ret, 'matched something' ); 60my $result = $exp->match(); 61$result = '' if ! defined $result; 62ok( $result eq $expected, "expected: '$expected', got: '$result'" ); 63 64$exp->hard_close(); 65 66done_testing(); 67