Convert all tests to done_testing.
[gitmo/Moose.git] / t / 030_roles / 012_method_exclusion_in_composition.t
CommitLineData
c4538447 1#!/usr/bin/perl
2
3use strict;
4use warnings;
5
a28e50e4 6use Test::More;
c4538447 7use Test::Exception;
8
7ff56534 9
c4538447 10{
11 package My::Role;
12 use Moose::Role;
13
14 sub foo { 'Foo::foo' }
15 sub bar { 'Foo::bar' }
16 sub baz { 'Foo::baz' }
17
18 package My::Class;
19 use Moose;
20
c8b8d92f 21 with 'My::Role' => { -excludes => 'bar' };
c4538447 22}
23
24ok(My::Class->meta->has_method($_), "we have a $_ method") for qw(foo baz);
25ok(!My::Class->meta->has_method('bar'), '... but we excluded bar');
26
27{
28 package My::OtherRole;
29 use Moose::Role;
30
c8b8d92f 31 with 'My::Role' => { -excludes => 'foo' };
c4538447 32
33 sub foo { 'My::OtherRole::foo' }
34 sub bar { 'My::OtherRole::bar' }
35}
36
37ok(My::OtherRole->meta->has_method($_), "we have a $_ method") for qw(foo bar baz);
38
39ok(!My::OtherRole->meta->requires_method('foo'), '... and the &foo method is not required');
40ok(My::OtherRole->meta->requires_method('bar'), '... and the &bar method is required');
41
28412c0b 42{
43 package Foo::Role;
44 use Moose::Role;
d03bd989 45
28412c0b 46 sub foo { 'Foo::Role::foo' }
d03bd989 47
28412c0b 48 package Bar::Role;
49 use Moose::Role;
d03bd989 50
51 sub foo { 'Bar::Role::foo' }
28412c0b 52
53 package Baz::Role;
54 use Moose::Role;
d03bd989 55
56 sub foo { 'Baz::Role::foo' }
57
28412c0b 58 package My::Foo::Class;
59 use Moose;
d03bd989 60
28412c0b 61 ::lives_ok {
c8b8d92f 62 with 'Foo::Role' => { -excludes => 'foo' },
63 'Bar::Role' => { -excludes => 'foo' },
28412c0b 64 'Baz::Role';
65 } '... composed our roles correctly';
d03bd989 66
28412c0b 67 package My::Foo::Class::Broken;
68 use Moose;
d03bd989 69
28412c0b 70 ::throws_ok {
71 with 'Foo::Role',
c8b8d92f 72 'Bar::Role' => { -excludes => 'foo' },
28412c0b 73 'Baz::Role';
353d4b3b 74 } qr/Due to a method name conflict in roles 'Baz::Role' and 'Foo::Role', the method 'foo' must be implemented or excluded by 'My::Foo::Class::Broken'/,
d03bd989 75 '... composed our roles correctly';
28412c0b 76}
77
78{
79 my $foo = My::Foo::Class->new;
80 isa_ok($foo, 'My::Foo::Class');
81 can_ok($foo, 'foo');
82 is($foo->foo, 'Baz::Role::foo', '... got the right method');
83}
84
85{
86 package My::Foo::Role;
87 use Moose::Role;
88
89 ::lives_ok {
c8b8d92f 90 with 'Foo::Role' => { -excludes => 'foo' },
91 'Bar::Role' => { -excludes => 'foo' },
28412c0b 92 'Baz::Role';
93 } '... composed our roles correctly';
94}
95
96ok(My::Foo::Role->meta->has_method('foo'), "we have a foo method");
97ok(!My::Foo::Role->meta->requires_method('foo'), '... and the &foo method is not required');
98
99{
100 package My::Foo::Role::Other;
101 use Moose::Role;
102
103 ::lives_ok {
104 with 'Foo::Role',
c8b8d92f 105 'Bar::Role' => { -excludes => 'foo' },
28412c0b 106 'Baz::Role';
107 } '... composed our roles correctly';
108}
c4538447 109
28412c0b 110ok(!My::Foo::Role::Other->meta->has_method('foo'), "we dont have a foo method");
111ok(My::Foo::Role::Other->meta->requires_method('foo'), '... and the &foo method is required');
c4538447 112
a28e50e4 113done_testing;