Got rid of a bunch of random whitespace and tidied the file
[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
13     package Foo::Role;
14     use Moose::Role;
15
16     requires 'foo';
17 }
18
19 is_deeply(
20     [ sort Foo::Role->meta->get_required_method_list ],
21     ['foo'],
22     '... the Foo::Role has a required method (foo)'
23 );
24
25 # classes which does not implement required method
26 {
27
28     package Foo::Class;
29     use Moose;
30
31     ::dies_ok{ with('Foo::Role') }
32         '... no foo method implemented by Foo::Class';
33 }
34
35 # class which does implement required method
36 {
37
38     package Bar::Class;
39     use Moose;
40
41     ::dies_ok{ with('Foo::Class') }
42         '... cannot consume a class, it must be a role';
43     ::lives_ok{ with('Foo::Role') }
44         '... has a foo method implemented by Bar::Class';
45
46     sub foo {'Bar::Class::foo'}
47 }
48
49 # role which does implement required method
50 {
51
52     package Bar::Role;
53     use Moose::Role;
54
55     ::lives_ok{ with('Foo::Role') }
56         '... has a foo method implemented by Bar::Role';
57
58     sub foo {'Bar::Role::foo'}
59 }
60
61 is_deeply(
62     [ sort Bar::Role->meta->get_required_method_list ],
63     [],
64     '... the Bar::Role has not inherited the required method from Foo::Role'
65 );
66
67 # role which does not implement required method
68 {
69
70     package Baz::Role;
71     use Moose::Role;
72
73     ::lives_ok{ with('Foo::Role') }
74         '... no foo method implemented by Baz::Role';
75 }
76
77 is_deeply(
78     [ sort Baz::Role->meta->get_required_method_list ],
79     ['foo'],
80     '... the Baz::Role has inherited the required method from Foo::Role'
81 );
82
83 # classes which does not implement required method
84 {
85
86     package Baz::Class;
87     use Moose;
88
89     ::dies_ok{ with('Baz::Role') }
90         '... no foo method implemented by Baz::Class2';
91 }
92
93 # class which does implement required method
94 {
95
96     package Baz::Class2;
97     use Moose;
98
99     ::lives_ok{ with('Baz::Role') }
100         '... has a foo method implemented by Baz::Class2';
101
102     sub foo {'Baz::Class2::foo'}
103 }
104