summaryrefslogtreecommitdiffstats
path: root/t/buggy-constructors.t
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2013-09-04 19:38:21 -0400
committerJesse Luehrs <doy@tozt.net>2013-09-04 19:47:11 -0400
commit8bf5e6931a1bd96df0cdb1ceb94bbb3e578a8126 (patch)
tree2e659a8f07ea1cca3091a9c0578bbd8e53c20c11 /t/buggy-constructors.t
parent8e0b4f219f2d8d94cb6937ef47168ac5fac03cd9 (diff)
downloadmoosex-nonmoose-8bf5e6931a1bd96df0cdb1ceb94bbb3e578a8126.tar.gz
moosex-nonmoose-8bf5e6931a1bd96df0cdb1ceb94bbb3e578a8126.zip
packaging
Diffstat (limited to 't/buggy-constructors.t')
-rw-r--r--t/buggy-constructors.t94
1 files changed, 94 insertions, 0 deletions
diff --git a/t/buggy-constructors.t b/t/buggy-constructors.t
new file mode 100644
index 0000000..bbe5127
--- /dev/null
+++ b/t/buggy-constructors.t
@@ -0,0 +1,94 @@
+#!/usr/bin/env perl
+use strict;
+use warnings;
+use Test::More;
+use Test::Fatal;
+use Test::Moose;
+
+{
+ package Foo;
+
+ sub new { bless {}, shift }
+}
+
+{
+ package Foo::Sub;
+ use Moose;
+ use MooseX::NonMoose;
+
+ extends 'Foo';
+}
+
+with_immutable {
+ my $foo;
+ is(exception { $foo = Foo::Sub->new }, undef,
+ "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;
+ is(exception { $foo = BadFoo::Sub->new }, undef,
+ "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;
+ like(exception { $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;
+ like(exception { $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;