Entering MooseX, Cheaper by the Dozen

A Dozen is one of those great numbers that goes way back to the Assyrian empire so today was just a little writing up what I though would be my last .t for my new MooseX and then put this project to bed by throwing it up on CPAN. I was wrong.

Well it seems I have a little bug in my .t files. I was happily doing today's .t and about half way though I ran into this

 

D:\Blogs\Moosex-AuthorizedMethodRoles\t\30-Instance.t ..
1..3
ok 1 - use MooseX::AuthorizedMethodRoles;
ok 2 - use Moose::Util;
ping instance_test_one_ofok 3 - instance_test_one_of pass
Failed 1/3 subtests

Test Summary Report
-------------------
D:\Blogs\Moosex-AuthorizedMethodRoles\t\30-Instance.t (Wstat: 0 Tests: 2 Failed: 0)
Parse errors: Bad plan. You planned 3 tests but ran 2.
Files=1, Tests=2, 0 wallclock secs ( 0.03 usr + 0.00 sys = 0.03 CPU)
Result: FAIL


Opps what is going on here this should work I haven't changed anything in my Mod and there are no syntax error in my test code. So being a good programmer reran my tests from this post and got this

 
D:\Blogs\Moosex-AuthorizedMethodRoles\t\20-Validation.t .. 
1..5
ok 1 - use MooseX::AuthorizedMethodRoles;
...
ok
All tests successful.
Files=1, Tests=5,  0 wallclock secs ( 0.03 usr +  0.00 sys =  0.03 CPU)
Result: PASS

Well alright how about the tests from this post.

 
D:\Blogs\Moosex-AuthorizedMethodRoles\t\10-API.t .. 
1..8
ok 1 - use MooseX::AuthorizedMethodRoles;
ping test_one_of_passok 2 - one_of pass
ok 3 - test_one_of_fail
ping test_required_passok 4 - test_required_pass
ok 5 - test_required_fail
ping test_required_pass_2ok 6 - test_required_pass_2
ok 7 - test_required_fail_2
ping test_allok 8 - test_all
Failed 4/8 subtests 

Test Summary Report
-------------------
D:\Blogs\Moosex-AuthorizedMethodRoles\t\10-API.t (Wstat: 0 Tests: 4 Failed: 0)
Parse errors: Tests out of sequence. Found (3) but expected (2)
Tests out of sequence. Found (5) but expected (3)
Tests out of sequence. Found (7) but expected (4)
Bad plan. You planned 8 tests but ran 4.
Files=1, Tests=4, 0 wallclock secs ( 0.03 usr + 0.00 sys = 0.03 CPU)
Result: FAIL

Opps something is amiss and then I spotted it. Seem in my little test packages I was doing this

 
{  
   package test_one_of_pass;
   use MooseX::AuthorizedMethodRoles;
   with 'test_role1';
   authorized_roles ping =>  {one_of=>['test_role1','test_role2']}, sub {
   print("ping test_one_of_pass");
};

where I really should be doing this

 

{
package test_one_of_pass;
use MooseX::AuthorizedMethodRoles;
with 'test_role1';
authorized_roles ping => {one_of=>['test_role1','test_role2']}, sub {
return "ping test_one_of_pass";
};

as the 'print' (or warn for that matter) really buggers up the TAP output and causes false fails all over the place.

Now my second test set passed because I was never invoking any of the methods that my little test packages had. Funny really I have written many thousands of test over the years and this is the first time I ran into this.

Guess I will have to go back and correct those posts.
5477138054_5a907a7eed_o.gif

2 Comments

If you want to output while testing, the right way is to use Test::More::diag, which "Prints a diagnostic message which is guaranteed not to interfere with test output."

Leave a comment

About byterock

user-pic Long time Perl guy, a few CPAN mods allot of work on DBD::Oracle and a few YAPC presentations