Eric,

I was just thinking of writing some tests for Getopt::Helpful and was wondering if something using IPC::Run might do the trick. The idea was to write a series of little programs that should behave in a given way (print something, die, or warn with a usage message) for some set of arguments and doing a string-match against their outputs.

I just have a little function for things like this:

sub test_subprogram
{
    my ($mini_prog, $action) = @_;

# make sure single quotes in our subprogram don't wack us out
$mini_prog =~ s/'/'"'"'/g; # that looks funky, but that's because shell quoting rules are funky


if (not defined $action or $action eq 'RETURN_EXIT_VALUE')
{
my $exit_val = system("perl -e '$mini_prog'");
return $exit_val == 0;
}
elsif ($action eq 'RETURN_STDOUT')


{

my $output = `perl -e '$mini_prog' 2>/dev/null`;
return $output;
}
elsif ($action eq 'RETURN_STDERR')
{
my $output = `perl -e '$mini_prog' 2>&1 1>/dev/null`;
return $output;
}
elsif ($action eq 'RETURN_STDOUT_AND_STDERR')
{
my $output = `perl -e '$mini_prog' 2>&1`;
return $output;
}
else
{
die("TestFirst::test_subprogram: don't know what action $action means");
}
}


It might be possible to do this more simply with a module, but I never really went looking for one.


-- Buddy

Reply via email to