Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re: How to capture and verify STDOUT of a Perl Module

by Perlbotics (Abbot)
on Jul 29, 2013 at 18:11 UTC ( #1046902=note: print w/ replies, xml ) Need Help??


in reply to How to capture and verify STDOUT of a Perl Module

Test::Output already seems to do what you want.

stdout_like( sub{ $obj->run }, qr/as expected regex/, 'output as expe +cted' );

Update (response to CR below): When capturing output from an external process, try IO::CaptureOutput:

use strict; use warnings; use Test::More; use Test::Output; use IO::CaptureOutput qw(capture); sub writer { system("echo Hubba") }; #fails: stdout_like( \&writer, qr/Hubba/ms, "it's a hubba" ); capture { writer() } \my $stdout, \my $stderr; is( $stdout, "Hubba\n", "system hubba" ); done_testing; #-- output: # # ok 1 - system hubba # 1..1


Comment on Re: How to capture and verify STDOUT of a Perl Module
Select or Download Code
Re^2: How to capture and verify STDOUT of a Perl Module
by yuri123 (Novice) on Jul 29, 2013 at 18:33 UTC
    I tried Test::Output. It looks like it did not capture the output from a system() that Module issues.
      it did not capture the output from a system()
      system does not return a command's output (only its exit status). Perhaps you want qx.
        I know, but if system() runs something that produces output, I want it captured and can't:
        system("/bin/echo HELLO");

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1046902]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (5)
As of 2014-08-21 04:48 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (127 votes), past polls