diff --git a/lib/Expect.pm b/lib/Expect.pm index fc48140..3db44ca 100644 --- a/lib/Expect.pm +++ b/lib/Expect.pm @@ -507,7 +507,10 @@ sub expect { print STDERR ("expect(): handling param '$parm'...\n") if $Expect::Debug; if ( ref($parm) ) { - if ( ref($parm) eq 'ARRAY' ) { + if ( ref($parm) eq 'Regexp' ) { + push @pattern_list, [ $parm_nr, '-re', $parm, undef ]; + } + elsif ( ref($parm) eq 'ARRAY' ) { my $err = _add_patterns_to_list( \@pattern_list, \@timeout_list, $parm_nr, $parm @@ -2105,8 +2108,9 @@ makes the pty transparently act like a bidirectional pipe. Given $timeout in seconds Expect will wait for $object's handle to produce one of the match_patterns, which are matched exactly by default. If you -want a regexp match, prefix the pattern with '-re'. +want a regexp match, use a regexp object (C) or prefix the pattern with '-re'. + $object->expect(15, 'match me exactly', qr/match\s+me\s+exactly/); $object->expect(15, 'match me exactly','-re','match\s+me\s+exactly'); Due to o/s limitations $timeout should be a round number. If $timeout diff --git a/t/01-test.t b/t/01-test.t index b2dc02e..b6373a9 100644 --- a/t/01-test.t +++ b/t/01-test.t @@ -445,20 +445,13 @@ subtest respawn => sub { like $@, qr/^Cannot reuse an object with an already spawned command/; }; -subtest "implicit timeout" => sub { - diag "Basic tests..."; - plan tests => 4; +subtest "regexp ref" => sub { + plan tests => 1; my $exp = Expect->spawn("$Perl -v"); - $exp->timeout(10); - - ok( defined $exp ); $exp->log_user(0); - is( $exp->expect( "krzlbrtz", "Copyright" ), 2 ); - is( $exp->expect( "Larry Wall", "krzlbrtz" ), 1 ); - ok( not $exp->expect( "Copyright" ) ); -}; - + is( $exp->expect( 10, qr/L.*[WH]all/ ), 1 ); + }; use Test::Builder; my $Test = Test::Builder->new;