Ovid wrote:
Just to let folks know, at the Perl-QA Hackathon, I've implemented nested TAP 
in Test::Builder.

        Ooooh.... This calls for a spontaneous dance of joy!


A few months ago, I hacked Test::Class so that it uses Test::Group to aggregate the subtests of each test. Changing the hack to use the new subtest() is fairly trivial:

$ cat test-nested.pl
#!/usr/bin/perl

package MyTests;

use strict;
use warnings;

use base 'Test::Class::Nested';
use Test::More;

sub failingTest :Test {
    ok 1 for 1..2;
}

sub passingTest :Tests(2) {
    ok 1 for 1..2;
}

sub failingTest2 :Tests(2) {
    ok 0;
    ok 1;
}

__PACKAGE__->runtests;

$ perl test-nested.pl
1..3
    1..2
    not ok 1 - FailingTest2
    #   Failed test 'FailingTest2'
    #   at test-nested.pl line 20.
#   (in MyTests->FailingTest2)
    ok 2 - FailingTest2
    # Looks like you failed 1 test of 2.
not ok 1 - MyTests::FailingTest2
#   Failed test 'MyTests::FailingTest2'
#   at ../test-more/lib/Test/More.pm line 717.
#   (in MyTests->FailingTest2)
    1..1
    ok 1 - failingTest
    ok 2 - failingTest
    # Looks like you planned 1 test but ran 2.
not ok 2 - MyTests::failingTest
#   Failed test 'MyTests::failingTest'
#   at ../test-more/lib/Test/More.pm line 717.
#   (in MyTests->failingTest)
    1..2
    ok 1 - passingTest
    ok 2 - passingTest
ok 3 - MyTests::passingTest
# Looks like you failed 2 tests of 3.


        If anyone's interested, the code is on Github:
http://github.com/yanick/test-class/tree/nested (the hack is encapsulated in lib/Test/Class/Nested.pm). Caveat emptor:
this is code typed on a Sunday morning right after breakfast
on a jetlagged brain, so take it all with a shovelfull of salt.


Joy,
`/anick

Reply via email to