Dne So 29.led.2011 17:04:47, MSCHWERN napsal(a):
Show quoted text> Test::Able::Role::Meta::Class uses the internals of Test::Builder in
> several places. This is not safe. Those internals will and have changed.
>
Please look at the attached patch. It makes tests passing again.
From 23d457c1528c44c4fb1aca34cccc5f18086fc5c9 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Petr=20P=C3=ADsa=C5=99?= <ppisar@redhat.com>
Date: Mon, 23 May 2016 18:16:24 +0200
Subject: [PATCH] Adapt to Test-Simple-1.302019
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
This patch removes touching internals of the Test::Builder. More code
could be removed probably.
Also I removed the trailing END test in t/plans.t because number of
expected tests is not a global variable anymore and thus it's not
accessible out of the test scope.
I do not understand how t/cookbook.t gets plan defined to no_plan, but
if I kept setting plan to no_plan in the _build_runner_plan's else
branch, Test::Builder would complain about multiple setting to
no_plan.
Actually if all the branches after the "return $plan if $self->dry_run;"
are removed, the tests will pass. Maybe current Test::Builder is smart
enough to count the expected tests properly.
CPAN RT#65249
Signed-off-by: Petr PÃsaÅ <ppisar@redhat.com>
---
lib/Test/Able/Role/Meta/Class.pm | 20 +++++++++-----------
t/plans.t | 5 -----
2 files changed, 9 insertions(+), 16 deletions(-)
diff --git a/lib/Test/Able/Role/Meta/Class.pm b/lib/Test/Able/Role/Meta/Class.pm
index ab31e92..8056dc6 100644
--- a/lib/Test/Able/Role/Meta/Class.pm
+++ b/lib/Test/Able/Role/Meta/Class.pm
@@ -304,6 +304,7 @@ sub run_tests {
}
# Finalize planning for this run.
+ $self->builder->{able_Finalized} = 1;
$self->clear_runner_plan;
$self->runner_plan;
$self->clear_last_runner_plan;
@@ -348,7 +349,7 @@ sub run_methods {
}
unless ( $setup_exception_count || $self->dry_run ) {
- my $tests_before = $self->builder->{Curr_Test};
+ my $tests_before = $self->builder->current_test;
eval { $self->current_test_object->$method_name; };
if ( my $exception = $@ ) {
@@ -368,7 +369,7 @@ sub run_methods {
}
if ( $self->on_method_plan_fail && $method->plan =~ /^\d+$/ ) {
- my $tests_diff = $self->builder->{Curr_Test} - $tests_before;
+ my $tests_diff = $self->builder->current_test - $tests_before;
if ( $tests_diff != $method->plan ) {
my $msg = "Method $method_name planned " . $method->plan
. " tests but ran $tests_diff.";
@@ -550,24 +551,22 @@ sub _build_runner_plan {
return $plan if $self->dry_run;
- $self->builder->no_plan unless $self->builder->has_plan;
-
- # Update Test::Builder.
- if ( $self->builder->{No_Plan} || $self->builder->{was_No_Plan} ) {
+ if ( !defined $self->builder->has_plan || $self->builder->has_plan eq 'no_plan' || $self->builder->{was_No_Plan} ) {
if ( $plan =~ /^\d+$/ ) {
if ( $self->has_last_runner_plan ) {
my $last = $self->last_runner_plan;
my $plan_diff = $plan - ( $last eq 'no_plan' ? 0 : $last );
- $self->builder->{Expected_Tests} += $plan_diff;
+ $self->builder->{able_Plan} += $plan_diff;
+ if ($self->builder->{able_Finalized} and !defined $self->builder->has_plan) {
+ $self->builder->plan(tests => $self->builder->{able_Plan});
+ }
}
else {
- $self->builder->{Expected_Tests} += $plan;
+ $self->builder->{able_Plan} += $plan;
}
- $self->builder->{No_Plan} = 0;
$self->builder->{was_No_Plan} = 1;
$self->last_runner_plan( $plan );
}
- else { $self->builder->{No_Plan} = 1; }
}
return $plan;
@@ -587,7 +586,6 @@ sub _hack_test_builder {
my $builder = shift;
if ( $builder->{was_No_Plan} && $self->runner_plan =~ /\d+/ ) {
- $builder->expected_tests( $self->builder->{Expected_Tests} );
$builder->no_header( 1 );
}
diff --git a/t/plans.t b/t/plans.t
index 38cc9f3..4b48de1 100644
--- a/t/plans.t
+++ b/t/plans.t
@@ -94,8 +94,3 @@ sub set_plan_on_no_plan_methods {
return;
}
-sub END {
- my $tb = Test::Builder->new;
- die 'bad plan (' . $tb->expected_tests . ')'
- unless $tb->expected_tests == 66;
-}
--
2.5.5