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 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 expect
44 The expect subroutine is the catch all subroutine. You pass in the
45 command, the expected output of the subroutine and an optional comment.
46
47 expect("ping", "pong", "expect");
48
49 expect_send
50 The expect_send subroutine sends a command to the program. You pass in
51 the command and an optional comment.
52
53 expect_send("ping", "expect_send");
54
55 expect_is
56 The expect_is subroutine tests the output of the program like
57 Test::More's is. It has an optional comment:
58
59 expect_is("* Hi there, to testme", "expect_is");
60
61 expect_like
62 The expect_like subroutine tests the output of the program like
63 Test::More's like. It has an optional comment:
64
65 expect_like(qr/Hi there, to testme/, "expect_like");
66
67 expect_handle
68 This returns the Expect object.
69
71 Closes the Expect handle.
72
74 Expect, Expect::Simple.
75
77 Leon Brocard, "<acme@astray.com>"
78
80 Copyright (C) 2005, Leon Brocard
81
82 This module is free software; you can redistribute it or modify it
83 under the same terms as Perl itself.
84
85
86
87perl v5.12.0 2010-05-06 Test::Expect(3)