On Tue Mar 19 08:44:08 2013, STEFFENW wrote:
Show quoted text> In a regular *.t file I can plan before the first test was executed.
Also
Show quoted text> I can plan after all tests are executed. I think after all tests that
> would be ok for you.
>
> I don't know if it's possible in your module. That was only a short
idea.
Hi Steffan,
Consider this:
sub test_this {
my $test = shift;
pass 'this test passes';
}
Due to the nature of Moose, any subclass or role can apply a method
modifier to that test:
after 'test_this' => sub {
pass 'another pass';
};
The original test method only has one test, but after the modifier, it
has two methods. However, the modifier can't know whether or not their
are other modifiers (and thus whether their are more tests). There's no
place to put a "plan", nor is there a way to modify the plan with
Test::Builder (unless you reach into the internals). When TB2 comes out,
this should be possible, but for now, it's not.
Though now that I stop to think about this, I wonder if I can safely do
this?
sub test_this {
my $test = shift;
$test->plan(1);
pass 'this test passes';
}
after 'test_this' => sub {
my $test = shift;
$test->plan(1);
pass 'another pass';
};
I *think* I can make that work without violating encapsulation. The
problem is that if a single modifier forgets a plan, or if a modifier
has a plan and the method its modifying does not, your your tests fail
due a plan mismatch. That *sounds* desirable, but what if a modifier is
in a role and one test method it modifies has a plan but another one
does not? I need to think about this some more. Maybe if modifiers are
forbidden to plan, but can call $test->add_to_plan($tests)?
Cheers,
Ovid