Re: Testing Output and Functionality
Eirik, Thank you for the suggestion. I had not seen Test::Trap in my searches so I will investigate. Best Regards, Jed On Mon, Apr 23, 2012 at 11:44 PM, Eirik Berg Hanssen < eirik-berg.hans...@allverden.no> wrote: > On Tue, Apr 24, 2012 at 6:35 AM, Jed Lund 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 >
Re: Testing Output and Functionality
David, Thank you for your suggestion. I haven't gone down that road yet so I will try it. Best Regards, Jed On Tue, Apr 24, 2012 at 4:07 AM, David Golden wrote: > On Tue, Apr 24, 2012 at 12:35 AM, Jed Lund wrote: > > I understand that this is a fairly basic question but I am stuck trying > to > > find the right path forward. > > It's not entirely basic, because you're testing an array of three > "outputs" for each functionality test instead of just one. > > I'd probably use Capture::Tiny: > >use Capture::Tiny qw/capture/; > >my ($out, $err, $result) = capture { your_code_here }; ># then test $out, $err, $result however you want > > If that's repetitive, stick it in a loop or write a function to > abstract testing the three results against your expectations. > > -- David >
Re: Testing Output and Functionality
On Tue, Apr 24, 2012 at 12:35 AM, Jed Lund wrote: > I understand that this is a fairly basic question but I am stuck trying to > find the right path forward. It's not entirely basic, because you're testing an array of three "outputs" for each functionality test instead of just one. I'd probably use Capture::Tiny: use Capture::Tiny qw/capture/; my ($out, $err, $result) = capture { your_code_here }; # then test $out, $err, $result however you want If that's repetitive, stick it in a loop or write a function to abstract testing the three results against your expectations. -- David
Re: Testing Output and Functionality
On Tue, Apr 24, 2012 at 6:35 AM, Jed Lund 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
Re: Testing Output and Functionality
Andy, Thank you for the reply. I did try Test::Output but I ran into a Smart::Comments incompatibility. This is a sort of corner case to the issue I described where I am trying to print the Smart::Comments but capture the STDOUT output for testing. When I run the following; use Test::Most; use Test::Output; use Smart::Comments '###'; stdout_is( sub{ print "Hello World\n"; ### Goodby World ... }, "Hello World\n", 'Test Hello World' ); done_testing(); I get the following error; Can't locate object method "TELL" via package "Test::Output::Tie" at C:/Perl/site/lib/Smart/Comments.pm line 438. While a warn or carp statement in the same place seems to work just fine the Smart::Comments don't. I kind of walked away at that point and started looking somewhere else. Should I just be more persistent to fix this issue or is there another solution? Best Regards, Jed On Mon, Apr 23, 2012 at 9:53 PM, Andy Lester wrote: > > On Apr 23, 2012, at 11:35 PM, Jed Lund wrote: > > 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. > > > Sounds like you're looking for Test::Output. > > http://search.cpan.org/dist/Test-Output/ > > xoxo, > Andy > > -- > Andy Lester => a...@petdance.com => www.petdance.com => AIM:petdance > >
Re: Testing Output and Functionality
On Apr 23, 2012, at 11:35 PM, Jed Lund wrote: > 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. Sounds like you're looking for Test::Output. http://search.cpan.org/dist/Test-Output/ xoxo, Andy -- Andy Lester => a...@petdance.com => www.petdance.com => AIM:petdance