Test-Expect-0.31/0000755000175000017500000000000011010272035012165 5ustar acmeacmeTest-Expect-0.31/lib/0000755000175000017500000000000011010272035012733 5ustar acmeacmeTest-Expect-0.31/lib/Test/0000755000175000017500000000000011010272035013652 5ustar acmeacmeTest-Expect-0.31/lib/Test/Expect.pm0000444000175000017500000001001611010272035015434 0ustar acmeacmepackage Test::Expect; use strict; use warnings; use Class::Accessor::Chained::Fast; use Expect::Simple; use Exporter; use Test::Builder; use base qw(Class::Accessor::Chained::Fast Exporter); __PACKAGE__->mk_accessors(qw(program)); our $VERSION = "0.31"; our @EXPORT = qw( expect_run expect_handle expect_is expect_like expect_send expect_quit expect END ); my $Test = Test::Builder->new; my $expect; my $sent; sub import { my $self = shift; if (@_) { die @_; my $package = caller; $Test->exported_to($package); $Test->plan(@_); } $Test->no_ending(0); $self->export_to_level( 1, $self, $_ ) foreach @EXPORT; } sub expect_run { my (%conf) = @_; $expect = Expect::Simple->new( { Cmd => "PERL_RL=\"o=0\" " . $conf{command}, Prompt => $conf{prompt}, DisconnectCmd => $conf{quit}, Verbose => 0, Debug => 0, Timeout => 100 } ); die $expect->error if $expect->error; $Test->ok( 1, "expect_run" ); } sub expect_handle { return $expect->expect_handle(); } sub before { my $before = $expect->before; $before =~ s/\r//g; $before =~ s/^$sent// if $sent; $before =~ s/^\n+//; $before =~ s/\n+$//; return $before; } sub expect_like { my ( $like, $comment ) = @_; $Test->like( before(), $like, $comment ); } sub expect_is { my ( $is, $comment ) = @_; $Test->is_eq( before(), $is, $comment ); } sub expect_send { my ( $send, $comment ) = @_; $expect->send($send); $sent = $send; $Test->ok( 1, $comment ); } sub expect { my ( $send, $is, $label ) = @_; expect_send( $send, $label ); expect_is( $is, $label ); } sub expect_quit { undef $expect; } sub END { expect_quit; } 1; __END__ =head1 NAME Test::Expect - Automated driving and testing of terminal-based programs =head1 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"); =head1 DESCRIPTION L 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 L, the L object is made available for tweaking. L is intended for use in a test script. =head1 SUBROUTINES =head2 expect_run The expect_run subroutine sets up L. 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', ); =head2 expect 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"); =head2 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"); =head2 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"); =head2 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"); =head2 expect_handle This returns the L object. =head1 expect_quit Closes the L handle. =head1 SEE ALSO L, L. =head1 AUTHOR Leon Brocard, C<< >> =head1 COPYRIGHT Copyright (C) 2005, Leon Brocard This module is free software; you can redistribute it or modify it under the same terms as Perl itself. Test-Expect-0.31/MANIFEST0000444000175000017500000000016711010272035013320 0ustar acmeacmeBuild.PL CHANGES lib/Test/Expect.pm Makefile.PL MANIFEST This list of files META.yml read readline README t/simple.t Test-Expect-0.31/Build.PL0000444000175000017500000000062111010272035013456 0ustar acmeacmeuse Module::Build; use strict; my $build = Module::Build->new( create_makefile_pl => 'traditional', license => 'perl', module_name => 'Test::Expect', requires => { 'Class::Accessor::Chained::Fast' => '0', 'Expect::Simple' => '0', 'Term::ReadLine' => '0', 'Test::Builder' => '0', 'Test::More' => '0', }, ); $build->create_build_script; Test-Expect-0.31/t/0000755000175000017500000000000011010272035012430 5ustar acmeacmeTest-Expect-0.31/t/simple.t0000444000175000017500000000104511010272035014104 0ustar acmeacme#!perl use strict; use warnings; use lib 'lib'; use Test::Expect; use Test::More tests => 18; require_ok('Expect'); ok(1, "True"); foreach my $filename ('read', 'readline') { ok($filename, "Testing $filename"); expect_run( command => "$^X $filename", prompt => $filename . ': ', quit => 'quit', ); isa_ok(expect_handle(), 'Expect'); expect_like(qr/Hi there, to $filename/, "expect_like"); expect_is("* Hi there, to $filename", "expect_is"); expect_send("ping", "expect_send"); expect("ping", "pong", "expect"); }; Test-Expect-0.31/README0000444000175000017500000000430311010272035013043 0ustar acmeacmeNAME Test::Expect - Automated driving and testing of terminal-based programs 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 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. 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', ); expect 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"); 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. SEE ALSO Expect, Expect::Simple. AUTHOR Leon Brocard, "" COPYRIGHT Copyright (C) 2005, Leon Brocard This module is free software; you can redistribute it or modify it under the same terms as Perl itself. Test-Expect-0.31/CHANGES0000444000175000017500000000054611010272035013163 0ustar acmeacmeRevision history for Perl module Devel::ebug 0.31 Wed May 7 10:15:19 BST 2008 - add expect_quit method to close the Expect object (patch by Alex Vandiver) 0.30 Tue Feb 28 21:54:16 GMT 2006 - added expect_handle to fetch the underlying Expect object (patch by Kevin Riggle) 0.29 Wed Mar 30 23:18:02 CST 2005 - initial release Test-Expect-0.31/META.yml0000444000175000017500000000104611010272035013435 0ustar acmeacme--- name: Test-Expect version: 0.31 author: - 'Leon Brocard, C<< >>' abstract: Automated driving and testing of terminal-based programs license: perl resources: license: http://dev.perl.org/licenses/ requires: Class::Accessor::Chained::Fast: 0 Expect::Simple: 0 Term::ReadLine: 0 Test::Builder: 0 Test::More: 0 provides: Test::Expect: file: lib/Test/Expect.pm version: 0.31 generated_by: Module::Build version 0.280801 meta-spec: url: http://module-build.sourceforge.net/META-spec-v1.2.html version: 1.2 Test-Expect-0.31/Makefile.PL0000444000175000017500000000117311010272035014137 0ustar acmeacme# Note: this file was auto-generated by Module::Build::Compat version 0.2808_01 use ExtUtils::MakeMaker; WriteMakefile ( 'PL_FILES' => {}, 'INSTALLDIRS' => 'site', 'NAME' => 'Test::Expect', 'EXE_FILES' => [], 'VERSION_FROM' => 'lib/Test/Expect.pm', 'PREREQ_PM' => { 'Test::More' => '0', 'Class::Accessor::Chained::Fast' => '0', 'Term::ReadLine' => '0', 'Test::Builder' => '0', 'Expect::Simple' => '0' } ) ; Test-Expect-0.31/readline0000444000175000017500000000044411010272035013673 0ustar acmeacme#!perl use strict; use warnings; use Term::ReadLine; print "* Hi there, to readline\n"; my $term = Term::ReadLine->new('readline'); while (1) { my $command = $term->readline("readline: "); if ($command eq 'ping') { print "pong\n"; } elsif ($command eq 'quit') { exit; } } Test-Expect-0.31/read0000444000175000017500000000036011010272035013020 0ustar acmeacme#!perl use strict; use warnings; $| = 1; print "* Hi there, to read\n"; while (1) { print "read: "; my $command = <>; chomp $command; if ($command eq 'ping') { print "pong\n"; } elsif ($command eq 'quit') { exit; } }