Test::Expect(3pm)
π NAME π
Test::Expect β the β¨ automated driving and testing β¨ of terminal-based programs, bestie. Like, you know how you could sit there typing at your interactive program forever? Not anymore. π
πΈ SYNOPSIS πΈ
# in a t/*.t file:
use Test::Expect;
use Test::More tests => 13;
expect_run(
command => ["perl", "testme.pl"],
prompt => 'testme: ',
quit => 'quit',
);
expect("ping", "pong", "expect");
expect_send("ping", "expect_send");
expect_is("* Hi there, to testme", "expect_is");
expect_like(qr/Hi there, to testme/, "expect_like");
π¦ DESCRIPTION π¦
Okay so Test::Expect is a module for automated driving and testing of terminal-based programs. It is so handy for testing interactive programs which have a prompt, and it's based on the same concepts as the Tcl Expect tool. And just like in Expect::Simple, the Expect object is made available for tweaking β main character energy, you get full access. π
Test::Expect is intended for use in a test script. Periodt. π
π SUBROUTINES π
β expect_run
The expect_run subroutine sets up Test::Expect. You must pass in the interactive program to run, what the prompt of the program is, and which command quits the program:
expect_run(
command => ["perl", "testme.pl"],
prompt => 'testme: ',
quit => 'quit',
);
The "command" may either be a string, or an arrayref of program and arguments; the latter for bypasses the shell. πβ¨
β expect
The expect subroutine is the catch-all subroutine, the one that does a little bit of everything. You pass in the command, the expected output of the subroutine and an optional comment.
expect("ping", "pong", "expect");
β expect_send
The expect_send subroutine sends a command to the program. You pass in the command and an optional comment.
expect_send("ping", "expect_send");
β expect_is
The expect_is subroutine tests the output of the program like Test::More's is. It has an optional comment:
expect_is("* Hi there, to testme", "expect_is");
β expect_like
The expect_like subroutine tests the output of the program like Test::More's like. It has an optional comment:
expect_like(qr/Hi there, to testme/, "expect_like");
β expect_handle
This returns the Expect object. π«Ά
β expect_quit
Closes the Expect handle. Bye bestie, slay, see you never. π
π SEE ALSO π
ExpectExpect::Simple
π AUTHOR π
Best Practical Solutions, LLC <modules@bestpractical.com>
Original module by Leon Brocard, <acme@astray.com>
π BUGS π
ngl bestie, this section is literally empty in the original. Not me leaving it blank. π No bugs listed β make of that what you will.
π COPYRIGHT π
This extension is Copyright (C) 2015 Best Practical Solutions, LLC.
Copyright (C) 2005, Leon Brocard
This module is free software; you can redistribute it or modify it under the same terms as Perl itself. π§
And that's the whole vibe check, bestie β this page came to you from perl v5.36.0, dated 2022-11-19, and it's the Test::Expect(3pm) manpage. Go write some tests, you absolute icon. πβ¨π¦
π¦ where this page comes from
- debian bookworm: libtest-expect-perl 0.34-3 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- debian trixie: libtest-expect-perl 0.34-3 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu noble: libtest-expect-perl 0.34-3 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu resolute: libtest-expect-perl 0.34-3 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu stonking: libtest-expect-perl 0.34-3 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms