| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Test::Moose; |
|
2
|
|
|
|
|
|
|
our $VERSION = '2.2205'; |
|
3
|
|
|
|
|
|
|
|
|
4
|
35
|
|
|
35
|
|
2432503
|
use strict; |
|
|
35
|
|
|
|
|
398
|
|
|
|
35
|
|
|
|
|
1079
|
|
|
5
|
35
|
|
|
35
|
|
195
|
use warnings; |
|
|
35
|
|
|
|
|
75
|
|
|
|
35
|
|
|
|
|
939
|
|
|
6
|
|
|
|
|
|
|
|
|
7
|
35
|
|
|
35
|
|
18784
|
use Sub::Exporter; |
|
|
35
|
|
|
|
|
405391
|
|
|
|
35
|
|
|
|
|
229
|
|
|
8
|
35
|
|
|
35
|
|
7427
|
use Test::Builder; |
|
|
35
|
|
|
|
|
76
|
|
|
|
35
|
|
|
|
|
1030
|
|
|
9
|
|
|
|
|
|
|
|
|
10
|
35
|
|
|
35
|
|
201
|
use List::Util 1.33 'all'; |
|
|
35
|
|
|
|
|
694
|
|
|
|
35
|
|
|
|
|
3911
|
|
|
11
|
35
|
|
|
35
|
|
14496
|
use Moose::Util 'does_role', 'find_meta'; |
|
|
35
|
|
|
|
|
132
|
|
|
|
35
|
|
|
|
|
1672
|
|
|
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
|
2297
|
my ($class_or_obj, $message) = @_; |
|
33
|
|
|
|
|
|
|
|
|
34
|
2
|
|
50
|
|
|
9
|
$message ||= "The object has a meta"; |
|
35
|
|
|
|
|
|
|
|
|
36
|
2
|
100
|
|
|
|
7
|
if (find_meta($class_or_obj)) { |
|
37
|
1
|
|
|
|
|
7
|
return $Test->ok(1, $message) |
|
38
|
|
|
|
|
|
|
} |
|
39
|
|
|
|
|
|
|
else { |
|
40
|
1
|
|
|
|
|
4
|
return $Test->ok(0, $message); |
|
41
|
|
|
|
|
|
|
} |
|
42
|
|
|
|
|
|
|
} |
|
43
|
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
sub does_ok ($$;$) { |
|
45
|
61
|
|
|
61
|
1
|
5688
|
my ($class_or_obj, $does, $message) = @_; |
|
46
|
|
|
|
|
|
|
|
|
47
|
61
|
|
66
|
|
|
332
|
$message ||= "The object does $does"; |
|
48
|
|
|
|
|
|
|
|
|
49
|
61
|
100
|
|
|
|
222
|
if (does_role($class_or_obj, $does)) { |
|
50
|
54
|
|
|
|
|
226
|
return $Test->ok(1, $message) |
|
51
|
|
|
|
|
|
|
} |
|
52
|
|
|
|
|
|
|
else { |
|
53
|
7
|
|
|
|
|
40
|
return $Test->ok(0, $message); |
|
54
|
|
|
|
|
|
|
} |
|
55
|
|
|
|
|
|
|
} |
|
56
|
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
sub has_attribute_ok ($$;$) { |
|
58
|
4
|
|
|
4
|
1
|
3995
|
my ($class_or_obj, $attr_name, $message) = @_; |
|
59
|
|
|
|
|
|
|
|
|
60
|
4
|
|
33
|
|
|
26
|
$message ||= "The object does has an attribute named $attr_name"; |
|
61
|
|
|
|
|
|
|
|
|
62
|
4
|
|
|
|
|
14
|
my $meta = find_meta($class_or_obj); |
|
63
|
|
|
|
|
|
|
|
|
64
|
4
|
100
|
|
|
|
17
|
if ($meta->find_attribute_by_name($attr_name)) { |
|
65
|
3
|
|
|
|
|
14
|
return $Test->ok(1, $message) |
|
66
|
|
|
|
|
|
|
} |
|
67
|
|
|
|
|
|
|
else { |
|
68
|
1
|
|
|
|
|
5
|
return $Test->ok(0, $message); |
|
69
|
|
|
|
|
|
|
} |
|
70
|
|
|
|
|
|
|
} |
|
71
|
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
sub with_immutable (&@) { |
|
73
|
58
|
|
|
58
|
1
|
249557
|
my $block = shift; |
|
74
|
58
|
|
|
|
|
343
|
my $before = $Test->current_test; |
|
75
|
|
|
|
|
|
|
|
|
76
|
58
|
|
|
|
|
9172
|
$block->(0); |
|
77
|
58
|
|
|
|
|
6343
|
Class::MOP::class_of($_)->make_immutable for @_; |
|
78
|
58
|
|
|
|
|
291
|
$block->(1); |
|
79
|
|
|
|
|
|
|
|
|
80
|
58
|
|
|
|
|
6655
|
my $num_tests = $Test->current_test - $before; |
|
81
|
58
|
|
|
4036
|
|
8580
|
my $all_passed = all { $_ } ($Test->summary)[-$num_tests..-1]; |
|
|
4036
|
|
|
|
|
31885
|
|
|
82
|
58
|
|
|
|
|
977
|
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.2205 |
|
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 |