From: Karen Etheridge Date: Sat, 13 Apr 2013 21:36:22 +0000 (-0700) Subject: fix incompatibilities with TB2 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=gitmo%2FMoose.git;a=commitdiff_plain;h=9153f80be375a2544592ce01f7a2cdcc008ba3d5 fix incompatibilities with TB2 I tested this with Test-Simple-1.005000_006. The return value of with_immutable still indicates whether all tests contained in its block had passed, even though this is undocumented. --- diff --git a/Changes b/Changes index ea0c078..9799f8c 100644 --- a/Changes +++ b/Changes @@ -2,6 +2,7 @@ Also see Moose::Manual::Delta for more details of, and workarounds for, noteworthy changes. {{$NEXT}} + * fix incompatibilities with Test::Builder 1.005+ (Karen Etheridge) 2.0801 Thu, Mar 28, 2013 diff --git a/lib/Test/Moose.pm b/lib/Test/Moose.pm index 38f5fe6..f2f0d9e 100644 --- a/lib/Test/Moose.pm +++ b/lib/Test/Moose.pm @@ -71,11 +71,17 @@ sub has_attribute_ok ($$;$) { sub with_immutable (&@) { my $block = shift; my $before = $Test->current_test; + my $passing_before = (Test::Builder->VERSION < 1.005 ? 0 : $Test->history->pass_count) || 0; + $block->(); Class::MOP::class_of($_)->make_immutable for @_; $block->(); + my $num_tests = $Test->current_test - $before; - return all { $_ } ($Test->summary)[-$num_tests..-1]; + my $all_passed = Test::Builder->VERSION < 1.005 + ? all { $_ } ($Test->summary)[-$num_tests..-1] + : $num_tests == $Test->history->pass_count - $passing_before; + return $all_passed; } 1; diff --git a/t/test_moose/with_immutable.t b/t/test_moose/with_immutable.t index 7690ce2..26f992e 100644 --- a/t/test_moose/with_immutable.t +++ b/t/test_moose/with_immutable.t @@ -6,6 +6,9 @@ use warnings; use Test::Builder::Tester; use Test::More; +plan skip_all => 'These tests are only for Test::Builder 0.9x' + if Test::Builder->VERSION >= 1.005; + use Test::Moose; { diff --git a/t/test_moose/with_immutable_tb2.t b/t/test_moose/with_immutable_tb2.t new file mode 100644 index 0000000..634a0d4 --- /dev/null +++ b/t/test_moose/with_immutable_tb2.t @@ -0,0 +1,70 @@ +use strict; +use warnings; + +use Test::More; + +BEGIN { + use Test::More; + plan skip_all => 'These tests are only for Test::Builder 1.005+' + if Test::Builder->VERSION < 1.005; +} + +{ + package Foo; + use Moose; +} + +{ + package Bar; + use Moose; +} + +package main; + +use Test::Moose; +use TB2::Tester; +use TB2::History; # FIXME - this should not need to be loaded here explicitly + +my ($ret1, $ret2); +my $capture = capture { + $ret1 = with_immutable { + ok(Foo->meta->is_mutable, 'is mutable'); + } qw(Foo); + + $ret2 = with_immutable { + ok(Bar->meta->find_method_by_name('new'), 'can find "new" method'); + } qw(Bar); +}; + +my $results = $capture->results; + +my @tests = ( + [ + 'first test runs while Foo is mutable' => { name => 'is mutable', + is_pass => 1, + }, + ], + [ + 'first test runs while Foo is immutable' => { name => 'is mutable', + is_pass => 0, + }, + ], + [ + 'can find "new" while Bar is mutable' => { name => 'can find "new" method', + is_pass => 1, + }, + ], + [ + 'can find "new" while Bar is immutable' => { name => 'can find "new" method', + is_pass => 1, + }, + ], +); + +result_like(shift(@$results), $_->[1], $_->[0]) foreach @tests; + +ok(!$ret1, 'one of the is_immutable tests failed'); +ok($ret2, 'the find_method_by_name tests passed'); + +done_testing; +