Make some C symbols static
[gitmo/Mouse.git] / Moose-t-failing / 030_roles / 011_overriding.t
CommitLineData
67199842 1#!/usr/bin/perl
c47cf415 2# This is automatically generated by author/import-moose-test.pl.
3# DO NOT EDIT THIS FILE. ANY CHANGES WILL BE LOST!!!
4use t::lib::MooseCompat;
67199842 5
6use strict;
7use warnings;
8
c47cf415 9use Test::More;
10$TODO = q{Mouse is not yet completed};
67199842 11use Test::Exception;
12
13
c2d7552a 14{
67199842 15 # test no conflicts here
16 package Role::A;
17 use Mouse::Role;
18
19 sub bar { 'Role::A::bar' }
20
21 package Role::B;
22 use Mouse::Role;
23
24 sub xxy { 'Role::B::xxy' }
25
26 package Role::C;
27 use Mouse::Role;
c2d7552a 28
67199842 29 ::lives_ok {
30 with qw(Role::A Role::B); # no conflict here
31 } "define role C";
32
33 sub foo { 'Role::C::foo' }
34 sub zot { 'Role::C::zot' }
35
36 package Class::A;
37 use Mouse;
38
39 ::lives_ok {
40 with qw(Role::C);
41 } "define class A";
c2d7552a 42
67199842 43 sub zot { 'Class::A::zot' }
44}
45
46can_ok( Class::A->new, qw(foo bar xxy zot) );
47
48is( Class::A->new->foo, "Role::C::foo", "... got the right foo method" );
49is( Class::A->new->zot, "Class::A::zot", "... got the right zot method" );
50is( Class::A->new->bar, "Role::A::bar", "... got the right bar method" );
51is( Class::A->new->xxy, "Role::B::xxy", "... got the right xxy method" );
52
53{
54 # check that when a role is added to another role
c2d7552a 55 # and they conflict and the method they conflict
56 # with is then required.
57
67199842 58 package Role::A::Conflict;
59 use Mouse::Role;
c2d7552a 60
67199842 61 with 'Role::A';
c2d7552a 62
67199842 63 sub bar { 'Role::A::Conflict::bar' }
c2d7552a 64
67199842 65 package Class::A::Conflict;
66 use Mouse;
c2d7552a 67
67199842 68 ::throws_ok {
69 with 'Role::A::Conflict';
c2d7552a 70 } qr/Due to a method name conflict in roles 'Role::A' and 'Role::A::Conflict', the method 'bar' must be implemented or excluded by 'Class::A::Conflict'/, '... did not fufill the requirement of &bar method';
71
67199842 72 package Class::A::Resolved;
73 use Mouse;
c2d7552a 74
67199842 75 ::lives_ok {
76 with 'Role::A::Conflict';
c2d7552a 77 } '... did fufill the requirement of &bar method';
78
67199842 79 sub bar { 'Class::A::Resolved::bar' }
80}
81
82ok(Role::A::Conflict->meta->requires_method('bar'), '... Role::A::Conflict created the bar requirement');
83
84can_ok( Class::A::Resolved->new, qw(bar) );
85
86is( Class::A::Resolved->new->bar, 'Class::A::Resolved::bar', "... got the right bar method" );
87
88{
89 # check that when two roles are composed, they conflict
90 # but the composing role can resolve that conflict
c2d7552a 91
67199842 92 package Role::D;
93 use Mouse::Role;
94
95 sub foo { 'Role::D::foo' }
c2d7552a 96 sub bar { 'Role::D::bar' }
67199842 97
98 package Role::E;
99 use Mouse::Role;
100
101 sub foo { 'Role::E::foo' }
102 sub xxy { 'Role::E::xxy' }
103
104 package Role::F;
105 use Mouse::Role;
106
107 ::lives_ok {
108 with qw(Role::D Role::E); # conflict between 'foo's here
109 } "define role Role::F";
c2d7552a 110
67199842 111 sub foo { 'Role::F::foo' }
c2d7552a 112 sub zot { 'Role::F::zot' }
113
67199842 114 package Class::B;
115 use Mouse;
c2d7552a 116
67199842 117 ::lives_ok {
118 with qw(Role::F);
119 } "define class Class::B";
c2d7552a 120
67199842 121 sub zot { 'Class::B::zot' }
122}
123
124can_ok( Class::B->new, qw(foo bar xxy zot) );
125
126is( Class::B->new->foo, "Role::F::foo", "... got the &foo method okay" );
127is( Class::B->new->zot, "Class::B::zot", "... got the &zot method okay" );
128is( Class::B->new->bar, "Role::D::bar", "... got the &bar method okay" );
129is( Class::B->new->xxy, "Role::E::xxy", "... got the &xxy method okay" );
130
131ok(!Role::F->meta->requires_method('foo'), '... Role::F fufilled the &foo requirement');
132
133{
134 # check that a conflict can be resolved
c2d7552a 135 # by a role, but also new ones can be
67199842 136 # created just as easily ...
c2d7552a 137
67199842 138 package Role::D::And::E::Conflict;
139 use Mouse::Role;
140
141 ::lives_ok {
142 with qw(Role::D Role::E); # conflict between 'foo's here
143 } "... define role Role::D::And::E::Conflict";
c2d7552a 144
67199842 145 sub foo { 'Role::D::And::E::Conflict::foo' } # this overrides ...
c2d7552a 146
147 # but these conflict
148 sub xxy { 'Role::D::And::E::Conflict::xxy' }
149 sub bar { 'Role::D::And::E::Conflict::bar' }
67199842 150
151}
152
153ok(!Role::D::And::E::Conflict->meta->requires_method('foo'), '... Role::D::And::E::Conflict fufilled the &foo requirement');
154ok(Role::D::And::E::Conflict->meta->requires_method('xxy'), '... Role::D::And::E::Conflict adds the &xxy requirement');
155ok(Role::D::And::E::Conflict->meta->requires_method('bar'), '... Role::D::And::E::Conflict adds the &bar requirement');
156
157{
158 # conflict propagation
c2d7552a 159
67199842 160 package Role::H;
161 use Mouse::Role;
162
163 sub foo { 'Role::H::foo' }
c2d7552a 164 sub bar { 'Role::H::bar' }
67199842 165
166 package Role::J;
167 use Mouse::Role;
168
169 sub foo { 'Role::J::foo' }
170 sub xxy { 'Role::J::xxy' }
171
172 package Role::I;
173 use Mouse::Role;
174
175 ::lives_ok {
176 with qw(Role::J Role::H); # conflict between 'foo's here
177 } "define role Role::I";
c2d7552a 178
67199842 179 sub zot { 'Role::I::zot' }
180 sub zzy { 'Role::I::zzy' }
181
182 package Class::C;
183 use Mouse;
c2d7552a 184
67199842 185 ::throws_ok {
186 with qw(Role::I);
c2d7552a 187 } qr/Due to a method name conflict in roles 'Role::H' and 'Role::J', the method 'foo' must be implemented or excluded by 'Class::C'/, "defining class Class::C fails";
67199842 188
189 sub zot { 'Class::C::zot' }
190
191 package Class::E;
192 use Mouse;
193
194 ::lives_ok {
195 with qw(Role::I);
c2d7552a 196 } "resolved with method";
67199842 197
198 sub foo { 'Class::E::foo' }
c2d7552a 199 sub zot { 'Class::E::zot' }
67199842 200}
201
202can_ok( Class::E->new, qw(foo bar xxy zot) );
203
204is( Class::E->new->foo, "Class::E::foo", "... got the right &foo method" );
205is( Class::E->new->zot, "Class::E::zot", "... got the right &zot method" );
206is( Class::E->new->bar, "Role::H::bar", "... got the right &bar method" );
207is( Class::E->new->xxy, "Role::J::xxy", "... got the right &xxy method" );
208
209ok(Role::I->meta->requires_method('foo'), '... Role::I still have the &foo requirement');
210
211{
212 lives_ok {
213 package Class::D;
214 use Mouse;
215
216 has foo => ( default => __PACKAGE__ . "::foo", is => "rw" );
217
218 sub zot { 'Class::D::zot' }
219
220 with qw(Role::I);
221
222 } "resolved with attr";
223
224 can_ok( Class::D->new, qw(foo bar xxy zot) );
225 is( eval { Class::D->new->bar }, "Role::H::bar", "bar" );
226 is( eval { Class::D->new->zzy }, "Role::I::zzy", "zzy" );
227
228 is( eval { Class::D->new->foo }, "Class::D::foo", "foo" );
229 is( eval { Class::D->new->zot }, "Class::D::zot", "zot" );
230
231}
232
c47cf415 233done_testing;