Commit | Line | Data |
67199842 |
1 | #!/usr/bin/perl |
2 | |
3 | use strict; |
4 | use warnings; |
5 | |
6 | use Test::More tests => 7; |
7 | use Test::Exception; |
8 | |
9 | use Mouse::Meta::Role::Application::RoleSummation; |
10 | use Mouse::Meta::Role::Composite; |
11 | |
12 | { |
13 | package Role::Foo; |
6cfa1e5e |
14 | use Mouse::Role; |
67199842 |
15 | has 'foo' => (is => 'rw'); |
6cfa1e5e |
16 | |
67199842 |
17 | package Role::Bar; |
18 | use Mouse::Role; |
19 | has 'bar' => (is => 'rw'); |
6cfa1e5e |
20 | |
67199842 |
21 | package Role::FooConflict; |
6cfa1e5e |
22 | use Mouse::Role; |
67199842 |
23 | has 'foo' => (is => 'rw'); |
6cfa1e5e |
24 | |
67199842 |
25 | package Role::BarConflict; |
26 | use Mouse::Role; |
27 | has 'bar' => (is => 'rw'); |
6cfa1e5e |
28 | |
67199842 |
29 | package Role::AnotherFooConflict; |
6cfa1e5e |
30 | use Mouse::Role; |
67199842 |
31 | with 'Role::FooConflict'; |
32 | } |
33 | |
34 | # test simple attributes |
35 | { |
36 | my $c = Mouse::Meta::Role::Composite->new( |
37 | roles => [ |
38 | Role::Foo->meta, |
39 | Role::Bar->meta, |
40 | ] |
41 | ); |
42 | isa_ok($c, 'Mouse::Meta::Role::Composite'); |
43 | |
6cfa1e5e |
44 | is($c->name, 'Role::Foo|Role::Bar', '... got the composite role name'); |
45 | |
67199842 |
46 | lives_ok { |
47 | Mouse::Meta::Role::Application::RoleSummation->new->apply($c); |
6cfa1e5e |
48 | } '... this succeeds as expected'; |
49 | |
67199842 |
50 | is_deeply( |
51 | [ sort $c->get_attribute_list ], |
52 | [ 'bar', 'foo' ], |
53 | '... got the right list of attributes' |
54 | ); |
55 | } |
56 | |
57 | # test simple conflict |
58 | dies_ok { |
59 | Mouse::Meta::Role::Application::RoleSummation->new->apply( |
60 | Mouse::Meta::Role::Composite->new( |
61 | roles => [ |
62 | Role::Foo->meta, |
63 | Role::FooConflict->meta, |
64 | ] |
65 | ) |
66 | ); |
67 | } '... this fails as expected'; |
68 | |
69 | # test complex conflict |
70 | dies_ok { |
71 | Mouse::Meta::Role::Application::RoleSummation->new->apply( |
72 | Mouse::Meta::Role::Composite->new( |
73 | roles => [ |
74 | Role::Foo->meta, |
6cfa1e5e |
75 | Role::Bar->meta, |
67199842 |
76 | Role::FooConflict->meta, |
6cfa1e5e |
77 | Role::BarConflict->meta, |
67199842 |
78 | ] |
79 | ) |
80 | ); |
81 | } '... this fails as expected'; |
82 | |
83 | # test simple conflict |
84 | dies_ok { |
85 | Mouse::Meta::Role::Application::RoleSummation->new->apply( |
86 | Mouse::Meta::Role::Composite->new( |
87 | roles => [ |
88 | Role::Foo->meta, |
89 | Role::AnotherFooConflict->meta, |
90 | ] |
91 | ) |
92 | ); |
93 | } '... this fails as expected'; |
94 | |