Commit | Line | Data |
fb1e11d5 |
1 | #!/usr/bin/perl |
2 | |
3 | use strict; |
4 | use warnings; |
5 | |
6 | use Test::More no_plan => 1; |
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 | package Role::Bar; |
20 | use Moose::Role; |
21 | |
22 | package Role::ExcludesFoo; |
23 | use Moose::Role; |
24 | excludes 'Role::Foo'; |
25 | |
26 | package Role::DoesExcludesFoo; |
27 | use Moose::Role; |
28 | with 'Role::ExcludesFoo'; |
29 | |
30 | package Role::DoesFoo; |
31 | use Moose::Role; |
32 | with 'Role::Foo'; |
33 | } |
34 | |
1c9db35c |
35 | ok(Role::ExcludesFoo->meta->excludes_role('Role::Foo'), '... got the right exclusions'); |
36 | ok(Role::DoesExcludesFoo->meta->excludes_role('Role::Foo'), '... got the right exclusions'); |
37 | |
fb1e11d5 |
38 | # test simple exclusion |
39 | dies_ok { |
40 | Moose::Meta::Role::Application::RoleSummation->new->apply( |
41 | Moose::Meta::Role::Composite->new( |
42 | roles => [ |
43 | Role::Foo->meta, |
44 | Role::ExcludesFoo->meta, |
45 | ] |
46 | ) |
47 | ); |
48 | } '... this fails as expected'; |
49 | |
50 | # test no conflicts |
51 | { |
52 | my $c = Moose::Meta::Role::Composite->new( |
53 | roles => [ |
54 | Role::Foo->meta, |
55 | Role::Bar->meta, |
56 | ] |
57 | ); |
58 | isa_ok($c, 'Moose::Meta::Role::Composite'); |
59 | |
60 | is($c->name, 'Role::Foo|Role::Bar', '... got the composite role name'); |
61 | |
62 | lives_ok { |
63 | Moose::Meta::Role::Application::RoleSummation->new->apply($c); |
64 | } '... this lives as expected'; |
65 | } |
66 | |
67 | # test no conflicts w/exclusion |
68 | { |
69 | my $c = Moose::Meta::Role::Composite->new( |
70 | roles => [ |
71 | Role::Bar->meta, |
72 | Role::ExcludesFoo->meta, |
73 | ] |
74 | ); |
75 | isa_ok($c, 'Moose::Meta::Role::Composite'); |
76 | |
77 | is($c->name, 'Role::Bar|Role::ExcludesFoo', '... got the composite role name'); |
78 | |
79 | lives_ok { |
80 | Moose::Meta::Role::Application::RoleSummation->new->apply($c); |
81 | } '... this lives as expected'; |
82 | |
83 | is_deeply([$c->get_excluded_roles_list], ['Role::Foo'], '... has excluded roles'); |
84 | } |
85 | |
86 | |
87 | # test conflict with an "inherited" exclusion |
88 | dies_ok { |
89 | Moose::Meta::Role::Application::RoleSummation->new->apply( |
90 | Moose::Meta::Role::Composite->new( |
91 | roles => [ |
92 | Role::Foo->meta, |
93 | Role::DoesExcludesFoo->meta, |
94 | ] |
95 | ) |
96 | ); |
97 | |
98 | } '... this fails as expected'; |
99 | |
100 | # test conflict with an "inherited" exclusion of an "inherited" role |
101 | dies_ok { |
102 | Moose::Meta::Role::Application::RoleSummation->new->apply( |
103 | Moose::Meta::Role::Composite->new( |
104 | roles => [ |
105 | Role::DoesFoo->meta, |
106 | Role::DoesExcludesFoo->meta, |
107 | ] |
108 | ) |
109 | ); |
110 | } '... this fails as expected'; |
111 | |
112 | |