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
    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");