From: Jesse Luehrs Date: Fri, 11 Dec 2009 00:48:34 +0000 (-0600) Subject: give with_immutable a reasonable return value X-Git-Tag: 0.93_01~41^2~2 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=92c04d5e095336867d30244dec27de72b05f8475;p=gitmo%2FMoose.git give with_immutable a reasonable return value --- diff --git a/lib/Test/Moose.pm b/lib/Test/Moose.pm index ed78dd3..5f66349 100644 --- a/lib/Test/Moose.pm +++ b/lib/Test/Moose.pm @@ -6,6 +6,7 @@ use warnings; use Sub::Exporter; use Test::Builder; +use List::MoreUtils 'all'; use Moose::Util 'does_role', 'find_meta'; our $VERSION = '0.93'; @@ -73,9 +74,12 @@ sub has_attribute_ok ($$;$) { sub with_immutable (&@) { my $block = shift; + my $before = $Test->current_test; $block->(); $_->meta->make_immutable for @_; $block->(); + my $num_tests = $Test->current_test - $before; + return all { $_ } ($Test->summary)[-$num_tests..-1]; } 1; diff --git a/t/500_test_moose/005_with_immutable.t b/t/500_test_moose/005_with_immutable.t index 77e2b6c..3cfe91d 100644 --- a/t/500_test_moose/005_with_immutable.t +++ b/t/500_test_moose/005_with_immutable.t @@ -3,7 +3,7 @@ use strict; use warnings; -use Test::Builder::Tester tests => 2; +use Test::Builder::Tester tests => 5; use Test::More; BEGIN { @@ -15,12 +15,24 @@ BEGIN { use Moose; } +{ + package Bar; + use Moose; +} + package main; test_out("ok 1", "not ok 2"); test_fail(+2); -with_immutable { +my $ret = with_immutable { ok(Foo->meta->is_mutable); } qw(Foo); +test_test('with_immutable failure'); +ok(!$ret, "one of our tests failed"); -test_test('with_immutable'); +test_out("ok 1", "ok 2"); +$ret = with_immutable { + ok(Bar->meta->find_method_by_name('new')); +} qw(Bar); +test_test('with_immutable success'); +ok($ret, "all tests succeeded");