Ovid wrote:
> ----- Original Message ----
> 
>> From: David E. Wheeler <da...@kineticode.com>
>> To: Ovid <publiustemp-perl...@yahoo.com>
>> Cc: perl-qa@perl.org
>> Sent: Monday, 29 June, 2009 17:38:15
>> Subject: Re: Subtest fail with singletons
>>
>> On Jun 29, 2009, at 2:19 AM, Ovid wrote:
>>
>>>    my $Test = Test::Builder->new;
>>>
>>> If every test function simply had that line in the function, rather than 
>> trying to share this across all test functions, the code would work fine.
>>> Not sure of the best way of handling this, but it's annoying as heck :(
>> Submit a bug report for Test::XML and Test::JSON with a test case 
>> demonstrating 
>> the issue?
> 
> And Test::Exception and many, many other Test:: modules.  It's a very common
> pattern and getting all authors to agree to fix those modules is a dubious
> strategy, I think.

Having one global singleton was the original way to do it.  Along the way the
recommended way of doing it was changed to getting a new builder per test
method invocation.

    sub ok($;$) {
        my $tb = __PACKAGE__->builder;
        return $tb->ok(@_);
    }

That was never enforced.  The change was because at some point each module is
going to get their own builder object, possibly each method, and there won't
be a single singleton any more.  But that's been pushed off into TB2.

So there's nothing wrong with what test modules are doing right now.  And
you're pretty much going to have to change the overwhelming majority of them.
 This is ++ungood.

A simple strategy might be to just replace the global singleton with the
child's guts at the start of a subtest() and then back out again at the end.

    %$Test = %$child;

Watch out for edge cases of when subtest() dies, make sure the parent's guts
get put back.

Ovid, you get to figure it out. :)


-- 
We do what we must because we can.
For the good of all of us,
Except the ones who are dead.
    -- Jonathan Coulton, "Still Alive"

Reply via email to