Commit | Line | Data |
7a50b450 |
1 | #!/usr/bin/perl |
fde8e43f |
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; |
7a50b450 |
5 | |
6 | use strict; |
7 | use warnings; |
8 | |
6475f69d |
9 | use Test::More; |
7a50b450 |
10 | use Test::Exception; |
11 | |
12 | |
7a50b450 |
13 | { |
14 | |
15 | package Foo::Role; |
16 | use Mouse::Role; |
17 | |
18 | requires 'foo'; |
19 | } |
20 | |
21 | is_deeply( |
22 | [ sort Foo::Role->meta->get_required_method_list ], |
23 | ['foo'], |
24 | '... the Foo::Role has a required method (foo)' |
25 | ); |
26 | |
27 | # classes which does not implement required method |
28 | { |
29 | |
30 | package Foo::Class; |
31 | use Mouse; |
32 | |
33 | ::dies_ok { with('Foo::Role') } |
34 | '... no foo method implemented by Foo::Class'; |
35 | } |
36 | |
37 | # class which does implement required method |
38 | { |
39 | |
40 | package Bar::Class; |
41 | use Mouse; |
42 | |
43 | ::dies_ok { with('Foo::Class') } |
44 | '... cannot consume a class, it must be a role'; |
45 | ::lives_ok { with('Foo::Role') } |
46 | '... has a foo method implemented by Bar::Class'; |
47 | |
48 | sub foo {'Bar::Class::foo'} |
49 | } |
50 | |
51 | # role which does implement required method |
52 | { |
53 | |
54 | package Bar::Role; |
55 | use Mouse::Role; |
56 | |
57 | ::lives_ok { with('Foo::Role') } |
58 | '... has a foo method implemented by Bar::Role'; |
59 | |
60 | sub foo {'Bar::Role::foo'} |
61 | } |
62 | |
63 | is_deeply( |
64 | [ sort Bar::Role->meta->get_required_method_list ], |
65 | [], |
66 | '... the Bar::Role has not inherited the required method from Foo::Role' |
67 | ); |
68 | |
69 | # role which does not implement required method |
70 | { |
71 | |
72 | package Baz::Role; |
73 | use Mouse::Role; |
74 | |
75 | ::lives_ok { with('Foo::Role') } |
76 | '... no foo method implemented by Baz::Role'; |
77 | } |
78 | |
79 | is_deeply( |
80 | [ sort Baz::Role->meta->get_required_method_list ], |
81 | ['foo'], |
82 | '... the Baz::Role has inherited the required method from Foo::Role' |
83 | ); |
84 | |
85 | # classes which does not implement required method |
86 | { |
87 | |
88 | package Baz::Class; |
89 | use Mouse; |
90 | |
91 | ::dies_ok { with('Baz::Role') } |
92 | '... no foo method implemented by Baz::Class2'; |
93 | } |
94 | |
95 | # class which does implement required method |
96 | { |
97 | |
98 | package Baz::Class2; |
99 | use Mouse; |
100 | |
101 | ::lives_ok { with('Baz::Role') } |
102 | '... has a foo method implemented by Baz::Class2'; |
103 | |
104 | sub foo {'Baz::Class2::foo'} |
105 | } |
106 | |
107 | |
108 | { |
109 | package Quux::Role; |
110 | use Mouse::Role; |
111 | |
112 | requires qw( meth1 meth2 meth3 meth4 ); |
113 | } |
114 | |
115 | # RT #41119 |
116 | { |
117 | |
118 | package Quux::Class; |
119 | use Mouse; |
120 | |
121 | ::throws_ok { with('Quux::Role') } |
122 | qr/\Q'Quux::Role' requires the methods 'meth1', 'meth2', 'meth3', and 'meth4' to be implemented by 'Quux::Class'/, |
123 | 'exception mentions all the missing required methods at once'; |
124 | } |
125 | |
126 | { |
127 | package Quux::Class2; |
128 | use Mouse; |
129 | |
130 | sub meth1 { } |
131 | |
132 | ::throws_ok { with('Quux::Role') } |
133 | qr/'Quux::Role' requires the methods 'meth2', 'meth3', and 'meth4' to be implemented by 'Quux::Class2'/, |
134 | 'exception mentions all the missing required methods at once, but not the one that exists'; |
135 | } |
136 | |
137 | { |
138 | package Quux::Class3; |
139 | use Mouse; |
140 | |
141 | has 'meth1' => ( is => 'ro' ); |
142 | has 'meth2' => ( is => 'ro' ); |
143 | |
144 | ::throws_ok { with('Quux::Role') } |
145 | qr/'Quux::Role' requires the methods 'meth3' and 'meth4' to be implemented by 'Quux::Class3'/, |
146 | 'exception mentions all the missing methods at once, but not the accessors'; |
147 | } |
148 | |
149 | { |
150 | package Quux::Class4; |
151 | use Mouse; |
152 | |
153 | sub meth1 { } |
154 | has 'meth2' => ( is => 'ro' ); |
155 | |
156 | ::throws_ok { with('Quux::Role') } |
157 | qr/'Quux::Role' requires the methods 'meth3' and 'meth4' to be implemented by 'Quux::Class4'/, |
158 | 'exception mentions all the require methods that are accessors at once, as well as missing methods, but not the one that exists'; |
159 | } |
6475f69d |
160 | |
161 | done_testing; |