Make Test::Output optional again
[gitmo/Moose.git] / t / 300_immutable / 010_constructor_is_not_moose.t
1 #!/usr/bin/perl
2
3 use strict;
4 use warnings;
5
6 use Test::More;
7 BEGIN {
8     eval "use Test::Output;";
9     plan skip_all => "Test::Output is required for this test" if $@;
10     plan tests => 6;
11 }
12
13 {
14     package NotMoose;
15
16     sub new {
17         my $class = shift;
18
19         return bless { not_moose => 1 }, $class;
20     }
21 }
22
23 {
24     package Foo;
25     use Moose;
26
27     extends 'NotMoose';
28
29     ::stderr_is(
30         sub { Foo->meta->make_immutable },
31         "Not inlining 'new' for Foo since it is not inheriting the default Moose::Object::new\nIf you are certain you don't need to inline your constructor, specify inline_constructor => 0 in your call to Foo->meta->make_immutable\n",
32         'got a warning that Foo may not have an inlined constructor'
33     );
34 }
35
36 is(
37     Foo->meta->find_method_by_name('new')->body,
38     NotMoose->can('new'),
39     'Foo->new is inherited from NotMoose'
40 );
41
42 {
43     package Bar;
44     use Moose;
45
46     extends 'NotMoose';
47
48     ::stderr_is(
49         sub { Bar->meta->make_immutable( replace_constructor => 1 ) },
50         q{},
51         'no warning when replace_constructor is true'
52     );
53 }
54
55 is(
56     Bar->meta->find_method_by_name('new')->package_name,
57    'Bar',
58     'Bar->new is inlined, and not inherited from NotMoose'
59 );
60
61 {
62     package Baz;
63     use Moose;
64
65     Baz->meta->make_immutable;
66 }
67
68 {
69     package Quux;
70     use Moose;
71
72     extends 'Baz';
73
74     ::stderr_is(
75         sub { Quux->meta->make_immutable },
76         q{},
77         'no warning when inheriting from a class that has already made itself immutable'
78     );
79 }
80
81 {
82     package My::Constructor;
83     use base 'Moose::Meta::Method::Constructor';
84 }
85
86 {
87     package CustomCons;
88     use Moose;
89
90     CustomCons->meta->make_immutable( constructor_class => 'My::Constructor' );
91 }
92
93 {
94     package Subclass;
95     use Moose;
96
97     extends 'CustomCons';
98
99     ::stderr_is(
100         sub { Subclass->meta->make_immutable },
101         q{},
102         'no warning when inheriting from a class that has already made itself immutable'
103     );
104 }