Skip Menu |

Preferred bug tracker

Please visit the preferred bug tracker to report your issue.

This queue is for tickets about the Test-Class-Moose CPAN distribution.

Report information
The Basics
Id: 84046
Status: resolved
Priority: 0/
Queue: Test-Class-Moose

People
Owner: Nobody in particular
Requestors: STEFFENW [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: 0.06
Fixed in: (no value)



Subject: "done_testing" is not a replacement for "plan".
If you have tests in a callback sub you don't know if the sub is called and all is ok or the sub is not called and it looks like ok only. Removing "plan" looks clever but it is not. Watch https://metacpan.org/module/Test::Class how to plan in a method. --Steffen
On Tue Mar 19 04:53:53 2013, STEFFENW wrote: Show quoted text
> If you have tests in a callback sub you don't know if the sub is
called Show quoted text
> and all is ok or the sub is not called and it looks like ok only. > Removing "plan" looks clever but it is not. > > Watch https://metacpan.org/module/Test::Class how to plan in a method. > > --Steffen
I'm familiar with how plans are declared in methods in Test::Class. However, Test::Class::Moose doesn't have plans in test methods because any method modifier can alter the number of tests in a method (http://blogs.perl.org/users/ovid/2013/03/using-roles-with- testclassmoose.html) and the Test::Builder public API has no way of altering a plan once declared. With the release of Test::Builder2, this limitation should be easier to fix. In the meantime, if you have a suggestion on how to deal with this, I'm happy to hear it. Cheers, Ovid
In a regular *.t file I can plan before the first test was executed. Also 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.
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
Hi Steffan, The latest Test::Class::Moose on github (https://github.com/Ovid/test-class-moose) implements test plans for methods. In a test method, you do this: sub test_something { my ( $test, $report ) = @_; $report->plan($num_tests); ... } However, you cannot plan twice, so if a method modifier is applied to the test method, you must call add_to_plan(): after 'test_something' => sub { my ( $test, $report ) = @_; $report->add_to_plan($num_extra_tests); ... }; Plans are still optional for test methods. Does that look OK? Cheers, Ovid
:-) great, plan is possible! I saw your code on https://github.com/Ovid/test-class-moose/blob/master/lib/Test/Class/Moose.pm and I can say: You write a very good structured code, very good readable. Congratulations! Steffen.
This is fixed as of the 0.07 release. Thanks for the report and getting me to think about this. Cheers, Ovid