From: Jesse Luehrs Date: Sat, 5 Dec 2009 00:32:53 +0000 (-0600) Subject: add with_immutable test helper X-Git-Tag: 0.93_01~41^2~3 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=f2ca7ada2d1760ce3d561ec1902867d5f6da41e4;p=gitmo%2FMoose.git add with_immutable test helper --- diff --git a/Changes b/Changes index c4cdb8f..fe3a047 100644 --- a/Changes +++ b/Changes @@ -8,6 +8,10 @@ for, noteworthy changes. general failures if you don't have the author side dependencies installed + * Test::Moose + - Added a with_immutable test function, to run a block of tests with + and without certain classes being immutable. (doy) + 0.94 * Moose::Cookbook::Basics::Recipe4 - Grammar error [rt.cpan.org #51791] (Amir E. Aharoni) diff --git a/lib/Test/Moose.pm b/lib/Test/Moose.pm index b27e8b1..ed78dd3 100644 --- a/lib/Test/Moose.pm +++ b/lib/Test/Moose.pm @@ -16,6 +16,7 @@ my @exports = qw[ meta_ok does_ok has_attribute_ok + with_immutable ]; Sub::Exporter::setup_exporter({ @@ -70,6 +71,13 @@ sub has_attribute_ok ($$;$) { } } +sub with_immutable (&@) { + my $block = shift; + $block->(); + $_->meta->make_immutable for @_; + $block->(); +} + 1; __END__ diff --git a/t/500_test_moose/005_with_immutable.t b/t/500_test_moose/005_with_immutable.t new file mode 100644 index 0000000..77e2b6c --- /dev/null +++ b/t/500_test_moose/005_with_immutable.t @@ -0,0 +1,26 @@ +#!/usr/bin/perl + +use strict; +use warnings; + +use Test::Builder::Tester tests => 2; +use Test::More; + +BEGIN { + use_ok('Test::Moose'); +} + +{ + package Foo; + use Moose; +} + +package main; + +test_out("ok 1", "not ok 2"); +test_fail(+2); +with_immutable { + ok(Foo->meta->is_mutable); +} qw(Foo); + +test_test('with_immutable');