IPC::Run looks quite nice and easy. It looks like the timeout from the module handles alarm-style behavior.
Actually, IPC::Run looked so nice and easy that I tried it out. My attempts to use it pleased me, so I wrote a little wrapper to hide some of the clutter.
package Test::CLI;
use Modern::Perl;
use IPC::Run qw(run timeout);
use Test::More;
use base qw(Exporter);
our @EXPORT_OK = qw(
run_output_is
);
our $TIMEOUT = 10;
sub run_output_is {
my ($expected, $command, $input, $diagnostic) = @_;
my ($out, $err);
run $command, \$input, \$out, \$err, timeout($TIMEOUT);
is $expected, $out, $diagnostic;
}
1;
That allowed for a nice simple script in my test code.
use Modern::Perl;
use Test::CLI qw(run_output_is);
use Test::More tests => 1;
my @command = qw(parrot code/example-01-06.pir);
my $in =<<INPUT
Brian
INPUT
;
my $expected =<<EXPECTED
Please enter your name: Brian
Hello, Brian!
EXPECTED
;
run_output_is $expected, \@command, $in;
So thanks for the suggestion! That worked quite nicely for my needs.
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.