File: timeout.t

package info (click to toggle)
libexpect-perl 1.38-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 444 kB
  • sloc: perl: 1,818; makefile: 13
file content (48 lines) | stat: -rwxr-xr-x 1,106 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
use strict;
use warnings;

use Test::More tests => 2;
use Expect;

my $Perl = $^X;
my $slow_program = "$Perl t/utils/slow-interaction.pl";

subtest "implicit timeout" => sub {
	plan tests => 1;

	my $exp = Expect->spawn($slow_program);
    $exp->timeout(10);
	$exp->log_user(0);

	$exp->expect( 
        [ "string to transform", sub { $_[0]->send("banana\n") } ]
    );

	is $exp->expect( "BANANA" ) => 1;
};

subtest "undef as timeout" => sub {
	plan tests => 2;

    subtest "no explicit timeout, we get default" => sub {
        my $exp = Expect->spawn($slow_program);
        $exp->timeout(1);
        $exp->log_user(0);

        # no explicit timeout, we get the default of '1' and fail
        is $exp->expect( 
            [ "string to transform", sub { $_[0]->send("banana\n") } ]
        ) => undef;
    };

    subtest "explicit timeout, we wait forever" => sub {
        my $exp = Expect->spawn($slow_program);
        $exp->timeout(1);
        $exp->log_user(0);

        is $exp->expect( undef,
            [ "string to transform", sub { $_[0]->send("banana\n") } ]
        ) => 1;
    };

};