GSP
Quick Navigator

Search Site

Unix VPS
A - Starter
B - Basic
C - Preferred
D - Commercial
MPS - Dedicated
Previous VPSs
* Sign Up! *

Support
Contact Us
Online Help
Handbooks
Domain Status
Man Pages

FAQ
Virtual Servers
Pricing
Billing
Technical

Network
Facilities
Connectivity
Topology Map

Miscellaneous
Server Agreement
Year 2038
Credits
 

USA Flag

 

 

Man Pages
Test::Expect(3) User Contributed Perl Documentation Test::Expect(3)

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

  # 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");

Test::Expect is a module for automated driving and testing of terminal-based programs. It is handy for testing interactive programs which have a prompt, and is based on the same concepts as the Tcl Expect tool. As in Expect::Simple, the Expect object is made available for tweaking.

Test::Expect is intended for use in a test script.

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.

The expect subroutine is the catch all subroutine. You pass in the command, the expected output of the subroutine and an optional comment.

  expect("ping", "pong", "expect");

The expect_send subroutine sends a command to the program. You pass in the command and an optional comment.

  expect_send("ping", "expect_send");

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");

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");

This returns the Expect object.

Closes the Expect handle.

Expect, Expect::Simple.

Best Practical Solutions, LLC <modules@bestpractical.com>

Original module by Leon Brocard, <acme@astray.com>

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.

2017-02-21 perl v5.32.1

Search for    or go to Top of page |  Section 3 |  Main Index

Powered by GSP Visit the GSP FreeBSD Man Page Interface.
Output converted with ManDoc.