Cleanup failing tests
[gitmo/Mouse.git] / Moose-t-failing / 030_roles / 012_method_exclusion_in_composition.t
CommitLineData
67199842 1#!/usr/bin/perl
c47cf415 2# This is automatically generated by author/import-moose-test.pl.
3# DO NOT EDIT THIS FILE. ANY CHANGES WILL BE LOST!!!
4use t::lib::MooseCompat;
67199842 5
6use strict;
7use warnings;
8
c47cf415 9use Test::More;
10$TODO = q{Mouse is not yet completed};
67199842 11use Test::Exception;
12
13
67199842 14{
15 package My::Role;
16 use Mouse::Role;
17
18 sub foo { 'Foo::foo' }
19 sub bar { 'Foo::bar' }
20 sub baz { 'Foo::baz' }
21
22 package My::Class;
23 use Mouse;
24
6cfa1e5e 25 with 'My::Role' => { -excludes => 'bar' };
67199842 26}
27
28ok(My::Class->meta->has_method($_), "we have a $_ method") for qw(foo baz);
29ok(!My::Class->meta->has_method('bar'), '... but we excluded bar');
30
31{
32 package My::OtherRole;
33 use Mouse::Role;
34
6cfa1e5e 35 with 'My::Role' => { -excludes => 'foo' };
67199842 36
37 sub foo { 'My::OtherRole::foo' }
38 sub bar { 'My::OtherRole::bar' }
39}
40
41ok(My::OtherRole->meta->has_method($_), "we have a $_ method") for qw(foo bar baz);
42
43ok(!My::OtherRole->meta->requires_method('foo'), '... and the &foo method is not required');
44ok(My::OtherRole->meta->requires_method('bar'), '... and the &bar method is required');
6fea087b 45
67199842 46{
47 package Foo::Role;
48 use Mouse::Role;
c2d7552a 49
67199842 50 sub foo { 'Foo::Role::foo' }
c2d7552a 51
67199842 52 package Bar::Role;
53 use Mouse::Role;
c2d7552a 54
55 sub foo { 'Bar::Role::foo' }
67199842 56
57 package Baz::Role;
58 use Mouse::Role;
c2d7552a 59
60 sub foo { 'Baz::Role::foo' }
61
67199842 62 package My::Foo::Class;
63 use Mouse;
c2d7552a 64
67199842 65 ::lives_ok {
6cfa1e5e 66 with 'Foo::Role' => { -excludes => 'foo' },
67 'Bar::Role' => { -excludes => 'foo' },
67199842 68 'Baz::Role';
69 } '... composed our roles correctly';
c2d7552a 70
67199842 71 package My::Foo::Class::Broken;
72 use Mouse;
c2d7552a 73
67199842 74 ::throws_ok {
75 with 'Foo::Role',
6cfa1e5e 76 'Bar::Role' => { -excludes => 'foo' },
67199842 77 'Baz::Role';
c2d7552a 78 } 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'/,
79 '... composed our roles correctly';
67199842 80}
81
82{
83 my $foo = My::Foo::Class->new;
84 isa_ok($foo, 'My::Foo::Class');
85 can_ok($foo, 'foo');
86 is($foo->foo, 'Baz::Role::foo', '... got the right method');
87}
88
89{
90 package My::Foo::Role;
91 use Mouse::Role;
92
93 ::lives_ok {
6cfa1e5e 94 with 'Foo::Role' => { -excludes => 'foo' },
95 'Bar::Role' => { -excludes => 'foo' },
67199842 96 'Baz::Role';
97 } '... composed our roles correctly';
98}
99
100ok(My::Foo::Role->meta->has_method('foo'), "we have a foo method");
101ok(!My::Foo::Role->meta->requires_method('foo'), '... and the &foo method is not required');
102
103{
104 package My::Foo::Role::Other;
105 use Mouse::Role;
106
107 ::lives_ok {
108 with 'Foo::Role',
6cfa1e5e 109 'Bar::Role' => { -excludes => 'foo' },
67199842 110 'Baz::Role';
111 } '... composed our roles correctly';
112}
113
114ok(!My::Foo::Role::Other->meta->has_method('foo'), "we dont have a foo method");
115ok(My::Foo::Role::Other->meta->requires_method('foo'), '... and the &foo method is required');
116
c47cf415 117done_testing;