Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Sending module output to STDOUT in test

by loris (Hermit)
on Aug 28, 2014 at 12:21 UTC ( [id://1098859]=perlquestion: print w/replies, xml ) Need Help??

loris has asked for the wisdom of the Perl Monks concerning the following question:

Dear Monks,

I have a test using Test::More which is failing. I would like to debug the relevant subroutine in my module by inserting a print to see what is going on.

How do can I see the output when I run the test with, say, prove?

Thanks,

loris

Replies are listed 'Best First'.
Re: Sending module output to STDOUT in test
by choroba (Cardinal) on Aug 28, 2014 at 12:27 UTC
    When running tests, standard output is used to communicate the test results. You can still use the standard error:
    print STDERR "You can see this in prove\n";

    Or, don't run your test through prove, but run it directly.

    t/01-basic.t

    Standard output is not captured in this case.

    لսႽ† ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ
Re: Sending module output to STDOUT in test
by Solo (Deacon) on Aug 28, 2014 at 13:24 UTC

    If you're willing to use STDERR, you'd just need to prove --merge ...

    If you really want to send to STDOUT instead of STDERR, you could use something like Test::Trap to capture STDOUT to send to diag().

    use Test::More; use Test::Trap; my @r = trap { some_code(@some_parameters) }; diag($trap->stdout);
Re: Sending module output to STDOUT in test
by neilwatson (Priest) on Aug 28, 2014 at 13:16 UTC

    Try warn instead of print. It's like print STDERR, but prettier and more succinct. You don't want to use STDOUT.

    warn "Something went wrong.";

    Neil Watson
    watson-wilson.ca

Re: Sending module output to STDOUT in test
by salva (Canon) on Aug 28, 2014 at 12:47 UTC
    Also, Test::More provides a diag sub just for that.
      Yes, but... you can use diag in the test file, but not in the library the test file is testing.
      لսႽ† ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ
Re: Sending module output to STDOUT in test
by tangent (Parson) on Aug 28, 2014 at 15:10 UTC

      Good point. Actually my newer modules all do use Log::Log4Perl, but I happened to have to tweak an old one and was to lazy to set logging up.

      Cheers,

      loris

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://1098859]
Approved by ww
Front-paged by toolic
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others taking refuge in the Monastery: (4)
As of 2026-02-08 23:50 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?
    hippoepoptai's answer Re: how do I set a cookie and redirect was blessed by hippo!
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.