line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Test::Moose; |
2
|
|
|
|
|
|
|
our $VERSION = '2.2203'; |
3
|
|
|
|
|
|
|
|
4
|
37
|
|
|
37
|
|
3538399
|
use strict; |
|
37
|
|
|
|
|
359
|
|
|
37
|
|
|
|
|
1039
|
|
5
|
37
|
|
|
37
|
|
183
|
use warnings; |
|
37
|
|
|
|
|
71
|
|
|
37
|
|
|
|
|
890
|
|
6
|
|
|
|
|
|
|
|
7
|
37
|
|
|
37
|
|
17260
|
use Sub::Exporter; |
|
37
|
|
|
|
|
384802
|
|
|
37
|
|
|
|
|
218
|
|
8
|
37
|
|
|
37
|
|
7348
|
use Test::Builder; |
|
37
|
|
|
|
|
73
|
|
|
37
|
|
|
|
|
999
|
|
9
|
|
|
|
|
|
|
|
10
|
37
|
|
|
37
|
|
207
|
use List::Util 1.33 'all'; |
|
37
|
|
|
|
|
606
|
|
|
37
|
|
|
|
|
2200
|
|
11
|
37
|
|
|
37
|
|
13781
|
use Moose::Util 'does_role', 'find_meta'; |
|
37
|
|
|
|
|
100
|
|
|
37
|
|
|
|
|
329
|
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
my @exports = qw[ |
14
|
|
|
|
|
|
|
meta_ok |
15
|
|
|
|
|
|
|
does_ok |
16
|
|
|
|
|
|
|
has_attribute_ok |
17
|
|
|
|
|
|
|
with_immutable |
18
|
|
|
|
|
|
|
]; |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
Sub::Exporter::setup_exporter({ |
21
|
|
|
|
|
|
|
exports => \@exports, |
22
|
|
|
|
|
|
|
groups => { default => \@exports } |
23
|
|
|
|
|
|
|
}); |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
## the test builder instance ... |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
my $Test = Test::Builder->new; |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
## exported functions |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
sub meta_ok ($;$) { |
32
|
2
|
|
|
2
|
1
|
2997
|
my ($class_or_obj, $message) = @_; |
33
|
|
|
|
|
|
|
|
34
|
2
|
|
50
|
|
|
8
|
$message ||= "The object has a meta"; |
35
|
|
|
|
|
|
|
|
36
|
2
|
100
|
|
|
|
10
|
if (find_meta($class_or_obj)) { |
37
|
1
|
|
|
|
|
8
|
return $Test->ok(1, $message) |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
else { |
40
|
1
|
|
|
|
|
6
|
return $Test->ok(0, $message); |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
sub does_ok ($$;$) { |
45
|
62
|
|
|
62
|
1
|
6952
|
my ($class_or_obj, $does, $message) = @_; |
46
|
|
|
|
|
|
|
|
47
|
62
|
|
66
|
|
|
313
|
$message ||= "The object does $does"; |
48
|
|
|
|
|
|
|
|
49
|
62
|
100
|
|
|
|
201
|
if (does_role($class_or_obj, $does)) { |
50
|
55
|
|
|
|
|
207
|
return $Test->ok(1, $message) |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
else { |
53
|
7
|
|
|
|
|
27
|
return $Test->ok(0, $message); |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
sub has_attribute_ok ($$;$) { |
58
|
4
|
|
|
4
|
1
|
3923
|
my ($class_or_obj, $attr_name, $message) = @_; |
59
|
|
|
|
|
|
|
|
60
|
4
|
|
33
|
|
|
12
|
$message ||= "The object does has an attribute named $attr_name"; |
61
|
|
|
|
|
|
|
|
62
|
4
|
|
|
|
|
15
|
my $meta = find_meta($class_or_obj); |
63
|
|
|
|
|
|
|
|
64
|
4
|
100
|
|
|
|
19
|
if ($meta->find_attribute_by_name($attr_name)) { |
65
|
3
|
|
|
|
|
13
|
return $Test->ok(1, $message) |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
else { |
68
|
1
|
|
|
|
|
5
|
return $Test->ok(0, $message); |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
sub with_immutable (&@) { |
73
|
59
|
|
|
59
|
1
|
254046
|
my $block = shift; |
74
|
59
|
|
|
|
|
301
|
my $before = $Test->current_test; |
75
|
|
|
|
|
|
|
|
76
|
59
|
|
|
|
|
9025
|
$block->(0); |
77
|
59
|
|
|
|
|
7443
|
Class::MOP::class_of($_)->make_immutable for @_; |
78
|
59
|
|
|
|
|
269
|
$block->(1); |
79
|
|
|
|
|
|
|
|
80
|
59
|
|
|
|
|
7543
|
my $num_tests = $Test->current_test - $before; |
81
|
59
|
|
|
4044
|
|
8168
|
my $all_passed = all { $_ } ($Test->summary)[-$num_tests..-1]; |
|
4044
|
|
|
|
|
30849
|
|
82
|
59
|
|
|
|
|
801
|
return $all_passed; |
83
|
|
|
|
|
|
|
} |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
1; |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
# ABSTRACT: Test functions for Moose specific features |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
__END__ |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
=pod |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
=encoding UTF-8 |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
=head1 NAME |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
Test::Moose - Test functions for Moose specific features |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
=head1 VERSION |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
version 2.2203 |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
=head1 SYNOPSIS |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
use Test::More plan => 1; |
106
|
|
|
|
|
|
|
use Test::Moose; |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
meta_ok($class_or_obj, "... Foo has a ->meta"); |
109
|
|
|
|
|
|
|
does_ok($class_or_obj, $role, "... Foo does the Baz role"); |
110
|
|
|
|
|
|
|
has_attribute_ok($class_or_obj, $attr_name, "... Foo has the 'bar' attribute"); |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
=head1 DESCRIPTION |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
This module provides some useful test functions for Moose based classes. It |
115
|
|
|
|
|
|
|
is an experimental first release, so comments and suggestions are very welcome. |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
=head1 EXPORTED FUNCTIONS |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
=head2 meta_ok ($class_or_object) |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
Tests if a class or object has a metaclass. |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
=head2 does_ok ($class_or_object, $role, ?$message) |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
Tests if a class or object does a certain role, similar to what C<isa_ok> |
126
|
|
|
|
|
|
|
does for the C<isa> method. |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
=head2 has_attribute_ok($class_or_object, $attr_name, ?$message) |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
Tests if a class or object has a certain attribute, similar to what C<can_ok> |
131
|
|
|
|
|
|
|
does for the methods. |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
=head2 with_immutable { CODE } @class_names |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
Runs B<CODE> (which should contain normal tests) twice, and make each |
136
|
|
|
|
|
|
|
class in C<@class_names> immutable in between the two runs. |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
The B<CODE> block is called with a single boolean argument indicating whether |
139
|
|
|
|
|
|
|
or not the classes have been made immutable yet. |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
=head1 TODO |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
=over 4 |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
=item Convert the Moose test suite to use this module. |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
=item Here is a list of possible functions to write |
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
=over 4 |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
=item immutability predicates |
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
=item anon-class predicates |
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
=item discovering original method from modified method |
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
=item attribute metaclass predicates (attribute_isa?) |
158
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
=back |
160
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
=back |
162
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
=head1 SEE ALSO |
164
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
=over 4 |
166
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
=item L<Test::More> |
168
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
=back |
170
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
=head1 BUGS |
172
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
See L<Moose/BUGS> for details on reporting bugs. |
174
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
=head1 AUTHORS |
176
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
=over 4 |
178
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
=item * |
180
|
|
|
|
|
|
|
|
181
|
|
|
|
|
|
|
Stevan Little <stevan@cpan.org> |
182
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
=item * |
184
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
Dave Rolsky <autarch@urth.org> |
186
|
|
|
|
|
|
|
|
187
|
|
|
|
|
|
|
=item * |
188
|
|
|
|
|
|
|
|
189
|
|
|
|
|
|
|
Jesse Luehrs <doy@cpan.org> |
190
|
|
|
|
|
|
|
|
191
|
|
|
|
|
|
|
=item * |
192
|
|
|
|
|
|
|
|
193
|
|
|
|
|
|
|
Shawn M Moore <sartak@cpan.org> |
194
|
|
|
|
|
|
|
|
195
|
|
|
|
|
|
|
=item * |
196
|
|
|
|
|
|
|
|
197
|
|
|
|
|
|
|
יובל קוג'מן (Yuval Kogman) <nothingmuch@woobling.org> |
198
|
|
|
|
|
|
|
|
199
|
|
|
|
|
|
|
=item * |
200
|
|
|
|
|
|
|
|
201
|
|
|
|
|
|
|
Karen Etheridge <ether@cpan.org> |
202
|
|
|
|
|
|
|
|
203
|
|
|
|
|
|
|
=item * |
204
|
|
|
|
|
|
|
|
205
|
|
|
|
|
|
|
Florian Ragwitz <rafl@debian.org> |
206
|
|
|
|
|
|
|
|
207
|
|
|
|
|
|
|
=item * |
208
|
|
|
|
|
|
|
|
209
|
|
|
|
|
|
|
Hans Dieter Pearcey <hdp@cpan.org> |
210
|
|
|
|
|
|
|
|
211
|
|
|
|
|
|
|
=item * |
212
|
|
|
|
|
|
|
|
213
|
|
|
|
|
|
|
Chris Prather <chris@prather.org> |
214
|
|
|
|
|
|
|
|
215
|
|
|
|
|
|
|
=item * |
216
|
|
|
|
|
|
|
|
217
|
|
|
|
|
|
|
Matt S Trout <mstrout@cpan.org> |
218
|
|
|
|
|
|
|
|
219
|
|
|
|
|
|
|
=back |
220
|
|
|
|
|
|
|
|
221
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
222
|
|
|
|
|
|
|
|
223
|
|
|
|
|
|
|
This software is copyright (c) 2006 by Infinity Interactive, Inc. |
224
|
|
|
|
|
|
|
|
225
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
226
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
227
|
|
|
|
|
|
|
|
228
|
|
|
|
|
|
|
=cut |