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