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