Test-Expect-0.34000755000765000024 013053110311 13342 5ustar00sartakstaff000000000000Test-Expect-0.34/Build.PL000444000765000024 66013053110311 14755 0ustar00sartakstaff000000000000use 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', }, test_requires => { 'Test::Builder' => '0', 'Test::More' => '0', 'Term::ReadLine' => '0', }, ); $build->create_build_script; Test-Expect-0.34/CHANGES000444000765000024 124013053110311 14467 0ustar00sartakstaff000000000000Revision history for Perl module Test::Expect 0.33 2015-04-02 - Allow multi-argument forms of "command" to be passed - Force Term::ReadLine in called programs to use the "Stub" implementation, which has consistent output (vs Term::ReadLine::Perl) 0.32 2015-04-02 - Quote regex meta-characters before using them in a regex (fixes #81987) - Include leading space in PERL_RL variable (fixes #38914) - New maintainer (BPS) 0.31 2008-05-07 - add expect_quit method to close the Expect object (patch by Alex Vandiver) 0.30 2006-02-28 - added expect_handle to fetch the underlying Expect object (patch by Kevin Riggle) 0.29 2005-03-30 - initial release Test-Expect-0.34/Makefile.PL000444000765000024 62113053110311 15430 0ustar00sartakstaff000000000000# Note: this file was auto-generated by Module::Build::Compat version 0.4218 use ExtUtils::MakeMaker; WriteMakefile ( 'NAME' => 'Test::Expect', 'VERSION_FROM' => 'lib/Test/Expect.pm', 'PREREQ_PM' => { 'Class::Accessor::Chained::Fast' => '0', 'Expect::Simple' => '0' }, 'INSTALLDIRS' => 'site', 'EXE_FILES' => [], 'PL_FILES' => {} ) ; Test-Expect-0.34/MANIFEST000444000765000024 20113053110311 14601 0ustar00sartakstaff000000000000Build.PL CHANGES lib/Test/Expect.pm Makefile.PL MANIFEST This list of files read readline README t/simple.t META.yml META.json Test-Expect-0.34/META.json000444000765000024 236513053110311 15126 0ustar00sartakstaff000000000000{ "abstract" : "Automated driving and testing of terminal-based programs", "author" : [ "Best Practical Solutions, LLC Emodules@bestpractical.comE", "Original module by Leon Brocard, Eacme@astray.comE" ], "dynamic_config" : 1, "generated_by" : "Module::Build version 0.4218", "license" : [ "perl_5" ], "meta-spec" : { "url" : "http://search.cpan.org/perldoc?CPAN::Meta::Spec", "version" : "2" }, "name" : "Test-Expect", "prereqs" : { "configure" : { "requires" : { "Module::Build" : "0.42" } }, "runtime" : { "requires" : { "Class::Accessor::Chained::Fast" : "0", "Expect::Simple" : "0" } }, "test" : { "requires" : { "Term::ReadLine" : "0", "Test::Builder" : "0", "Test::More" : "0" } } }, "provides" : { "Test::Expect" : { "file" : "lib/Test/Expect.pm", "version" : "0.34" } }, "release_status" : "stable", "resources" : { "license" : [ "http://dev.perl.org/licenses/" ] }, "version" : "0.34", "x_serialization_backend" : "JSON::PP version 2.27400" } Test-Expect-0.34/META.yml000444000765000024 150413053110311 14750 0ustar00sartakstaff000000000000--- abstract: 'Automated driving and testing of terminal-based programs' author: - 'Best Practical Solutions, LLC Emodules@bestpractical.comE' - 'Original module by Leon Brocard, Eacme@astray.comE' build_requires: Term::ReadLine: '0' Test::Builder: '0' Test::More: '0' configure_requires: Module::Build: '0.42' dynamic_config: 1 generated_by: 'Module::Build version 0.4218, CPAN::Meta::Converter version 2.150005' license: perl meta-spec: url: http://module-build.sourceforge.net/META-spec-v1.4.html version: '1.4' name: Test-Expect provides: Test::Expect: file: lib/Test/Expect.pm version: '0.34' requires: Class::Accessor::Chained::Fast: '0' Expect::Simple: '0' resources: license: http://dev.perl.org/licenses/ version: '0.34' x_serialization_backend: 'CPAN::Meta::YAML version 0.018' Test-Expect-0.34/read000444000765000024 42513053110311 14316 0ustar00sartakstaff000000000000#!perl use strict; use warnings; $| = 1; my $what = (shift @ARGV) || "there"; print "* Hi $what, to read\n"; while (1) { print "read: "; my $command = <>; chomp $command; if ($command eq 'ping') { print "pong\n"; } elsif ($command eq 'quit') { exit; } } Test-Expect-0.34/readline000444000765000024 51113053110311 15162 0ustar00sartakstaff000000000000#!perl use strict; use warnings; use Term::ReadLine; my $what = (shift @ARGV) || "there"; print "* Hi $what, 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.34/README000444000765000024 430313053110311 14357 0ustar00sartakstaff000000000000NAME 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.34/lib000755000765000024 013053110311 14110 5ustar00sartakstaff000000000000Test-Expect-0.34/lib/Test000755000765000024 013053110311 15027 5ustar00sartakstaff000000000000Test-Expect-0.34/lib/Test/Expect.pm000444000765000024 1137213053110311 16776 0ustar00sartakstaff000000000000package 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.34"; 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) = @_; local $ENV{PERL_RL} = "Stub o=0"; $expect = Expect::Simple->new( { Cmd => $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/^\Q$sent\E// 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', ); The C may either be a string, or an arrayref of program and arguments; the latter for bypasses the shell. =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. =head2 expect_quit Closes the L handle. =head1 SEE ALSO L, L. =head1 AUTHOR Best Practical Solutions, LLC Emodules@bestpractical.comE Original module by Leon Brocard, Eacme@astray.comE =head1 BUGS =for html

All bugs should be reported via email to bug-Test-Expect@rt.cpan.org or via the web at rt.cpan.org.

=for text All bugs should be reported via email to bug-Test-Expect@rt.cpan.org or via the web at http://rt.cpan.org/Public/Dist/Display.html?Name=Test-Expect =head1 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. =cut Test-Expect-0.34/t000755000765000024 013053110311 13605 5ustar00sartakstaff000000000000Test-Expect-0.34/t/simple.t000444000765000024 114713053110311 15423 0ustar00sartakstaff000000000000#!perl use strict; use warnings; use lib 'lib'; use Test::Expect; use Test::More tests => 20; require_ok('Expect'); ok(1, "True"); foreach my $filename ('read', 'readline') { ok($filename, "Testing $filename"); expect_run( command => [$^X, $filename, "world"], prompt => $filename . ': ', quit => 'quit', ); isa_ok(expect_handle(), 'Expect'); expect_like(qr/Hi world, to $filename/, "expect_like"); expect_is("* Hi world, to $filename", "expect_is"); expect_send("ping", "expect_send"); expect_is("pong", "expect_is receiving expect_send"); expect("ping", "pong", "expect"); };