Permalink
Browse files

Emulate an accidental behavior of Test::Builder::Tester.

Previously, TBT would not completely reset the test state so the
plan would still be set.  Some tests accidentally relied on this,
anything that would set the plan if it hasn't already been set like
Test::HasVersion or Test::DistManifest.

This change sets a plan in the test test if there was one before
to emulate the behavior.

For #327 and #328
  • Loading branch information...
1 parent ecb3a34 commit 00d4609f79fef0ad0db954ba9d9982026eb755e0 @schwern schwern committed Aug 3, 2012
Showing with 25 additions and 2 deletions.
  1. +3 −0 Changes
  2. +5 −2 lib/Test/Builder/Tester.pm
  3. +17 −0 t/Tester/plan.t
View
3 Changes
@@ -4,6 +4,9 @@ See README and version control log for Test::Builder2 changes.
Bug Fixes
* Patched TB2::Mouse to not blow over tied $_ (a local $_ bug).
(Father Chrysostomos) [github 293]
+ * Test::Builder::Tester will now set a plan in test tests emulating
+ an undocumented feature that some tests accidentally rely on.
+ [github 327] [github 328]
Misc
* Update the resources meta data to point at the correct repository, issues
View
7 lib/Test/Builder/Tester.pm
@@ -99,9 +99,12 @@ sub _start_testing {
late_handlers => $original_state->late_handlers,
);
- # To emulate existing behavior, start testing but don't
- # let the formatter see it
+ # To retain compatibility with old behaviors...
+ # start testing but don't let the formatter see it
$state->post_event( TB2::Event::TestStart->new );
+ # start a plan if the original test had a plan
+ $state->post_event( TB2::Event::SetPlan->new( no_plan => 1 ) )
+ if $original_state->history->plan;
$state->add_formatters($formatter);
# remember that we're testing
View
17 t/Tester/plan.t
@@ -0,0 +1,17 @@
+#!/usr/bin/env perl
+
+# This tests that TBT emulates a previous accidental behavior that some
+# tests accidentally rely on. The larger TBT plan would leak into the
+# test tests.
+
+use strict;
+use warnings;
+
+use Test::Builder::Tester tests => 1;
+use Test::More;
+
+test_out("ok 1 - TBT sets a plan in test tests");
+test_out("ok 2");
+ok( Test::Builder->new->has_plan, "TBT sets a plan in test tests" );
+pass;
+test_test();

0 comments on commit 00d4609

Please sign in to comment.