merge trunk to pluggable errors
[gitmo/Moose.git] / t / 030_roles / 004_role_composition_errors.t
1 #!/usr/bin/perl
2
3 use strict;
4 use warnings;
5
6 use Test::More tests => 10;
7 use Test::Exception;
8
9
10
11 {
12     package Foo::Role;
13     use Moose::Role;
14     
15     requires 'foo';
16 }
17
18 is_deeply(
19     [ sort Foo::Role->meta->get_required_method_list ],
20     [ 'foo' ],
21     '... the Foo::Role has a required method (foo)');
22
23 # classes which does not implement required method
24 {
25     package Foo::Class;
26     use Moose;
27     
28     ::dies_ok { with('Foo::Role') } '... no foo method implemented by Foo::Class';
29 }
30
31 # class which does implement required method
32 {
33     package Bar::Class;
34     use Moose;
35     
36     ::dies_ok  { with('Foo::Class') } '... cannot consume a class, it must be a role';
37     ::lives_ok { with('Foo::Role')  } '... has a foo method implemented by Bar::Class';
38     
39     sub foo { 'Bar::Class::foo' }
40 }
41
42 # role which does implement required method
43 {
44     package Bar::Role;
45     use Moose::Role;
46     
47     ::lives_ok { with('Foo::Role') } '... has a foo method implemented by Bar::Role';
48     
49     sub foo { 'Bar::Role::foo' }
50 }
51
52 is_deeply(
53     [ sort Bar::Role->meta->get_required_method_list ],
54     [],
55     '... the Bar::Role has not inherited the required method from Foo::Role');
56
57 # role which does not implement required method
58 {
59     package Baz::Role;
60     use Moose::Role;
61     
62     ::lives_ok { with('Foo::Role') } '... no foo method implemented by Baz::Role';
63 }
64
65 is_deeply(
66     [ sort Baz::Role->meta->get_required_method_list ],
67     [ 'foo' ],
68     '... the Baz::Role has inherited the required method from Foo::Role');
69     
70 # classes which does not implement required method
71 {
72     package Baz::Class;
73     use Moose;
74
75     ::dies_ok { with('Baz::Role') } '... no foo method implemented by Baz::Class2';
76 }
77
78 # class which does implement required method
79 {
80     package Baz::Class2;
81     use Moose;
82
83     ::lives_ok { with('Baz::Role') } '... has a foo method implemented by Baz::Class2';
84
85     sub foo { 'Baz::Class2::foo' }
86 }    
87     
88