Require Dist::Zilla 4.200016+
[gitmo/Moose.git] / t / roles / role_composition_req_methods.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;
d03bd989 14 use Moose::Role;
fb1e11d5 15 requires 'foo';
d03bd989 16
fb1e11d5 17 package Role::Bar;
18 use Moose::Role;
19 requires 'bar';
d03bd989 20
fb1e11d5 21 package Role::ProvidesFoo;
d03bd989 22 use Moose::Role;
fb1e11d5 23 sub foo { 'Role::ProvidesFoo::foo' }
d03bd989 24
fb1e11d5 25 package Role::ProvidesBar;
d03bd989 26 use Moose::Role;
27 sub bar { 'Role::ProvidesBar::bar' }
fb1e11d5 28}
29
30# test simple requirement
31{
32 my $c = Moose::Meta::Role::Composite->new(
33 roles => [
34 Role::Foo->meta,
35 Role::Bar->meta,
d03bd989 36 ]
fb1e11d5 37 );
38 isa_ok($c, 'Moose::Meta::Role::Composite');
39
d03bd989 40 is($c->name, 'Role::Foo|Role::Bar', '... got the composite role name');
41
b10dde3a 42 is( exception {
fb1e11d5 43 Moose::Meta::Role::Application::RoleSummation->new->apply($c);
b10dde3a 44 }, undef, '... this succeeds as expected' );
d03bd989 45
fb1e11d5 46 is_deeply(
47 [ sort $c->get_required_method_list ],
48 [ 'bar', 'foo' ],
49 '... got the right list of required methods'
50 );
51}
52
53# test requirement satisfied
54{
55 my $c = Moose::Meta::Role::Composite->new(
56 roles => [
57 Role::Foo->meta,
58 Role::ProvidesFoo->meta,
59 ]
60 );
61 isa_ok($c, 'Moose::Meta::Role::Composite');
62
d03bd989 63 is($c->name, 'Role::Foo|Role::ProvidesFoo', '... got the composite role name');
64
b10dde3a 65 is( exception {
fb1e11d5 66 Moose::Meta::Role::Application::RoleSummation->new->apply($c);
b10dde3a 67 }, undef, '... this succeeds as expected' );
d03bd989 68
fb1e11d5 69 is_deeply(
70 [ sort $c->get_required_method_list ],
71 [],
72 '... got the right list of required methods'
73 );
74}
75
76# test requirement satisfied
77{
78 my $c = Moose::Meta::Role::Composite->new(
79 roles => [
80 Role::Foo->meta,
81 Role::ProvidesFoo->meta,
d03bd989 82 Role::Bar->meta,
fb1e11d5 83 ]
84 );
85 isa_ok($c, 'Moose::Meta::Role::Composite');
86
d03bd989 87 is($c->name, 'Role::Foo|Role::ProvidesFoo|Role::Bar', '... got the composite role name');
88
b10dde3a 89 is( exception {
fb1e11d5 90 Moose::Meta::Role::Application::RoleSummation->new->apply($c);
b10dde3a 91 }, undef, '... this succeeds as expected' );
d03bd989 92
fb1e11d5 93 is_deeply(
94 [ sort $c->get_required_method_list ],
95 [ 'bar' ],
96 '... got the right list of required methods'
97 );
98}
99
100# test requirement satisfied
101{
102 my $c = Moose::Meta::Role::Composite->new(
103 roles => [
104 Role::Foo->meta,
105 Role::ProvidesFoo->meta,
d03bd989 106 Role::ProvidesBar->meta,
107 Role::Bar->meta,
fb1e11d5 108 ]
109 );
110 isa_ok($c, 'Moose::Meta::Role::Composite');
111
d03bd989 112 is($c->name, 'Role::Foo|Role::ProvidesFoo|Role::ProvidesBar|Role::Bar', '... got the composite role name');
113
b10dde3a 114 is( exception {
fb1e11d5 115 Moose::Meta::Role::Application::RoleSummation->new->apply($c);
b10dde3a 116 }, undef, '... this succeeds as expected' );
d03bd989 117
fb1e11d5 118 is_deeply(
119 [ sort $c->get_required_method_list ],
120 [ ],
121 '... got the right list of required methods'
122 );
123}
124
a28e50e4 125done_testing;