add with_immutable test helper
Jesse Luehrs [Sat, 5 Dec 2009 00:32:53 +0000 (18:32 -0600)]
Changes
lib/Test/Moose.pm
t/500_test_moose/005_with_immutable.t [new file with mode: 0644]

diff --git a/Changes b/Changes
index c4cdb8f..fe3a047 100644 (file)
--- 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)
index b27e8b1..ed78dd3 100644 (file)
@@ -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 (file)
index 0000000..77e2b6c
--- /dev/null
@@ -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');