diff options
author | Jesse Luehrs <doy@tozt.net> | 2010-06-15 01:36:37 -0500 |
---|---|---|
committer | Jesse Luehrs <doy@tozt.net> | 2010-06-15 01:36:37 -0500 |
commit | 60c5f48aff6a579ce22bd4b4245f7be346609901 (patch) | |
tree | 7025b94a0470cef60d9c3694d0dbf247f5b30aaa /t/51-buggy-constructors.t | |
parent | 571bfa3b91ff5567338948776b6fce84d3ede09e (diff) | |
download | moosex-nonmoose-60c5f48aff6a579ce22bd4b4245f7be346609901.tar.gz moosex-nonmoose-60c5f48aff6a579ce22bd4b4245f7be346609901.zip |
convert to new dzil stuff
Diffstat (limited to 't/51-buggy-constructors.t')
-rw-r--r-- | t/51-buggy-constructors.t | 98 |
1 files changed, 98 insertions, 0 deletions
diff --git a/t/51-buggy-constructors.t b/t/51-buggy-constructors.t new file mode 100644 index 0000000..066498d --- /dev/null +++ b/t/51-buggy-constructors.t @@ -0,0 +1,98 @@ +#!/usr/bin/env perl +use strict; +use warnings; +use Test::More; +use Test::Exception; +use Test::Moose; + +{ + package Foo; + + sub new { bless {}, shift } +} + +{ + package Foo::Sub; + use Moose; + use MooseX::NonMoose; + + extends 'Foo'; +} + +with_immutable { + my $foo; + lives_ok { + $foo = Foo::Sub->new; + } "subclassing nonmoose classes with correct constructors works"; + isa_ok($foo, 'Foo'); + isa_ok($foo, 'Foo::Sub'); +} 'Foo::Sub'; + +{ + package BadFoo; + + sub new { bless {} } +} + +{ + package BadFoo::Sub; + use Moose; + use MooseX::NonMoose; + + extends 'BadFoo'; +} + +with_immutable { + my $foo; + lives_ok { + $foo = BadFoo::Sub->new; + } "subclassing nonmoose classes with incorrect constructors works"; + isa_ok($foo, 'BadFoo'); + isa_ok($foo, 'BadFoo::Sub'); +} 'BadFoo::Sub'; + +{ + package BadFoo2; + + sub new { {} } +} + +{ + package BadFoo2::Sub; + use Moose; + use MooseX::NonMoose; + + extends 'BadFoo2'; +} + +with_immutable { + my $foo; + throws_ok { + $foo = BadFoo2::Sub->new; + } qr/\QThe constructor for BadFoo2 did not return a blessed instance/, + "subclassing nonmoose classes with incorrect constructors dies properly"; +} 'BadFoo2::Sub'; + +{ + package BadFoo3; + + sub new { bless {}, 'Something::Else::Entirely' } +} + +{ + package BadFoo3::Sub; + use Moose; + use MooseX::NonMoose; + + extends 'BadFoo3'; +} + +with_immutable { + my $foo; + throws_ok { + $foo = BadFoo3::Sub->new; + } qr/\QThe constructor for BadFoo3 returned an object whose class is not a parent of BadFoo3::Sub/, + "subclassing nonmoose classes with incorrect constructors dies properly"; +} 'BadFoo3::Sub'; + +done_testing; |