RT#83929: fix memory leak in union types
[gitmo/Moose.git] / t / roles / role_composite_exclusion.t
CommitLineData
fb1e11d5 1#!/usr/bin/perl
2
3use strict;
4use warnings;
5
a28e50e4 6use Test::More;
b10dde3a 7use Test::Fatal;
fb1e11d5 8
7ff56534 9use Moose::Meta::Role::Application::RoleSummation;
10use Moose::Meta::Role::Composite;
fb1e11d5 11
12{
13 package Role::Foo;
14 use Moose::Role;
d03bd989 15
fb1e11d5 16 package Role::Bar;
17 use Moose::Role;
d03bd989 18
fb1e11d5 19 package Role::ExcludesFoo;
20 use Moose::Role;
21 excludes 'Role::Foo';
d03bd989 22
fb1e11d5 23 package Role::DoesExcludesFoo;
24 use Moose::Role;
d03bd989 25 with 'Role::ExcludesFoo';
26
fb1e11d5 27 package Role::DoesFoo;
28 use Moose::Role;
d03bd989 29 with 'Role::Foo';
fb1e11d5 30}
31
1c9db35c 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
fb1e11d5 35# test simple exclusion
b10dde3a 36isnt( exception {
fb1e11d5 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 );
b10dde3a 45}, undef, '... this fails as expected' );
fb1e11d5 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');
d03bd989 58
b10dde3a 59 is( exception {
fb1e11d5 60 Moose::Meta::Role::Application::RoleSummation->new->apply($c);
b10dde3a 61 }, undef, '... this lives as expected' );
fb1e11d5 62}
63
64# test no conflicts w/exclusion
65{
66 my $c = Moose::Meta::Role::Composite->new(
67 roles => [
68 Role::Bar->meta,
d03bd989 69 Role::ExcludesFoo->meta,
fb1e11d5 70 ]
71 );
72 isa_ok($c, 'Moose::Meta::Role::Composite');
73
74 is($c->name, 'Role::Bar|Role::ExcludesFoo', '... got the composite role name');
d03bd989 75
b10dde3a 76 is( exception {
fb1e11d5 77 Moose::Meta::Role::Application::RoleSummation->new->apply($c);
b10dde3a 78 }, undef, '... this lives as expected' );
d03bd989 79
80 is_deeply([$c->get_excluded_roles_list], ['Role::Foo'], '... has excluded roles');
fb1e11d5 81}
82
83
84# test conflict with an "inherited" exclusion
b10dde3a 85isnt( exception {
fb1e11d5 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 );
d03bd989 94
b10dde3a 95}, undef, '... this fails as expected' );
fb1e11d5 96
97# test conflict with an "inherited" exclusion of an "inherited" role
b10dde3a 98isnt( exception {
fb1e11d5 99 Moose::Meta::Role::Application::RoleSummation->new->apply(
d03bd989 100 Moose::Meta::Role::Composite->new(
fb1e11d5 101 roles => [
d03bd989 102 Role::DoesFoo->meta,
fb1e11d5 103 Role::DoesExcludesFoo->meta,
104 ]
105 )
106 );
b10dde3a 107}, undef, '... this fails as expected' );
fb1e11d5 108
a28e50e4 109done_testing;