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