Re: Testing Output and Functionality

Eirik Berg Hanssen <[email protected]>
Newsgroups gmane.comp.lang.perl.quality-assurance
Message-ID <CAHAeAG562ArerApNYc9mUj28=U_Qdj3+sweSqKCiZHqDci29wg@mail.gmail.com>
On Tue, Apr 24, 2012 at 6:35 AM, Jed Lund <[email protected]> wrote:

> Hello,
>
> I was wondering if I could get some pointers towards a module or package
> that would allow me to test the functionality of various elements of code
> that I was developing while I also tested the STDERR and STDOUT output from
> that element of code?  I have been hunting around CPAN for the right fit
> but so far I have only found STDERR/STDOUT tests or functionality tests not
> a way to test both results from the same method call.
>

  This sounds like a job for ... Test::Trap!


The most basic case would be to test the output of a method that returned
> some defined result while also capturing any warnings prompted by malformed
> input which did not cause catastrophic failure.  The goal would be to
> certify the output and the warning message from the same method call.
>


my $result = trap { $obj->method(@args) }; # or my @results, for list
context
# Possibly:
$trap->warn_is_deeply( \@expected_warnings, "Got exactly the expected
warnings?" );
# ... but usually more usefully:
$trap->stderr_like( $pattern, "Trapped stderr matches expectations" );
# ... and you may still test $trap->stdout, $result/@result (or
$trap->return), and whatever else, from the same call.


Eirik
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.