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

Does anyone know of a quick and dirty way to get the status of your tests in Test::More? The documentation suggests $Test::More::status, but remarks that this is "unimplemented". The reason I'm asking is in order to test I need to setup a number of files/database/blah objects, and then cleanup when done. I was hoping to leave around the test data if one or more of the tests failed -- for debugging purposes. The best I came up with so far was:
END { 
   my $tb = Test::More->builder;
   if ( !grep { !$_ } $tb->summary() ) {
      # do cleanup
   }
 }
Thanks

Replies are listed 'Best First'.
Re: Getting test status with Test::More
by fullermd (Vicar) on Aug 12, 2009 at 03:48 UTC

    That grep you gave should work OK.

    A possible alternative is to use an END block, and check $? in it to see if you're about to return a successful 0 (and if so clean up). That also has the advantage of catching if you somehow exit early, though it's likely that an early exit is the result of an error anyway, so it wouldn't matter.

    (n.b. I haven't tested that the END usage will actually DTRT, but it sounds like it work work)

      Thanks for the suggestion. Tried it out and unfortunately it didn't work. I suspect its in the order that the END blocks are called, as $? didn't appear to have been set yet.
        $? should be set, this come from http://perldoc.perl.org/perlmod.html:

        "Inside an END code block, $? contains the value that the program is going to pass to exit(). You can modify $? to change the exit value of the program. Beware of changing $? by accident (e.g. by running something via system)."

Re: Getting test status with Test::More
by Anonymous Monk on Aug 11, 2009 at 23:54 UTC
    make clean is for cleanup :)