refactor in progress, beware (still passing all my tests though :P)
[gitmo/Moose.git] / t / 030_roles / 021_role_composite_exlcusion.t
CommitLineData
fb1e11d5 1#!/usr/bin/perl
2
3use strict;
4use warnings;
5
6use Test::More no_plan => 1;
7use Test::Exception;
8
9BEGIN {
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
35# test simple exclusion
36dies_ok {
37 Moose::Meta::Role::Application::RoleSummation->new->apply(
38 Moose::Meta::Role::Composite->new(
39 roles => [
40 Role::Foo->meta,
41 Role::ExcludesFoo->meta,
42 ]
43 )
44 );
45} '... this fails as expected';
46
47# test no conflicts
48{
49 my $c = Moose::Meta::Role::Composite->new(
50 roles => [
51 Role::Foo->meta,
52 Role::Bar->meta,
53 ]
54 );
55 isa_ok($c, 'Moose::Meta::Role::Composite');
56
57 is($c->name, 'Role::Foo|Role::Bar', '... got the composite role name');
58
59 lives_ok {
60 Moose::Meta::Role::Application::RoleSummation->new->apply($c);
61 } '... this lives as expected';
62}
63
64# test no conflicts w/exclusion
65{
66 my $c = Moose::Meta::Role::Composite->new(
67 roles => [
68 Role::Bar->meta,
69 Role::ExcludesFoo->meta,
70 ]
71 );
72 isa_ok($c, 'Moose::Meta::Role::Composite');
73
74 is($c->name, 'Role::Bar|Role::ExcludesFoo', '... got the composite role name');
75
76 lives_ok {
77 Moose::Meta::Role::Application::RoleSummation->new->apply($c);
78 } '... this lives as expected';
79
80 is_deeply([$c->get_excluded_roles_list], ['Role::Foo'], '... has excluded roles');
81}
82
83
84# test conflict with an "inherited" exclusion
85dies_ok {
86 Moose::Meta::Role::Application::RoleSummation->new->apply(
87 Moose::Meta::Role::Composite->new(
88 roles => [
89 Role::Foo->meta,
90 Role::DoesExcludesFoo->meta,
91 ]
92 )
93 );
94
95} '... this fails as expected';
96
97# test conflict with an "inherited" exclusion of an "inherited" role
98dies_ok {
99 Moose::Meta::Role::Application::RoleSummation->new->apply(
100 Moose::Meta::Role::Composite->new(
101 roles => [
102 Role::DoesFoo->meta,
103 Role::DoesExcludesFoo->meta,
104 ]
105 )
106 );
107} '... this fails as expected';
108
109