Convert all tests to done_testing.
[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 }
11
12 {
13     package NotMoose;
14
15     sub new {
16         my $class = shift;
17
18         return bless { not_moose => 1 }, $class;
19     }
20 }
21
22 {
23     package Foo;
24     use Moose;
25
26     extends 'NotMoose';
27
28     ::stderr_like(
29         sub { Foo->meta->make_immutable },
30         qr/\QNot inlining 'new' for Foo since it is not inheriting the default Moose::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/,
31         'got a warning that Foo may not have an inlined constructor'
32     );
33 }
34
35 is(
36     Foo->meta->find_method_by_name('new')->body,
37     NotMoose->can('new'),
38     'Foo->new is inherited from NotMoose'
39 );
40
41 {
42     package Bar;
43     use Moose;
44
45     extends 'NotMoose';
46
47     ::stderr_is(
48         sub { Bar->meta->make_immutable( replace_constructor => 1 ) },
49         q{},
50         'no warning when replace_constructor is true'
51     );
52 }
53
54 is(
55     Bar->meta->find_method_by_name('new')->package_name,
56    'Bar',
57     'Bar->new is inlined, and not inherited from NotMoose'
58 );
59
60 {
61     package Baz;
62     use Moose;
63
64     Baz->meta->make_immutable;
65 }
66
67 {
68     package Quux;
69     use Moose;
70
71     extends 'Baz';
72
73     ::stderr_is(
74         sub { Quux->meta->make_immutable },
75         q{},
76         'no warning when inheriting from a class that has already made itself immutable'
77     );
78 }
79
80 {
81     package My::Constructor;
82     use base 'Moose::Meta::Method::Constructor';
83 }
84
85 {
86     package CustomCons;
87     use Moose;
88
89     CustomCons->meta->make_immutable( constructor_class => 'My::Constructor' );
90 }
91
92 {
93     package Subclass;
94     use Moose;
95
96     extends 'CustomCons';
97
98     ::stderr_is(
99         sub { Subclass->meta->make_immutable },
100         q{},
101         'no warning when inheriting from a class that has already made itself immutable'
102     );
103 }
104
105 done_testing;