Is there any good way to temporarily suspend or, even better, take
control of a Test::Builder testing session?

The reason I ask is because I am working on a specification-based
testing system for Perl that utilizes random-testing methods in which
a single property check can involve thousands of random test cases.
It would be great if testers could take advantage of Test::More
and other Test::Builder-based testing modules in their property
declarations, but right now that is tricky.

The problem is that when somebody uses a function such as like() or
is_deeply() within a property, it ends up getting called thousands of
times when the property is checked.  Test::Builder naturally thinks
each one of these calls represents a complete test case, and it
generates thousands of "ok" outputs and so on.  Oops.

What I want is for each property check to be seen as a single test.

How I do do this now is somewhat hackish.  For the duration of a
property check, I redefine some Test::Builder internals like so:

sub check_property {
    no warnings 'redefine';
    my $property = shift;
    my $diags = [];
    local *Test::Builder::ok   = sub { $_[1] ? 1 : 0 };
    local *Test::Builder::diag = sub { shift; push @$diags, @_; 0 };
    return ( $diags,
             Test::LectroTest::TestRunner->new(@_)->run($property) );
}

The idea is to sever the part of Test::Builder that reports back to
the caller (which I want) from the part that reports back to the test
harness (which I do not want).  It seems to work fine, but mucking
around with another module's internals carries with it an element of
risk that I don't like, and I would rather have a cleaner option.

Is there a cleaner option?  If not, can/should we create one?

Cheers,
Tom


For more background, see the following:

http://community.moertel.com/LectroTest
http://search.cpan.org/dist/Test-LectroTest/lib/Test/LectroTest/Compat.pm

Reply via email to