Skip Menu |

Preferred bug tracker

Please visit the preferred bug tracker to report your issue.

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

Report information
The Basics
Id: 27498
Status: new
Priority: 0/
Queue: Test-Base

People
Owner: Nobody in particular
Requestors: a.r.ferreira [...] gmail.com
Cc:
AdminCc:

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



Subject: [PATCH] improve cooperation with other test modules
Date: Fri, 8 Jun 2007 10:05:00 -0300
To: "Ingy döt Net" <ingy [...] cpan.org>, bug-Test-Base [...] rt.cpan.org
From: "Adriano Ferreira" <a.r.ferreira [...] gmail.com>
The attached patch is intented to improve the cooperation of Test::Base and other test modules, like Test::More itself. Even though Test::Base provides most (if not all) the functionality of Test::More, 0.53 does not allow writing some natural testing code without seeing some booms. For instance, use Test::More tests => 2; use Test::Base; pass; run_compare; __END__ === one --- foo 1 --- bar 1 crashes with the following messages $ perl ../t.pl 1..2 ok 1 You tried to plan twice at /usr/local/lib/perl5/site_perl/5.8.8/Test/Base.pm line 282. # Looks like you planned 2 tests but only ran 1. This is caused by the wrapper around Test::Builder::plan and the reliance on the lexical variable $Have_Plan. Note that, for the same reason, the former is alright if we change the order of the use statements: use Test::Base; use Test::More tests => 2; The patch replaces one sin (wrapping Test::Builder::plan without concern for the order it got used in the final test script) by another: the $Have_Plan variable is replaced by this sub sub _has_any_plan { return Test::Builder->new->has_plan || Test::Builder->new->{Skip_All}; # FIXME } because the Test::Builder::has_plan method contains the information about having a plan when "tests => <number>" or "no_plan" were used. But when doing an "skip all", the actual Test::Builder gives us no help (though I already submitted a patch to Test::Builder to have a documented way to determine if "plan('skip_all')" was seen, but I was not happy to get a response yet or the patch applied). So the sub peeks at the internal state of Test::Builder which should be fine by now, even though it is a hack. The importance of this has to do with END block used to invoke run_compare as a default action for an empty test script. What more can be done after this patch? (1) Easier code for skip_all tests. For instance, to use Test::Base (if installed) in a script on distribution Carp-Always, I used the code (which I should have borrowed somewhere else): BEGIN { eval { require Test::Base }; if ($@) { require Test::More; Test::More::plan(skip_all => "Test::Base required for module tests"); } } As Test::Base clashes with Test::More, only if require failed I require Test::More to emit a skip_all plan. After the patch, this code may be replaced by use Test::More; BEGIN { eval "use Test::Base"; plan skip_all => "Test::Base required for module tests" if $@; } which is closer to the one used for tests which run only when a testing module is available. (2) interaction with other Test:: modules The same way I showed the interference between Test::More and Test::Base, this patch avoids the user to be surprised when she mixes two test modules (Test::Base and the other) which are based on Test::Builder and which are supposed to cooperate. It may depend on the order and which test module was actually used to set the plan. But this is fixed after the patch. Well, that's it. Thanks for this great test module. Cheers, Adriano Ferreira

Message body is not shown because sender requested not to inline it.