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 = 'simple'; 26 27my $exp; 28eval { 29 $exp = Expect->new(); 30 $exp->raw_pty( 1 ); 31 $exp->log_stdout( 0 ); 32 $exp->slave->clone_winsize_from( \*STDIN ); 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 45my $a_ref = Z_Data_Test_Choose::return_test_data( $type ); 46my $ref = shift @$a_ref; 47 48my $ret = $exp->expect( 2, [ qr/Your choice: .*/ ] ); 49my $expected = $ref->{expected}; 50$exp->send( "\r" ); 51$ret = $exp->expect( 2, [ qr/<.+>/ ] ); 52ok( $ret, 'matched something' ); 53 54my $result = $exp->match(); 55$result = '' if ! defined $result; 56ok( $result eq $expected, qq[expected: "$expected", got: "$result"] ); 57 58$exp->hard_close(); 59 60done_testing(); 61