* role exclusion and aliasiing now works in composite roles too
[gitmo/Moose.git] / t / 030_roles / 024_role_composition_methods.t
1 #!/usr/bin/perl
2
3 use strict;
4 use warnings;
5
6 use Test::More tests => 22;
7 use Test::Exception;
8
9 BEGIN {
10     use_ok('Moose');
11     use_ok('Moose::Meta::Role::Application::RoleSummation');    
12     use_ok('Moose::Meta::Role::Composite');
13 }
14
15 {
16     package Role::Foo;
17     use Moose::Role;
18     
19     sub foo { 'Role::Foo::foo' }    
20     
21     package Role::Bar;
22     use Moose::Role;
23
24     sub bar { 'Role::Bar::bar' }
25     
26     package Role::FooConflict;
27     use Moose::Role;    
28     
29     sub foo { 'Role::FooConflict::foo' }    
30     
31     package Role::BarConflict;
32     use Moose::Role;
33     
34     sub bar { 'Role::BarConflict::bar' }
35     
36     package Role::AnotherFooConflict;
37     use Moose::Role;    
38     with 'Role::FooConflict';
39
40     sub baz { 'Role::AnotherFooConflict::baz' }
41 }
42
43 # test simple attributes
44 {
45     my $c = Moose::Meta::Role::Composite->new(
46         roles => [
47             Role::Foo->meta,
48             Role::Bar->meta,
49         ]
50     );
51     isa_ok($c, 'Moose::Meta::Role::Composite');
52
53     is($c->name, 'Role::Foo|Role::Bar', '... got the composite role name');    
54     
55     lives_ok {
56         Moose::Meta::Role::Application::RoleSummation->new->apply($c);
57     } '... this succeeds as expected';    
58     
59     is_deeply(
60         [ sort $c->get_method_list ],
61         [ 'bar', 'foo' ],
62         '... got the right list of methods'
63     );
64 }
65
66 # test simple conflict
67 {
68     my $c = Moose::Meta::Role::Composite->new(
69         roles => [
70             Role::Foo->meta,
71             Role::FooConflict->meta,
72         ]
73     );
74     isa_ok($c, 'Moose::Meta::Role::Composite');
75
76     is($c->name, 'Role::Foo|Role::FooConflict', '... got the composite role name');    
77     
78     lives_ok {
79         Moose::Meta::Role::Application::RoleSummation->new->apply($c);
80     } '... this succeeds as expected';    
81     
82     is_deeply(
83         [ sort $c->get_method_list ],
84         [],
85         '... got the right list of methods'
86     );    
87     
88     is_deeply(
89         [ sort $c->get_required_method_list ],
90         [ 'foo' ],
91         '... got the right list of required methods'
92     );    
93 }
94
95 # test complex conflict
96 {
97     my $c = Moose::Meta::Role::Composite->new(
98         roles => [
99             Role::Foo->meta,
100             Role::Bar->meta,            
101             Role::FooConflict->meta,
102             Role::BarConflict->meta,            
103         ]
104     );
105     isa_ok($c, 'Moose::Meta::Role::Composite');
106
107     is($c->name, 'Role::Foo|Role::Bar|Role::FooConflict|Role::BarConflict', '... got the composite role name');    
108
109     lives_ok {
110         Moose::Meta::Role::Application::RoleSummation->new->apply($c);
111     } '... this succeeds as expected';
112
113     is_deeply(
114         [ sort $c->get_method_list ],
115         [],
116         '... got the right list of methods'
117     );    
118     
119     is_deeply(
120         [ sort $c->get_required_method_list ],
121         [ 'bar', 'foo' ],
122         '... got the right list of required methods'
123     );    
124 }
125
126 # test simple conflict
127 {
128     my $c = Moose::Meta::Role::Composite->new(
129         roles => [
130             Role::Foo->meta,
131             Role::AnotherFooConflict->meta,
132         ]
133     );
134     isa_ok($c, 'Moose::Meta::Role::Composite');
135
136     is($c->name, 'Role::Foo|Role::AnotherFooConflict', '... got the composite role name');    
137     
138     lives_ok {
139         Moose::Meta::Role::Application::RoleSummation->new->apply($c);
140     } '... this succeeds as expected';    
141     
142     is_deeply(
143         [ sort $c->get_method_list ],
144         [ 'baz' ],
145         '... got the right list of methods'
146     );    
147     
148     is_deeply(
149         [ sort $c->get_required_method_list ],
150         [ 'foo' ],
151         '... got the right list of required methods'
152     );    
153 }
154