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
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: How to capture and verify STDOUT of a Perl Module
by yuri123 (Novice) on Jul 29, 2013 at 18:33 UTC | |
by toolic (Bishop) on Jul 29, 2013 at 18:51 UTC | |
by yuri123 (Novice) on Jul 29, 2013 at 19:27 UTC | |
by Loops (Curate) on Jul 29, 2013 at 19:31 UTC | |
by yuri123 (Novice) on Jul 29, 2013 at 19:34 UTC | |
by 2teez (Vicar) on Jul 29, 2013 at 21:20 UTC | |
by yuri123 (Novice) on Jul 30, 2013 at 19:43 UTC |