1Test::Expect(3) User Contributed Perl Documentation Test::Expect(3)
2
3
4
6 Test::Expect - Automated driving and testing of terminal-based programs
7
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
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
32 expect_run
33
34 The expect_run subroutine sets up Test::Expect. You must pass in the
35 interactive program to run, what the prompt of the program is, and
36 which command quits the program:
37
38 expect_run(
39 command => "perl testme.pl",
40 prompt => 'testme: ',
41 quit => 'quit',
42 );
43
44 expect
45
46 The expect subroutine is the catch all subroutine. You pass in the com‐
47 mand, the expected output of the subroutine and an optional comment.
48
49 expect("ping", "pong", "expect");
50
51 expect_send
52
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
60 The expect_is subroutine tests the output of the program like
61 Test::More's is. It has an optional comment:
62
63 expect_is("* Hi there, to testme", "expect_is");
64
65 expect_like
66
67 The expect_like subroutine tests the output of the program like
68 Test::More's like. It has an optional comment:
69
70 expect_like(qr/Hi there, to testme/, "expect_like");
71
72 expect_handle
73
74 This returns the Expect object.
75
77 Expect, Expect::Simple.
78
80 Leon Brocard, "<acme@astray.com>"
81
83 Copyright (C) 2005, Leon Brocard
84
85 This module is free software; you can redistribute it or modify it
86 under the same terms as Perl itself.
87
88
89
90perl v5.8.8 2006-05-18 Test::Expect(3)