Check for lazy_build when assign default default for native trait.
[gitmo/Moose.git] / t / 010_basics / 030_deprecations.t
1 use strict;
2 use warnings;
3
4 use Test::Exception;
5 use Test::More;
6
7 use Test::Requires {
8     'Test::Output' => '0.01',
9 };
10
11 {
12     package Role;
13
14     use Moose::Role;
15
16     sub thing { }
17 }
18
19 {
20     package Foo;
21
22     use Moose;
23
24     ::stderr_like{ has foo => (
25             traits => ['String'],
26             is     => 'ro',
27             isa    => 'Str',
28         );
29         }
30         qr/\QAllowing a native trait to automatically supply a default is deprecated/,
31         'Not providing a default for native String trait warns';
32
33     ::stderr_like{ has bar => (
34             traits  => ['String'],
35             isa     => 'Str',
36             default => q{},
37         );
38         }
39         qr/\QAllowing a native trait to automatically supply a value for "is" is deprecated/,
40         'Not providing a value for is with native String trait warns';
41
42     ::stderr_like{ with 'Role' =>
43             { excludes => ['thing'], alias => { thing => 'thing2' } };
44         }
45         qr/\QThe alias and excludes options for role application have been renamed -alias and -excludes/,
46         'passing excludes or alias with a leading dash warns';
47     ::ok(
48         !Foo->meta->has_method('thing'),
49         'thing method is excluded from role application'
50     );
51     ::ok(
52         Foo->meta->has_method('thing2'),
53         'thing2 method is created as alias in role application'
54     );
55 }
56
57 {
58     package Pack1;
59
60     use Moose;
61
62     ::stderr_is{ has foo => (
63             traits  => ['String'],
64             reader  => '_foo',
65             isa     => 'Str',
66             default => q{},
67         );
68         } q{},
69         'Providing a reader for a String trait avoids default is warning';
70
71     ::lives_and{ ::stderr_is{ has bar => (
72                 traits  => ['String'],
73                 is      => 'ro',
74                 isa     => 'Str',
75                 builder => '_build_foo',
76             );
77             } q{},
78         'Providing a builder for a String trait avoids default default warning';
79         } 'Providing a builder for a String trait does not die';
80
81     sub _build_foo { }
82 }
83
84 {
85     package Pack2;
86
87     use Moose;
88
89     ::stderr_is{ has foo => (
90             traits  => ['String'],
91             writer  => '_foo',
92             isa     => 'Str',
93             default => q{},
94         );
95         } q{},
96         'Providing a writer for a String trait avoids default is warning';
97
98     ::stderr_is{ has bar => (
99             traits   => ['String'],
100             is       => 'ro',
101             isa      => 'Str',
102             required => 1,
103         );
104         } q{},
105         'Making a String trait required avoids default default warning';
106
107     sub _build_foo { }
108 }
109
110 {
111     package Pack3;
112
113     use Moose;
114
115     ::stderr_is{ has foo => (
116             traits   => ['String'],
117             accessor => '_foo',
118             isa      => 'Str',
119             default  => q{},
120         );
121         } q{},
122         'Providing an accessor for a String trait avoids default is warning';
123
124     ::lives_and{ ::stderr_is{ has bar => (
125                 traits     => ['String'],
126                 is         => 'ro',
127                 isa        => 'Str',
128                 lazy_build => 1,
129             );
130             } q{},
131         'Making a String trait lazy_build avoids default default warning';
132         } 'Providing lazy_build for a String trait lives';
133
134     sub _build_bar { }
135 }
136
137 done_testing;
138