On Sat, Mar 30, 2002 at 05:33:55PM -0600, Dave Rolsky wrote:
> The changelog says this:
>
> 0.42 Wed Mar 6 15:00:24 EST 2002
> - Setting Test::Builder->current_test() now works (see what happens
> when you forget to test things?)
>
> But if I do this:
>
> perl -MTest::Builder -e 'Test::Builder->new->current_test(10)'
>
> it still blows chunks.
$ perl -Ilib -MTest::Builder -e 'Test::Builder->new->current_test(10)'
WHOA! Somehow your tests ran without a plan!
This should never happen! Please contact the author immediately!
END failed--call queue aborted.
which is only sort of right. The above code should result in a
failure, since you forgot to plan. However, it should not result in a
whoa.
Not sure how to handle this. It should result in an integrity check
failure, since there was no plan, but it should not think its an
internal inconsistency caused by a Test::Builder bug.
Simplest thing to do would be for current_test to disallow you
from changing it unless you have a plan, like ok() does...
$ perl -Ilib -MTest::Builder -e 'Test::Builder->new->current_test(10)'
Can't change the current test number without a plan! at -e line 1
> Patch below.
Doesn't seem to have any effect on the code above, but it does have an
effect on this:
$ perl -Ilib -MTest::Builder -e '$tb=Test::Builder->new; $tb->plan('no_plan');
$tb->current_test(10)'
Modification of non-creatable array value attempted, subscript -1 at
lib/Test/Builder.pm line 948.
WHOA! Somehow you got a different number of results than tests ran!
This should never happen! Please contact the author immediately!
END failed--call queue aborted.
which will result in this in 0.43:
$ perl -Ilib -MTest::Builder -e '$tb=Test::Builder->new; $tb->plan('no_plan');
$tb->current_test(10)'
1..10
Attached is a patch to 0.42 which has been applied to fix all this.
> houseabsolute:/usr/local/share/perl/5.6.1/Test> diff -u
> /root/.cpan/build/Test-Simple-0.42/lib/Test/Builder.pm Builder.pm
> --- /root/.cpan/build/Test-Simple-0.42/lib/Test/Builder.pm Wed Mar 6
> 14:14:58 2002
> +++ Builder.pm Sat Mar 30 17:29:42 2002
> @@ -935,7 +935,8 @@
> if( defined $num ) {
> $Curr_Test = $num;
> if( $num > @Test_Results ) {
> - for ($#Test_Results..$num-1) {
> + my $start = @Test_Results ? $#Test_Results : 0;
> + for ($start..$num-1) {
> $Test_Results[$_] = 1;
> }
> }
--
Michael G. Schwern <[EMAIL PROTECTED]> http://www.pobox.com/~schwern/
Perl Quality Assurance <[EMAIL PROTECTED]> Kwalitee Is Job One
I was *meant* to mount your donuts.
--- Changes 6 Mar 2002 20:24:57 -0000 1.30
+++ Changes 31 Mar 2002 03:37:01 -0000 1.31
@@ -1,5 +1,9 @@
Revision history for Perl extension Test::Simple
+0.43
+ - TB->current_test() still not working when no tests were run via
+ TB itself. Fixed by Dave Rolsky.
+
0.42 Wed Mar 6 15:00:24 EST 2002
- Setting Test::Builder->current_test() now works (see what happens
when you forget to test things?)
--- MANIFEST 19 Dec 2001 23:31:20 -0000 1.18
+++ MANIFEST 31 Mar 2002 03:35:38 -0000 1.19
@@ -10,6 +10,7 @@
t/Builder.t
t/More.t
t/buffer.t
+t/curr_test.t
t/diag.t
t/exit.t
t/extra.t
--- lib/Test/Builder.pm 6 Mar 2002 20:23:23 -0000 1.15
+++ lib/Test/Builder.pm 31 Mar 2002 03:36:30 -0000 1.16
@@ -8,7 +8,7 @@
use strict;
use vars qw($VERSION $CLASS);
-$VERSION = '0.12';
+$VERSION = '0.13';
$CLASS = __PACKAGE__;
my $IsVMS = $^O eq 'VMS';
@@ -239,7 +239,8 @@
my($self, $test, $name) = @_;
unless( $Have_Plan ) {
- die "You tried to run a test without a plan! Gotta have a plan.\n";
+ require Carp;
+ Carp::croak("You tried to run a test without a plan! Gotta have a plan.");
}
$Curr_Test++;
@@ -564,7 +565,8 @@
$why ||= '';
unless( $Have_Plan ) {
- die "You tried to run tests without a plan! Gotta have a plan.\n";
+ require Carp;
+ Carp::croak("You tried to run tests without a plan! Gotta have a plan.");
}
$Curr_Test++;
@@ -598,7 +600,8 @@
$why ||= '';
unless( $Have_Plan ) {
- die "You tried to run tests without a plan! Gotta have a plan.\n";
+ require Carp;
+ Carp::croak("You tried to run tests without a plan! Gotta have a plan.");
}
$Curr_Test++;
@@ -933,9 +936,16 @@
my($self, $num) = @_;
if( defined $num ) {
+
+ unless( $Have_Plan ) {
+ require Carp;
+ Carp::croak("Can't change the current test number without a plan!");
+ }
+
$Curr_Test = $num;
if( $num > @Test_Results ) {
- for ($#Test_Results..$num-1) {
+ my $start = @Test_Results ? $#Test_Results : 0;
+ for ($start..$num-1) {
$Test_Results[$_] = 1;
}
}
--- /dev/null Fri Mar 15 19:43:09 2002
+++ t/curr_test.t Sat Mar 30 22:33:42 2002
@@ -0,0 +1,11 @@
+#!/usr/bin/perl -w
+
+# Dave Rolsky found a bug where if current_test() is used and no
+# tests are run via Test::Builder it will blow up.
+
+use Test::Builder;
+$TB = Test::Builder->new;
+$TB->plan(tests => 2);
+print "ok 1\n";
+print "ok 2\n";
+$TB->current_test(2);