Revert autogenerated tests. Tests should not changed radically.
[gitmo/Mouse.git] / Moose-t-failing / 030_roles / 012_method_exclusion_in_composition.t
1 #!/usr/bin/perl
2 # This is automatically generated by author/import-moose-test.pl.
3 # DO NOT EDIT THIS FILE. ANY CHANGES WILL BE LOST!!!
4 use t::lib::MooseCompat;
5
6 use strict;
7 use warnings;
8
9 use Test::More;
10 $TODO = q{Mouse is not yet completed};
11 use Test::Exception;
12
13
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
25     with 'My::Role' => { -excludes => 'bar' };
26 }
27
28 ok(My::Class->meta->has_method($_), "we have a $_ method") for qw(foo baz);
29 ok(!My::Class->meta->has_method('bar'), '... but we excluded bar');
30
31 {
32     package My::OtherRole;
33     use Mouse::Role;
34
35     with 'My::Role' => { -excludes => 'foo' };
36
37     sub foo { 'My::OtherRole::foo' }
38     sub bar { 'My::OtherRole::bar' }
39 }
40
41 ok(My::OtherRole->meta->has_method($_), "we have a $_ method") for qw(foo bar baz);
42
43 ok(!My::OtherRole->meta->requires_method('foo'), '... and the &foo method is not required');
44 ok(My::OtherRole->meta->requires_method('bar'), '... and the &bar method is required');
45
46 {
47     package Foo::Role;
48     use Mouse::Role;
49
50     sub foo { 'Foo::Role::foo' }
51
52     package Bar::Role;
53     use Mouse::Role;
54
55     sub foo { 'Bar::Role::foo' }
56
57     package Baz::Role;
58     use Mouse::Role;
59
60     sub foo { 'Baz::Role::foo' }
61
62     package My::Foo::Class;
63     use Mouse;
64
65     ::lives_ok {
66         with 'Foo::Role' => { -excludes => 'foo' },
67              'Bar::Role' => { -excludes => 'foo' },
68              'Baz::Role';
69     } '... composed our roles correctly';
70
71     package My::Foo::Class::Broken;
72     use Mouse;
73
74     ::throws_ok {
75         with 'Foo::Role',
76              'Bar::Role' => { -excludes => 'foo' },
77              'Baz::Role';
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';
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 {
94         with 'Foo::Role' => { -excludes => 'foo' },
95              'Bar::Role' => { -excludes => 'foo' },
96              'Baz::Role';
97     } '... composed our roles correctly';
98 }
99
100 ok(My::Foo::Role->meta->has_method('foo'), "we have a foo method");
101 ok(!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',
109              'Bar::Role' => { -excludes => 'foo' },
110              'Baz::Role';
111     } '... composed our roles correctly';
112 }
113
114 ok(!My::Foo::Role::Other->meta->has_method('foo'), "we dont have a foo method");
115 ok(My::Foo::Role::Other->meta->requires_method('foo'), '... and the &foo method is required');
116
117 done_testing;