summaryrefslogtreecommitdiffstats
path: root/t
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2010-06-15 03:39:08 -0500
committerJesse Luehrs <doy@tozt.net>2010-06-15 03:39:08 -0500
commitdfc2ff5f2709f198d9fdb21d84a2534acc9f3670 (patch)
tree1e7792b6281cc26c634552d0b3a34ac73653fc62 /t
parenteaf8ccad64a0ca7a5f69ce884753a395f4c196fc (diff)
downloadmoosex-nonmoose-dfc2ff5f2709f198d9fdb21d84a2534acc9f3670.tar.gz
moosex-nonmoose-dfc2ff5f2709f198d9fdb21d84a2534acc9f3670.zip
make more tests use with_immutable
Diffstat (limited to 't')
-rw-r--r--t/21-BUILDARGS.t13
-rw-r--r--t/23-FOREIGNBUILDARGS.t33
-rw-r--r--t/24-nonmoose-moose-nonmoose.t70
-rw-r--r--t/25-constructor-method-calls.t2
-rw-r--r--t/32-moosex-insideout.t33
-rw-r--r--t/33-moosex-globref.t62
-rw-r--r--t/40-destructor.t19
-rw-r--r--t/50-buggy-constructor-inlining.t2
8 files changed, 93 insertions, 141 deletions
diff --git a/t/21-BUILDARGS.t b/t/21-BUILDARGS.t
index d6aa973..4fed2a7 100644
--- a/t/21-BUILDARGS.t
+++ b/t/21-BUILDARGS.t
@@ -2,6 +2,7 @@
use strict;
use warnings;
use Test::More tests => 4;
+use Test::Moose;
package Foo;
@@ -30,10 +31,8 @@ sub BUILDARGS {
package main;
-my $foo = Foo::Moose->new('bar', foo => 'baz');
-is($foo->name, 'bar', 'superclass constructor gets the right args');
-is($foo->foo, 'baz', 'subclass constructor gets the right args');
-Foo::Moose->meta->make_immutable;
-$foo = Foo::Moose->new('bar', foo => 'baz');
-is($foo->name, 'bar', 'superclass constructor gets the right args (immutable)');
-is($foo->foo, 'baz', 'subclass constructor gets the right args (immutable)');
+with_immutable {
+ my $foo = Foo::Moose->new('bar', foo => 'baz');
+ is($foo->name, 'bar', 'superclass constructor gets the right args');
+ is($foo->foo, 'baz', 'subclass constructor gets the right args');
+} 'Foo::Moose';
diff --git a/t/23-FOREIGNBUILDARGS.t b/t/23-FOREIGNBUILDARGS.t
index 43529dd..a9e8cef 100644
--- a/t/23-FOREIGNBUILDARGS.t
+++ b/t/23-FOREIGNBUILDARGS.t
@@ -2,6 +2,7 @@
use strict;
use warnings;
use Test::More tests => 12;
+use Test::Moose;
package Foo;
@@ -56,24 +57,14 @@ has baz => (
package main;
-my $foo = Foo::Moose->new(foo => 'bar');
-is($foo->foo, 'bar', 'subclass constructor gets the right args');
-is($foo->foo_base, 'bar_base', 'subclass constructor gets the right args');
-my $bar = Bar::Moose->new('baz');
-is($bar->bar, 'baz', 'subclass constructor gets the right args');
-is($bar->foo_base, 'baz_base', 'subclass constructor gets the right args');
-my $baz = Baz::Moose->new('bazbaz');
-is($baz->bar, 'bazbaz', 'extensions of extensions of the nonmoose class respect BUILDARGS');
-is($baz->foo_base, 'bazbaz_base', 'extensions of extensions of the nonmoose class respect FOREIGNBUILDARGS');
-Foo::Moose->meta->make_immutable;
-Bar::Moose->meta->make_immutable;
-Baz::Moose->meta->make_immutable;
-$foo = Foo::Moose->new(foo => 'bar');
-is($foo->foo, 'bar', 'subclass constructor gets the right args (immutable)');
-is($foo->foo_base, 'bar_base', 'subclass constructor gets the right args (immutable)');
-$bar = Bar::Moose->new('baz');
-is($bar->bar, 'baz', 'subclass constructor gets the right args (immutable)');
-is($bar->foo_base, 'baz_base', 'subclass constructor gets the right args (immutable)');
-$baz = Baz::Moose->new('bazbaz');
-is($baz->bar, 'bazbaz', 'extensions of extensions of the nonmoose class respect BUILDARGS (immutable)');
-is($baz->foo_base, 'bazbaz_base', 'extensions of extensions of the nonmoose class respect FOREIGNBUILDARGS (immutable)');
+with_immutable {
+ my $foo = Foo::Moose->new(foo => 'bar');
+ is($foo->foo, 'bar', 'subclass constructor gets the right args');
+ is($foo->foo_base, 'bar_base', 'subclass constructor gets the right args');
+ my $bar = Bar::Moose->new('baz');
+ is($bar->bar, 'baz', 'subclass constructor gets the right args');
+ is($bar->foo_base, 'baz_base', 'subclass constructor gets the right args');
+ my $baz = Baz::Moose->new('bazbaz');
+ is($baz->bar, 'bazbaz', 'extensions of extensions of the nonmoose class respect BUILDARGS');
+ is($baz->foo_base, 'bazbaz_base', 'extensions of extensions of the nonmoose class respect FOREIGNBUILDARGS');
+} qw(Foo::Moose Bar::Moose Baz::Moose);
diff --git a/t/24-nonmoose-moose-nonmoose.t b/t/24-nonmoose-moose-nonmoose.t
index ef0ce88..b9ae100 100644
--- a/t/24-nonmoose-moose-nonmoose.t
+++ b/t/24-nonmoose-moose-nonmoose.t
@@ -2,6 +2,7 @@
use strict;
use warnings;
use Test::More tests => 32;
+use Test::Moose;
package Foo;
@@ -54,46 +55,29 @@ package Bar::Moose::Sub;
use base 'Bar::Moose';
package main;
-my $foo = Foo::Moose::Sub->new(name => 'foomoosesub', foo2 => 'FOO2');
-isa_ok($foo, 'Foo');
-isa_ok($foo, 'Foo::Moose');
-is($foo->foo, 'foomoosesub', 'got name from nonmoose constructor');
-is($foo->foo2, 'FOO2', 'got attribute value from moose constructor');
-$foo = Foo::Moose->new(name => 'foomoosesub', foo2 => 'FOO2');
-isa_ok($foo, 'Foo');
-isa_ok($foo, 'Foo::Moose');
-is($foo->foo, 'foomoosesub', 'got name from nonmoose constructor');
-is($foo->foo2, 'FOO2', 'got attribute value from moose constructor');
-Foo::Moose->meta->make_immutable;
-$foo = Foo::Moose::Sub->new(name => 'foomoosesub', foo2 => 'FOO2');
-isa_ok($foo, 'Foo');
-isa_ok($foo, 'Foo::Moose');
-is($foo->foo, 'foomoosesub', 'got name from nonmoose constructor (immutable)');
-is($foo->foo2, 'FOO2', 'got attribute value from moose constructor (immutable)');
-$foo = Foo::Moose->new(name => 'foomoosesub', foo2 => 'FOO2');
-isa_ok($foo, 'Foo');
-isa_ok($foo, 'Foo::Moose');
-is($foo->foo, 'foomoosesub', 'got name from nonmoose constructor (immutable)');
-is($foo->foo2, 'FOO2', 'got attribute value from moose constructor (immutable)');
-
-my $bar = Bar::Moose::Sub->new(name => 'barmoosesub', bar2 => 'BAR2');
-isa_ok($bar, 'Bar');
-isa_ok($bar, 'Bar::Moose');
-is($bar->bar, 'barmoosesub', 'got name from nonmoose constructor');
-is($bar->bar2, 'BAR2', 'got attribute value from moose constructor');
-$bar = Bar::Moose->new(name => 'barmoosesub', bar2 => 'BAR2');
-isa_ok($bar, 'Bar');
-isa_ok($bar, 'Bar::Moose');
-is($bar->bar, 'barmoosesub', 'got name from nonmoose constructor');
-is($bar->bar2, 'BAR2', 'got attribute value from moose constructor');
-Bar::Moose->meta->make_immutable;
-$bar = Bar::Moose::Sub->new(name => 'barmoosesub', bar2 => 'BAR2');
-isa_ok($bar, 'Bar');
-isa_ok($bar, 'Bar::Moose');
-is($bar->bar, 'barmoosesub', 'got name from nonmoose constructor (immutable)');
-is($bar->bar2, 'BAR2', 'got attribute value from moose constructor (immutable)');
-$bar = Bar::Moose->new(name => 'barmoosesub', bar2 => 'BAR2');
-isa_ok($bar, 'Bar');
-isa_ok($bar, 'Bar::Moose');
-is($bar->bar, 'barmoosesub', 'got name from nonmoose constructor (immutable)');
-is($bar->bar2, 'BAR2', 'got attribute value from moose constructor (immutable)');
+
+with_immutable {
+ my $foo = Foo::Moose::Sub->new(name => 'foomoosesub', foo2 => 'FOO2');
+ isa_ok($foo, 'Foo');
+ isa_ok($foo, 'Foo::Moose');
+ is($foo->foo, 'foomoosesub', 'got name from nonmoose constructor');
+ is($foo->foo2, 'FOO2', 'got attribute value from moose constructor');
+ $foo = Foo::Moose->new(name => 'foomoosesub', foo2 => 'FOO2');
+ isa_ok($foo, 'Foo');
+ isa_ok($foo, 'Foo::Moose');
+ is($foo->foo, 'foomoosesub', 'got name from nonmoose constructor');
+ is($foo->foo2, 'FOO2', 'got attribute value from moose constructor');
+} 'Foo::Moose';
+
+with_immutable {
+ my $bar = Bar::Moose::Sub->new(name => 'barmoosesub', bar2 => 'BAR2');
+ isa_ok($bar, 'Bar');
+ isa_ok($bar, 'Bar::Moose');
+ is($bar->bar, 'barmoosesub', 'got name from nonmoose constructor');
+ is($bar->bar2, 'BAR2', 'got attribute value from moose constructor');
+ $bar = Bar::Moose->new(name => 'barmoosesub', bar2 => 'BAR2');
+ isa_ok($bar, 'Bar');
+ isa_ok($bar, 'Bar::Moose');
+ is($bar->bar, 'barmoosesub', 'got name from nonmoose constructor');
+ is($bar->bar2, 'BAR2', 'got attribute value from moose constructor');
+} 'Bar::Moose';
diff --git a/t/25-constructor-method-calls.t b/t/25-constructor-method-calls.t
index 7806b44..7187bb8 100644
--- a/t/25-constructor-method-calls.t
+++ b/t/25-constructor-method-calls.t
@@ -2,7 +2,7 @@
use strict;
use warnings;
use Test::More;
-use Test::Moose qw(with_immutable);
+use Test::Moose;
my ($foo, $foosub);
{
diff --git a/t/32-moosex-insideout.t b/t/32-moosex-insideout.t
index 128c437..ae31359 100644
--- a/t/32-moosex-insideout.t
+++ b/t/32-moosex-insideout.t
@@ -2,6 +2,7 @@
use strict;
use warnings;
use Test::More;
+use Test::Moose;
BEGIN {
eval "use MooseX::InsideOut 0.100 ()";
plan skip_all => "MooseX::InsideOut is required for this test" if $@;
@@ -63,23 +64,15 @@ package Foo::Moose::Sub;
use base 'Foo::Moose';
package main;
-my $foo = Foo::Moose->new('FOO', bar => 'BAR');
-is($foo->foo, 'FOO', 'base class accessor works');
-is($foo->bar, 'BAR', 'subclass accessor works');
-$foo->foo('OOF');
-$foo->bar('RAB');
-is($foo->foo, 'OOF', 'base class accessor works (setting)');
-is($foo->bar, 'RAB', 'subclass accessor works (setting)');
-my $sub_foo = eval { Foo::Moose::Sub->new(FOO => bar => 'AHOY') };
-is(eval { $sub_foo->bar }, 'AHOY', 'subclass constructor works');
-Foo::Moose->meta->make_immutable;
-$foo = Foo::Moose->new('FOO', bar => 'BAR');
-is($foo->foo, 'FOO', 'base class accessor works (immutable)');
-is($foo->bar, 'BAR', 'subclass accessor works (immutable)');
-$foo->foo('OOF');
-$foo->bar('RAB');
-is($foo->foo, 'OOF', 'base class accessor works (setting) (immutable)');
-is($foo->bar, 'RAB', 'subclass accessor works (setting) (immutable)');
-my $sub_foo_immutable = eval { Foo::Moose::Sub->new(FOO => bar => 'AHOY') };
-is(eval { $sub_foo_immutable->bar }, 'AHOY',
- 'subclass constructor works (immutable)');
+
+with_immutable {
+ my $foo = Foo::Moose->new('FOO', bar => 'BAR');
+ is($foo->foo, 'FOO', 'base class accessor works');
+ is($foo->bar, 'BAR', 'subclass accessor works');
+ $foo->foo('OOF');
+ $foo->bar('RAB');
+ is($foo->foo, 'OOF', 'base class accessor works (setting)');
+ is($foo->bar, 'RAB', 'subclass accessor works (setting)');
+ my $sub_foo = eval { Foo::Moose::Sub->new(FOO => bar => 'AHOY') };
+ is(eval { $sub_foo->bar }, 'AHOY', 'subclass constructor works');
+} 'Foo::Moose';
diff --git a/t/33-moosex-globref.t b/t/33-moosex-globref.t
index be8c26b..3f59e39 100644
--- a/t/33-moosex-globref.t
+++ b/t/33-moosex-globref.t
@@ -2,6 +2,7 @@
use strict;
use warnings;
use Test::More;
+use Test::Moose;
BEGIN {
eval "use MooseX::GlobRef ()";
plan skip_all => "MooseX::GlobRef is required for this test" if $@;
@@ -58,42 +59,27 @@ has baz => (
sub FOREIGNBUILDARGS { return }
package main;
-my $handle = IO::Handle::Moose->new(bar => 'BAR');
-is($handle->bar, 'BAR', 'moose accessor works properly');
-$handle->bar('RAB');
-is($handle->bar, 'RAB', 'moose accessor works properly (setting)');
-IO::Handle::Moose->meta->make_immutable;
-$handle = IO::Handle::Moose->new(bar => 'BAR');
-is($handle->bar, 'BAR', 'moose accessor works properly');
-$handle->bar('RAB');
-is($handle->bar, 'RAB', 'moose accessor works properly (setting)');
-SKIP: {
- my $fh = IO::File::Moose->new(baz => 'BAZ');
- open $fh, "+>", undef
- or skip "couldn't open a temporary file", 3;
- is($fh->baz, 'BAZ', "accessor works");
- $fh->baz('ZAB');
- is($fh->baz, 'ZAB', "accessor works (writing)");
- $fh->print("foo\n");
- print $fh "bar\n";
- $fh->seek(0, 0);
- my $buf;
- $fh->read($buf, 8);
- is($buf, "foo\nbar\n", "filehandle still works as normal");
-}
-IO::File::Moose->meta->make_immutable;
-SKIP: {
- my $fh = IO::File::Moose->new(baz => 'BAZ');
- open $fh, "+>", undef
- or skip "couldn't open a temporary file", 3;
- is($fh->baz, 'BAZ', "accessor works");
- $fh->baz('ZAB');
- is($fh->baz, 'ZAB', "accessor works (writing)");
- $fh->print("foo\n");
- print $fh "bar\n";
- $fh->seek(0, 0);
- my $buf;
- $fh->read($buf, 8);
- is($buf, "foo\nbar\n", "filehandle still works as normal");
-}
+with_immutable {
+ my $handle = IO::Handle::Moose->new(bar => 'BAR');
+ is($handle->bar, 'BAR', 'moose accessor works properly');
+ $handle->bar('RAB');
+ is($handle->bar, 'RAB', 'moose accessor works properly (setting)');
+} 'IO::Handle::Moose';
+
+with_immutable {
+ SKIP: {
+ my $fh = IO::File::Moose->new(baz => 'BAZ');
+ open $fh, "+>", undef
+ or skip "couldn't open a temporary file", 3;
+ is($fh->baz, 'BAZ', "accessor works");
+ $fh->baz('ZAB');
+ is($fh->baz, 'ZAB', "accessor works (writing)");
+ $fh->print("foo\n");
+ print $fh "bar\n";
+ $fh->seek(0, 0);
+ my $buf;
+ $fh->read($buf, 8);
+ is($buf, "foo\nbar\n", "filehandle still works as normal");
+ }
+} 'IO::File::Moose';
diff --git a/t/40-destructor.t b/t/40-destructor.t
index f2c88be..741db60 100644
--- a/t/40-destructor.t
+++ b/t/40-destructor.t
@@ -2,9 +2,9 @@
use strict;
use warnings;
use Test::More tests => 4;
+use Test::Moose;
-my $destroyed = 0;
-my $demolished = 0;
+my ($destroyed, $demolished);
package Foo;
sub new { bless {}, shift }
@@ -19,11 +19,10 @@ extends 'Foo';
sub DEMOLISH { $demolished++ }
package main;
-{ Foo::Sub->new }
-is($destroyed, 1, "non-Moose destructor called");
-is($demolished, 1, "Moose destructor called");
-Foo::Sub->meta->make_immutable;
-($destroyed, $demolished) = (0, 0);
-{ Foo::Sub->new }
-is($destroyed, 1, "non-Moose destructor called (immutable)");
-is($demolished, 1, "Moose destructor called (immutable)");
+
+with_immutable {
+ ($destroyed, $demolished) = (0, 0);
+ { Foo::Sub->new }
+ is($destroyed, 1, "non-Moose destructor called");
+ is($demolished, 1, "Moose destructor called");
+} 'Foo::Sub';
diff --git a/t/50-buggy-constructor-inlining.t b/t/50-buggy-constructor-inlining.t
index 253ff03..3537e31 100644
--- a/t/50-buggy-constructor-inlining.t
+++ b/t/50-buggy-constructor-inlining.t
@@ -2,7 +2,7 @@
use strict;
use warnings;
use Test::More tests => 6;
-use Test::Moose qw(with_immutable);
+use Test::Moose;
my ($Foo, $Bar, $Baz);
{