Mouse::Role improved
[gitmo/Mouse.git] / t / 030_roles / failing / 021_role_composite_exclusion.t
CommitLineData
67199842 1#!/usr/bin/perl
2
3use strict;
4use warnings;
5
6use Test::More tests => 12;
7use Test::Exception;
8
9use Mouse::Meta::Role::Application::RoleSummation;
10use Mouse::Meta::Role::Composite;
11
12{
13 package Role::Foo;
14 use Mouse::Role;
6cfa1e5e 15
67199842 16 package Role::Bar;
17 use Mouse::Role;
6cfa1e5e 18
67199842 19 package Role::ExcludesFoo;
20 use Mouse::Role;
21 excludes 'Role::Foo';
6cfa1e5e 22
67199842 23 package Role::DoesExcludesFoo;
24 use Mouse::Role;
6cfa1e5e 25 with 'Role::ExcludesFoo';
26
67199842 27 package Role::DoesFoo;
28 use Mouse::Role;
6cfa1e5e 29 with 'Role::Foo';
67199842 30}
31
32ok(Role::ExcludesFoo->meta->excludes_role('Role::Foo'), '... got the right exclusions');
33ok(Role::DoesExcludesFoo->meta->excludes_role('Role::Foo'), '... got the right exclusions');
34
35# test simple exclusion
36dies_ok {
37 Mouse::Meta::Role::Application::RoleSummation->new->apply(
38 Mouse::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 = Mouse::Meta::Role::Composite->new(
50 roles => [
51 Role::Foo->meta,
52 Role::Bar->meta,
53 ]
54 );
55 isa_ok($c, 'Mouse::Meta::Role::Composite');
56
57 is($c->name, 'Role::Foo|Role::Bar', '... got the composite role name');
6cfa1e5e 58
67199842 59 lives_ok {
60 Mouse::Meta::Role::Application::RoleSummation->new->apply($c);
6cfa1e5e 61 } '... this lives as expected';
67199842 62}
63
64# test no conflicts w/exclusion
65{
66 my $c = Mouse::Meta::Role::Composite->new(
67 roles => [
68 Role::Bar->meta,
6cfa1e5e 69 Role::ExcludesFoo->meta,
67199842 70 ]
71 );
72 isa_ok($c, 'Mouse::Meta::Role::Composite');
73
74 is($c->name, 'Role::Bar|Role::ExcludesFoo', '... got the composite role name');
6cfa1e5e 75
67199842 76 lives_ok {
77 Mouse::Meta::Role::Application::RoleSummation->new->apply($c);
6cfa1e5e 78 } '... this lives as expected';
79
80 is_deeply([$c->get_excluded_roles_list], ['Role::Foo'], '... has excluded roles');
67199842 81}
82
83
84# test conflict with an "inherited" exclusion
85dies_ok {
86 Mouse::Meta::Role::Application::RoleSummation->new->apply(
87 Mouse::Meta::Role::Composite->new(
88 roles => [
89 Role::Foo->meta,
90 Role::DoesExcludesFoo->meta,
91 ]
92 )
93 );
6cfa1e5e 94
67199842 95} '... this fails as expected';
96
97# test conflict with an "inherited" exclusion of an "inherited" role
98dies_ok {
99 Mouse::Meta::Role::Application::RoleSummation->new->apply(
6cfa1e5e 100 Mouse::Meta::Role::Composite->new(
67199842 101 roles => [
6cfa1e5e 102 Role::DoesFoo->meta,
67199842 103 Role::DoesExcludesFoo->meta,
104 ]
105 )
106 );
107} '... this fails as expected';
108
109