On Wed, 2004-04-28 at 09:33, Dan Sugalski wrote:

> Cool. If they do work, could you fire a quick note on how to the 
> list, so I don't forget again?

Alright, here's a TODO test:

        use Parrot::Test tests => 2;
        use Test::More;

        TODO:
        {
            local $TODO = 'Not implemented yet';
            ok( 0,    'Sufficiently large values of zero are true' );
            is( 1, 2, 'Sufficiently large values of one are two'   );
        }

Since Parrot::Test doesn't export TODO or $TODO, you have to use
Test::More.  Once you've done that, create a new block labelled TODO to
contain all of the tests that may fail.  Localize the global $TODO with
the reason you want to display and write your tests as normal.

If you run this file directly, you'll see the failures with the $TODO
reason in the test comment:

$ perl -Ilib t/todo_example.t

not ok 1 - Sufficiently large values of zero are true # TODO Not
implemented yet
#     Failed (TODO) test (t/example.t at line 9)
not ok 2 - Sufficiently large values of one are two # TODO Not
implemented yet
#     Failed (TODO) test (t/example.t at line 10)
#          got: '1'
#     expected: '2'

If you run this through Test::Harness, it'll pick up on the # TODO
comments and report that the tests succeeded.  (Hey, they failed, but
you expected them to fail, so everything is okay.)

$ perl t/harness t/todo_example.t
t/example....ok                                                              
All tests successful.
Files=1, Tests=2,  0 wallclock secs ( 0.08 cusr +  0.00 csys =  0.08
CPU)

If for some reason one of the tests suddenly starts to succeed, you'll
see a different message from the harness:

$ perl t/harness t/example.t 
t/example....ok                                                              
        1/2 unexpectedly succeeded
All tests successful (1 subtest UNEXPECTEDLY SUCCEEDED).
Files=1, Tests=2,  0 wallclock secs ( 0.07 cusr +  0.01 csys =  0.08
CPU)

Leo wants the harness to report TODO tests that fail as expected; that's
a little more complex, but it's doable.

-- c

Reply via email to