X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2F300_immutable%2F010_constructor_is_not_moose.t;fp=t%2F300_immutable%2F010_constructor_is_not_moose.t;h=040a39bd33e79ebfa96da0410fe34c6ededaca92;hb=fde8e43f95fe996fbc2a778aa259feeb04552171;hp=0000000000000000000000000000000000000000;hpb=0bdc9d38dfd3de07aad929f6629f8fa65d434c27;p=gitmo%2FMouse.git diff --git a/t/300_immutable/010_constructor_is_not_moose.t b/t/300_immutable/010_constructor_is_not_moose.t new file mode 100644 index 0000000..040a39b --- /dev/null +++ b/t/300_immutable/010_constructor_is_not_moose.t @@ -0,0 +1,108 @@ +#!/usr/bin/perl +# This is automatically generated by author/import-moose-test.pl. +# DO NOT EDIT THIS FILE. ANY CHANGES WILL BE LOST!!! +use t::lib::MooseCompat; + +use strict; +use warnings; + +use Test::More; + +use Test::Requires { + 'Test::Output' => '0.01', # skip all if not installed +}; + +{ + package NotMoose; + + sub new { + my $class = shift; + + return bless { not_moose => 1 }, $class; + } +} + +{ + package Foo; + use Mouse; + + extends 'NotMoose'; + + ::stderr_like( + sub { Foo->meta->make_immutable }, + qr/\QNot inlining 'new' for Foo since it is not inheriting the default Mouse::Object::new\E\s+\QIf you are certain you don't need to inline your constructor, specify inline_constructor => 0 in your call to Foo->meta->make_immutable/, + 'got a warning that Foo may not have an inlined constructor' + ); +} + +is( + Foo->meta->find_method_by_name('new')->body, + NotMoose->can('new'), + 'Foo->new is inherited from NotMoose' +); + +{ + package Bar; + use Mouse; + + extends 'NotMoose'; + + ::stderr_is( + sub { Bar->meta->make_immutable( replace_constructor => 1 ) }, + q{}, + 'no warning when replace_constructor is true' + ); +} + +is( + Bar->meta->find_method_by_name('new')->package_name, + 'Bar', + 'Bar->new is inlined, and not inherited from NotMoose' +); + +{ + package Baz; + use Mouse; + + Baz->meta->make_immutable; +} + +{ + package Quux; + use Mouse; + + extends 'Baz'; + + ::stderr_is( + sub { Quux->meta->make_immutable }, + q{}, + 'no warning when inheriting from a class that has already made itself immutable' + ); +} + +{ + package My::Constructor; + use base 'Mouse::Meta::Method'; +} + +{ + package CustomCons; + use Mouse; + + CustomCons->meta->make_immutable( constructor_class => 'My::Constructor' ); +} + +{ + package Subclass; + use Mouse; + + extends 'CustomCons'; + + ::stderr_is( + sub { Subclass->meta->make_immutable }, + q{}, + 'no warning when inheriting from a class that has already made itself immutable' + ); +} + +done_testing;