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

Hi all,

I'm looking for techniques to provide debug output from a TODO test running with Test::More.

What I want to do is output an additional message when a TODO test starts passing, to remind me to take some action. I can get the message to print with diag() when running in verbose mode, but not otherwise.

use Test::More tests => 2; TODO: { local $TODO = ' '; is(1,1,'Inside') and diag 'In'; } is(1,1,'Outside') and diag 'Out';
Output under verbose:
$ prove -lrv foo.t foo.t .. 1..2 ok 1 - Inside # TODO # In ok 2 - Outside # Out ok All tests successful. Test Summary Report ------------------- foo.t (Wstat: 0 Tests: 2 Failed: 0) TODO passed: 1 Files=1, Tests=2, 0 wallclock secs ( 0.02 usr 0.00 sys + 0.01 cusr + 0.00 csys = 0.03 CPU) Result: PASS
Output without verbose:
$ prove -lr foo.t foo.t .. 1/2 # Out foo.t .. ok All tests successful. Test Summary Report ------------------- foo.t (Wstat: 0 Tests: 2 Failed: 0) TODO passed: 1 Files=1, Tests=2, 0 wallclock secs ( 0.02 usr 0.00 sys + 0.02 cusr + 0.00 csys = 0.04 CPU) Result: PASS
I know that Test::More clones STDOUT and STDERR and other black magic ... but is there any way to accomplish what I want?

Thanks in advance!

Note:


The way forward always starts with a minimal test.

Replies are listed 'Best First'.
Re: debug output from TODO with Test::More
by stevieb (Canon) on Jan 13, 2017 at 15:04 UTC

    If I understand what you're trying to achieve, warn() seems to do the trick:

    use warnings; use strict; use Test::More; TODO: { local $TODO = ''; is (1, 1, 'inside') and warn "*** unexpected pass at line " . __LINE__ ."\n"; } done_testing();

    Output:

    ok 1 - inside *** unexpected pass at line 9 1..1

      Well, I'll be a ding-dong-dang.

      I had tested with print, but not warn. Thanks, couldn't ask for a better answer !


      The way forward always starts with a minimal test.

        I've done things like this before for nearly the same reason, but I added a $SIG{__WARN__} handler to filter these warnings out, and dump them all to a file so I could review them all in one place instead of scouring through hundreds of lines of test output.

Re: debug output from TODO with Test::More
by haukex (Archbishop) on Jan 13, 2017 at 17:07 UTC

    Hi 1nickt,

    As far as I can tell from the Test::Builder doc, the output of diag is directed to a special handle during TODO tests. Apparently I can force that output to be displayed with Test::More->builder->todo_output(\*STDERR);. However, I don't find that very elegant since it does this unconditionally. (Update: Probably better: Test::More->builder->todo_output(Test::More->builder->failure_output);)

    I played around with it a bit, here's a possibility to display a list of unexpectedly passing TODO tests without having to add a diag statement to every one of them. Stick this at the bottom of your test script (Perl v5.12 required for each @ARRAY):

    my @details = Test::More->builder->details; while (my ($i,$t) = each @details) { next unless $$t{type} eq 'todo' && $$t{actual_ok}; diag "Passing TODO Test #".($i+1)." / $$t{name}"; }

    (As you probably already know, there's also the "TODO passed" output that's already part of the "Test Summary Report". As far as I can tell from a look at the source, that's generated by TAP::Formatter::Base based on TAP::Parser's todo_passed.)

    Hope this helps,
    -- Hauke D

      Why do code all those lines when you can use SKIP? The reason can say "TODO" :-)

        Hi Anonymous,

        Why do code all those lines when you can use SKIP?

        Well first of all, because I was answering 1nickt's question, which is about TODO tests :-P

        Second, SKIP is not the same as TODO. SKIP doesn't run the test at all, whereas TODO runs it, but expects a failure, and reports when the test starts passing. If you use SKIP instead of TODO, you won't automatically get the information about tests that start passing.

        Regards,
        -- Hauke D

Re: debug output from TODO with Test::More
by Anonymous Monk on Jan 13, 2017 at 16:29 UTC
    If you want to see those tests naturally reflected in the output, use SKIP not TODO.

      Hi,

      If you want to see those tests naturally reflected in the output, use SKIP not TODO.

      Did you test before posting? Take 1nickt's code, change the TODO to SKIP, and you'll see that the output of prove doesn't mention the skipped tests at all! Under prove -v, the only difference is that the test will say "ok 1 # skip some reason" instead of "ok 1 - Inside # TODO", so no real difference there either. And as I mention here, SKIP will also not report when the test starts passing.

      Sorry, but this is not a solution to 1nickt's question, "What I want to do is output an additional message when a TODO test starts passing".

      Regards,
      -- Hauke D

        "Sorry, but this is not a solution to 1nickt's question"

        That's right. His question is not valid.