1Test::Expect(3)       User Contributed Perl Documentation      Test::Expect(3)
2
3
4

NAME

6       Test::Expect - Automated driving and testing of terminal-based programs
7

SYNOPSIS

9         # in a t/*.t file:
10         use Test::Expect;
11         use Test::More tests => 13;
12         expect_run(
13           command => ["perl", "testme.pl"],
14           prompt  => 'testme: ',
15           quit    => 'quit',
16         );
17         expect("ping", "pong", "expect");
18         expect_send("ping", "expect_send");
19         expect_is("* Hi there, to testme", "expect_is");
20         expect_like(qr/Hi there, to testme/, "expect_like");
21

DESCRIPTION

23       Test::Expect is a module for automated driving and testing of terminal-
24       based programs.  It is handy for testing interactive programs which
25       have a prompt, and is based on the same concepts as the Tcl Expect
26       tool.  As in Expect::Simple, the Expect object is made available for
27       tweaking.
28
29       Test::Expect is intended for use in a test script.
30

SUBROUTINES

32   expect_run
33       The expect_run subroutine sets up Test::Expect. You must pass in the
34       interactive program to run, what the prompt of the program is, and
35       which command quits the program:
36
37         expect_run(
38           command => ["perl", "testme.pl"],
39           prompt  => 'testme: ',
40           quit    => 'quit',
41         );
42
43       The "command" may either be a string, or an arrayref of program and
44       arguments; the latter for bypasses the shell.
45
46   expect
47       The expect subroutine is the catch all subroutine. You pass in the
48       command, the expected output of the subroutine and an optional comment.
49
50         expect("ping", "pong", "expect");
51
52   expect_send
53       The expect_send subroutine sends a command to the program. You pass in
54       the command and an optional comment.
55
56         expect_send("ping", "expect_send");
57
58   expect_is
59       The expect_is subroutine tests the output of the program like
60       Test::More's is. It has an optional comment:
61
62         expect_is("* Hi there, to testme", "expect_is");
63
64   expect_like
65       The expect_like subroutine tests the output of the program like
66       Test::More's like. It has an optional comment:
67
68         expect_like(qr/Hi there, to testme/, "expect_like");
69
70   expect_handle
71       This returns the Expect object.
72
73   expect_quit
74       Closes the Expect handle.
75

SEE ALSO

77       Expect, Expect::Simple.
78

AUTHOR

80       Best Practical Solutions, LLC <modules@bestpractical.com>
81
82       Original module by Leon Brocard, <acme@astray.com>
83

BUGS

86       This extension is Copyright (C) 2015 Best Practical Solutions, LLC.
87
88       Copyright (C) 2005, Leon Brocard
89
90       This module is free software; you can redistribute it or modify it
91       under the same terms as Perl itself.
92
93
94
95perl v5.34.0                      2022-01-21                   Test::Expect(3)
Impressum