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