Class.pm

filter: Statementstmt 99.7% 330 / 331 Branchbran 95.8% 163 / 170 Conditioncond 100% 18 / 18 MC/DCmcdc 100% 11 / 11 Subroutinesub 100% 61 / 61 Podpod 100% 17 / 17 totaltotal 98.6% 600 / 608 CC 108 SCAR 20.6
CC
108
Cov
98%
runtests
26.0
_get_methods
12.0
_run_method
10.0
CRAP 7.9
↑ Summary Class/MethodInfo.pm »
1 55 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 55 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 55 ▶use 5.006;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 package Test::Class;
6  
7 55 ▶use Attribute::Handlers;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 55 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 55 ▶use MRO::Compat;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 55 ▶use Storable qw(dclone);
Subroutine BEGIN: called CC=1 SCAR=0.0
11 55 ▶use Test::Builder;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 55 ▶use Test::Class::MethodInfo;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 55 ▶use Try::Tiny;
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 55 our $VERSION = '0.52';
16  
17 55 my $Check_block_has_run;
18 {
19 55 ▶ no warnings 'void';
Subroutine BEGIN: called CC=1 SCAR=0.0
20 54 ▶ CHECK { $Check_block_has_run = 1 }
Subroutine CHECK: called CC=1 SCAR=0.0
21 }
22  
23 55 ▶use constant NO_PLAN => "no_plan";
Subroutine BEGIN: called CC=1 SCAR=0.0
24 55 ▶use constant SETUP => "setup";
Subroutine BEGIN: called CC=1 SCAR=0.0
25 55 ▶use constant TEST => "test";
Subroutine BEGIN: called CC=1 SCAR=0.0
26 55 ▶use constant TEARDOWN => "teardown";
Subroutine BEGIN: called CC=1 SCAR=0.0
27 55 ▶use constant STARTUP => "startup";
Subroutine BEGIN: called CC=1 SCAR=0.0
28 55 ▶use constant SHUTDOWN => "shutdown";
Subroutine BEGIN: called CC=1 SCAR=0.0
29  
30  
31 55 our $Current_method = undef;
32 33 ▶sub current_method { $Current_method }
Subroutine current_method: called CC=1 SCAR=0.0
Pod documented
33  
34  
35 55 my $Builder = Test::Builder->new;
36 6 ▶sub builder { $Builder }
Subroutine builder: called CC=1 SCAR=0.0
Pod documented
37  
38  
39 55 my $Tests = {};
40 55 my @Filters = ();
41  
42  
43 55 my %_Test; # inside-out object field indexed on $self
44  
45 64 ▶sub DESTROY {
Subroutine DESTROY: called CC=1 SCAR=0.0
46 64 my $self = shift;
47 64 delete $_Test{ $self };
48 }
49  
50 996 ▶sub _test_info {
Subroutine _test_info: called CC=2 SCAR=6.9
51 996 my $self = shift;
52 996 ▶ return ref($self) ? $_Test{$self} : $Tests;
Branch: 1 branch
BranchTrueFalseTotal
ref $self ? : 897 99 996
53 }
54  
55 358 ▶sub _method_info {
Subroutine _method_info: called CC=1 SCAR=0.0
56 358 my ($self, $class, $method) = @_;
57 358 return( _test_info($self)->{$class}->{$method} );
58 }
59  
60 638 ▶sub _methods_of_class {
Subroutine _methods_of_class: called CC=2 SCAR=6.9
61 638 my ( $self, $class ) = @_;
62 638 ▶ my $test_info = _test_info($self)
Branch: 1 branch
BranchTrueFalseTotal
my $test_info = _test_info($self) or die "Test::Class internals seem confused. Did you override new() in a sub-class or via multiple inheritance?\n" 637 1 638
63 or die "Test::Class internals seem confused. Did you override "
64 . "new() in a sub-class or via multiple inheritance?\n";
65 637 return values %{ $test_info->{$class} };
66 }
67  
68 131 ▶sub _parse_attribute_args {
Subroutine _parse_attribute_args: called CC=5 SCAR=16.1
69 131 ▶ my $args = shift || '';
Condition100%2/2
shift() || ''
l!l
11120
MC/DC100%1/1
shift() || ''
shift()
Truth table100%2/2
A
A= shift()
Aresult
11
00
70 131 my $num_tests;
71 my $type;
72 131 $args =~ s/\s+//sg;
73 131 foreach my $arg (split /=>/, $args) {
74 155 ▶ if (Test::Class::MethodInfo->is_num_tests($arg)) {
Branch: 2 branches
BranchTrueFalseTotal
if ('Test::Class::MethodInfo'->is_num_tests($arg)) { } 103 52 155
elsif ('Test::Class::MethodInfo'->is_method_type($arg)) { } 51 1 52
75 103 $num_tests = $arg;
76 } elsif (Test::Class::MethodInfo->is_method_type($arg)) {
77 51 $type = $arg;
78 } else {
79 1 die 'bad attribute args';
80 }
81 }
82 130 return( $type, $num_tests );
83 }
84  
85 131 ▶sub _is_public_method {
Subroutine _is_public_method: called CC=4 SCAR=13.9
86 131 my ($class, $name) = @_;
87 131 my @parents = @{mro::get_linear_isa($class)};
88 131 shift @parents;
89 131 foreach my $parent_class ( @parents ) {
90 132 ▶ return unless $parent_class->can( $name );
Branch: 1 branch
BranchTrueFalseTotal
unless $parent_class->can($name) 126 6 132
91 6 ▶ return if _method_info( $class, $parent_class, $name );
Branch: 1 branch
BranchTrueFalseTotal
if _method_info($class, $parent_class, $name) 4 2 6
92 }
93 1 return 1;
94 }
95  
96 132 ▶sub Test : ATTR(CODE,RAWDATA) {
Subroutine Test: called CC=4 SCAR=13.9
Pod documented
97 132 my ($class, $symbol, $code_ref, $attr, $args) = @_;
98 132 ▶ if ($symbol eq "ANON") {
Branch: 1 branch
BranchTrueFalseTotal
if ($symbol eq 'ANON') { } 1 131 132
99 1 warn "cannot test anonymous subs - you probably loaded a Test::Class too late (after the CHECK block was run). See 'A NOTE ON LOADING TEST CLASSES' in perldoc Test::Class for more details\n";
100 } else {
101 131 my $name = *{$symbol}{NAME};
102 131 ▶ warn "overriding public method $name with a test method in $class\n"
Branch: 1 branch
BranchTrueFalseTotal
if _is_public_method($class, $name) 1 130 131
103 if _is_public_method( $class, $name );
104 131 ▶ eval { $class->add_testinfo($name, _parse_attribute_args($args)) }
Branch: 1 branch
BranchTrueFalseTotal
eval { do { $class->add_testinfo($name, _parse_attribute_args($args)) } } or warn "bad test definition '${args}' in $class->$name\n" 130 1 131
105 || warn "bad test definition '$args' in $class->$name\n";
106 }
107 55 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
108  
109 16 ▶sub Tests : ATTR(CODE,RAWDATA) {
Subroutine Tests: called CC=2 SCAR=6.9
Pod documented
110 16 my ($class, $symbol, $code_ref, $attr, $args) = @_;
111 16 ▶ $args ||= 'no_plan';
Condition100%2/2
$args ||= "no_plan"
l!l
97
MC/DC100%1/1
$args ||= "no_plan"
$args
Truth table100%2/2
A
A= $args
Aresult
11
00
112 16 Test( $class, $symbol, $code_ref, $attr, $args );
113 55 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
114  
115 130 ▶sub add_testinfo {
Subroutine add_testinfo: called CC=1 SCAR=0.0
Pod documented
116 130 my($class, $name, $type, $num_tests) = @_;
117 130 $Tests->{$class}->{$name} = Test::Class::MethodInfo->new(
118 name => $name,
119 num_tests => $num_tests,
120 type => $type,
121 );
122 }
123  
124 677 ▶sub _class_of {
Subroutine _class_of: called CC=2 SCAR=6.9
125 677 my $self = shift;
126 677 ▶ return ref $self ? ref $self : $self;
Branch: 1 branch
BranchTrueFalseTotal
ref $self ? : 549 128 677
127 }
128  
129 63 ▶sub new {
Subroutine new: called CC=2 SCAR=6.9
Pod documented
130 63 my $proto = shift;
131 63 my $class = _class_of( $proto );
132 63 ▶ $proto = {} unless ref($proto);
Branch: 1 branch
BranchTrueFalseTotal
unless ref $proto 62 1 63
133 63 my $self = bless {%$proto, @_}, $class;
134 63 $_Test{$self} = dclone($Tests);
135 63 return($self);
136 }
137  
138 322 ▶sub _get_methods {
Subroutine _get_methods: called CC=12 SCAR=24.8
139 322 my ( $self, @types ) = @_;
140 322 my $test_class = _class_of( $self );
141  
142 322 ▶ my $test_method_regexp = $ENV{ TEST_METHOD } || '.*';
Condition100%2/2
$ENV{'TEST_METHOD'} || '.*'
l!l
11311
MC/DC100%1/1
$ENV{'TEST_METHOD'} || '.*'
$ENV{'TEST_METHOD'}
Truth table100%2/2
A
A= $ENV{'TEST_METHOD'}
Aresult
11
00
143 322 my $method_regexp = eval { qr/\A$test_method_regexp\z/ };
144 322 ▶ die "TEST_METHOD ($test_method_regexp) is not a valid regexp: $@" if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 1 321 322
145  
146 321 my %methods = ();
147 321 foreach my $class ( @{mro::get_linear_isa( $test_class )} ) {
148 FILTER:
149 638 foreach my $info ( _methods_of_class( $self, $class ) ) {
150 807 my $name = $info->name;
151  
152 807 ▶ if ( $info->type eq TEST ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($info->type eq "test") 475 332 807
153 # determine if method is filtered, true if *any* filter
154 # returns false.
155 475 foreach my $filter ( @Filters ) {
156 90 ▶ next FILTER unless $filter->( $class, $name );
Branch: 1 branch
BranchTrueFalseTotal
unless &$filter($class, $name) 34 56 90
157 }
158 }
159  
160 773 foreach my $type ( @types ) {
161 907 ▶ if ( $info->is_type( $type ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($info->is_type($type)) 184 723 907
162 184 ▶ $methods{ $name } = 1
Branch: 1 branch
BranchTrueFalseTotal
unless $type eq "test" and not $name =~ /$method_regexp/ 181 3 184
Condition100%3/3
$type eq "test" and not $name =~ /$method_regexp/
!ll&&!rl&&r
82993
MC/DC100%2/2
$type eq "test" and not $name =~ /$method_regexp/
$type eq "test" not $name =~ /$method_regexp/
Truth table100%3/3
A and not(B)
A= $type eq "test"B= not $name =~ /$method_regexp/
ABresult
0X0
100
111
163 unless $type eq TEST && $name !~ $method_regexp;
164 }
165 }
166 }
167 }
168  
169 320 my @methods = sort keys %methods;
170 320 return @methods;
171 }
172  
173 47 ▶sub _num_expected_tests {
Subroutine _num_expected_tests: called CC=7 SCAR=19.5
174 47 my $self = shift;
175 47 ▶ if (my $reason = $self->SKIP_CLASS ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $reason = $self->SKIP_CLASS) 2 45 47
176 2 ▶ return $reason eq "1" ? 0 : 1;
Branch: 1 branch
BranchTrueFalseTotal
$reason eq '1' ? : 1 1 2
177 };
178 45 my @test_methods = _get_methods($self, TEST);
179 45 ▶ return 0 unless @test_methods;
Branch: 1 branch
BranchTrueFalseTotal
unless @test_methods 23 22 45
180 22 my @startup_shutdown_methods =
181 _get_methods($self, STARTUP, SHUTDOWN);
182 22 my $num_startup_shutdown_methods =
183 _total_num_tests($self, @startup_shutdown_methods);
184 22 ▶ return(NO_PLAN) if $num_startup_shutdown_methods eq NO_PLAN;
Branch: 1 branch
BranchTrueFalseTotal
if $num_startup_shutdown_methods eq "no_plan" 2 20 22
185 20 my @fixture_methods = _get_methods($self, SETUP, TEARDOWN);
186 20 my $num_fixture_tests = _total_num_tests($self, @fixture_methods);
187 20 ▶ return(NO_PLAN) if $num_fixture_tests eq NO_PLAN;
Branch: 1 branch
BranchTrueFalseTotal
if $num_fixture_tests eq "no_plan" 2 18 20
188 18 my $num_tests = _total_num_tests($self, @test_methods);
189 18 ▶ return(NO_PLAN) if $num_tests eq NO_PLAN;
Branch: 1 branch
BranchTrueFalseTotal
if $num_tests eq "no_plan" 4 14 18
190 14 return($num_startup_shutdown_methods + $num_tests + @test_methods * $num_fixture_tests);
191 }
192  
193 23 ▶sub expected_tests {
Subroutine expected_tests: called CC=7 SCAR=19.5
Pod documented
194 23 my $total = 0;
195 23 foreach my $test (@_) {
196 53 ▶ if ( _isa_class( __PACKAGE__, $test ) ) {
Branch: 2 branches
BranchTrueFalseTotal
if (_isa_class(__PACKAGE__, $test)) { } 47 6 53
elsif (defined $test and $test =~ /^\d+$/) { } 4 2 6
197 47 my $n = _num_expected_tests($test);
198 47 ▶ return NO_PLAN if $n eq NO_PLAN;
Branch: 1 branch
BranchTrueFalseTotal
if $n eq "no_plan" 8 39 47
199 39 $total += $n;
200 ▶ } elsif ( defined $test && $test =~ m/^\d+$/ ) {
Condition100%3/3
defined $test and $test =~ /^\d+$/
!ll&&!rl&&r
114
MC/DC100%2/2
defined $test and $test =~ /^\d+$/
defined $test $test =~ /^\d+$/
Truth table100%3/3
A and B
A= defined $testB= $test =~ /^\d+$/
ABresult
0X0
100
111
201 4 $total += $test;
202 } else {
203 2 ▶ $test = 'undef' unless defined $test;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $test 1 1 2
204 1 croak "$test is not a Test::Class or an integer";
205 }
206 }
207 13 return $total;
208 }
209  
210 292 ▶sub _total_num_tests {
Subroutine _total_num_tests: called CC=6 SCAR=17.9
211 292 my ($self, @methods) = @_;
212 292 my $class = _class_of( $self );
213 292 my $total_num_tests = 0;
214 292 foreach my $method (@methods) {
215 293 foreach my $class (@{mro::get_linear_isa($class)}) {
216 332 my $info = _method_info($self, $class, $method);
217 332 ▶ next unless $info;
Branch: 1 branch
BranchTrueFalseTotal
unless $info 31 301 332
218 301 my $num_tests = $info->num_tests;
219 301 ▶ return(NO_PLAN) if ($num_tests eq NO_PLAN);
Branch: 1 branch
BranchTrueFalseTotal
if $num_tests eq "no_plan" 24 277 301
220 277 $total_num_tests += $num_tests;
221 277 ▶ last unless $num_tests =~ m/^\+/
Branch: 1 branch
BranchTrueFalseTotal
unless $num_tests =~ /^\+/ 266 11 277
222 }
223 }
224 268 return($total_num_tests);
225 }
226  
227 116 ▶sub _has_no_tests {
Subroutine _has_no_tests: called CC=1 SCAR=0.0
228 116 my ( $self, $method ) = @_;
229 116 return _total_num_tests( $self, $method ) eq '0';
230 }
231  
232 114 ▶sub _all_ok_from {
Subroutine _all_ok_from: called CC=5 SCAR=16.2
233 114 my ($self, $start_test) = @_;
234  
235 # The Test::Builder 1.5 way to do it
236 114 ▶ if( $Builder->can("history") ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Builder->can('history')) { } 0 114 114
237 0 return $Builder->history->can_succeed;
238 }
239 # The Test::Builder 0.x way to do it
240 else {
241 114 my $current_test = $Builder->current_test;
242 114 ▶ return(1) if $start_test == $current_test;
Branch: 1 branch
BranchTrueFalseTotal
if $start_test == $current_test 5 109 114
243 109 my @results = ($Builder->summary)[$start_test .. $current_test-1];
244 109 ▶ foreach my $result (@results) { return(0) unless $result }
Branch: 1 branch
BranchTrueFalseTotal
unless $result 15 125 140
245 94 return(1);
246 }
247 }
248  
249 9 ▶sub _exception_failure {
Subroutine _exception_failure: called CC=3 SCAR=11.0
250 9 my ($self, $method, $exception, $tests) = @_;
251 9 local $Test::Builder::Level = 3;
252 9 my $message = $method;
253 9 ▶ $message .= " (for test method '$Current_method')"
Branch: 1 branch
BranchTrueFalseTotal
if defined $Test::Class::Current_method and $method ne $Test::Class::Current_method 2 7 9
Condition100%3/3
defined $Test::Class::Current_method and $method ne $Test::Class::Current_method
!ll&&!rl&&r
162
MC/DC100%2/2
defined $Test::Class::Current_method and $method ne $Test::Class::Current_method
defined $Test::Class::Current_method $method ne $Test::Class::Current_method
Truth table100%3/3
A and B
A= defined $Test::Class::Current_methodB= $method ne $Test::Class::Current_method
ABresult
0X0
100
111
254 if defined $Current_method && $method ne $Current_method;
255 9 _show_header($self, @$tests);
256 9 chomp $exception;
257 9 $Builder->ok(0, "$message died ($exception)");
258 9 _threw_exception( $self, $method => 1 );
259 }
260  
261 my %threw_exception;
262 223 ▶sub _threw_exception {
Subroutine _threw_exception: called CC=2 SCAR=6.9
263 223 my ( $self, $method, $optional_value) = @_;
264 223 my $class = ref( $self );
265 223 ▶ $threw_exception{ $class }{ $method } = $optional_value
Branch: 1 branch
BranchTrueFalseTotal
if defined $optional_value 125 98 223
266 if defined $optional_value;
267 223 return $threw_exception{ $class }{ $method };
268 }
269  
270 116 ▶sub _run_method {
Subroutine _run_method: called CC=10 SCAR=23.0
271 116 my ($self, $method, $tests) = @_;
272 116 _threw_exception( $self, $method => 0 );
273 116 my $num_start = $Builder->current_test;
274 116 my $skip_reason;
275 116 my $original_ok = \&Test::Builder::ok;
276 55 ▶ no warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
277 146 ▶ local *Test::Builder::ok = sub {
Subroutine __ANON__: called CC=3 SCAR=11.0
278 146 my ($builder, $test, $description) = @_;
279 146 local $Test::Builder::Level = $Test::Builder::Level+1;
280 146 ▶ unless ( defined($description) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $description) 22 124 146
281 22 $description = $self->current_method;
282 22 $description =~ tr/_/ /;
283 }
284 146 my $is_ok = $original_ok->($builder, $test, $description);
285 146 ▶ unless ( $is_ok ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($is_ok) 20 126 146
286 20 my $class = ref $self;
287 20 $Builder->diag( " (in $class->$method)" );
288 }
289 146 return $is_ok;
290 116 };
291  
292 116 my $exception;
293 116 ▶ $skip_reason = try { $self->$method } catch { $exception = $_; undef };
Subroutine __ANON__: called CC=1 SCAR=0.0
Subroutine __ANON__: called CC=1 SCAR=0.0
294 114 ▶ $skip_reason = $method unless $skip_reason;
Branch: 1 branch
BranchTrueFalseTotal
unless $skip_reason 17 97 114
295  
296 114 my $num_done = $Builder->current_test - $num_start;
297 114 my $num_expected = _total_num_tests($self, $method);
298 114 ▶ $num_expected = $num_done if $num_expected eq NO_PLAN;
Branch: 1 branch
BranchTrueFalseTotal
if $num_expected eq "no_plan" 7 107 114
299 114 ▶ if ($num_done == $num_expected) {
Branch: 2 branches
BranchTrueFalseTotal
if ($num_done == $num_expected) { } 101 13 114
elsif ($num_done > $num_expected) { } 5 8 13
300 101 ▶ _exception_failure($self, $method, $exception, $tests)
Branch: 1 branch
BranchTrueFalseTotal
if $exception 5 96 101
301 if $exception;
302 } elsif ($num_done > $num_expected) {
303 5 local $Test::Builder::Level = $Test::Builder::Level+1;
304 5 my $class = ref $self;
305 5 ▶ if ($self->fail_if_returned_late) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->fail_if_returned_late) { } 2 3 5
306 2 $Builder->ok(0, "expected $num_expected test(s) in $class\::$method, $num_done completed");
307 } else {
308 3 $Builder->diag("expected $num_expected test(s) in $class\::$method, $num_done completed\n");
309 }
310 } else {
311 8 ▶ until (($Builder->current_test - $num_start) >= $num_expected) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($Builder->current_test - $num_start >= $num_expected) 10 8 18
312 10 ▶ if ($exception) {
Branch: 1 branch
BranchTrueFalseTotal
if ($exception) { } 4 6 10
313 4 _exception_failure($self, $method, $exception, $tests);
314 4 $skip_reason = "$method died";
315 4 $exception = '';
316 } else {
317 6 local $Test::Builder::Level = $Test::Builder::Level+1;
318 6 ▶ if ($self->fail_if_returned_early) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->fail_if_returned_early) { } 3 3 6
319 3 my $class = ref $self;
320 3 $Builder->ok(0, "($class\::$method returned before plan complete)");
321 } else {
322 3 $Builder->skip( $skip_reason );
323 }
324 }
325 }
326 }
327 114 return(_all_ok_from($self, $num_start));
328 }
329  
330 3 ▶sub fail_if_returned_early { 0 }
Subroutine fail_if_returned_early: called CC=1 SCAR=0.0
Pod documented
331 3 ▶sub fail_if_returned_late { 0 }
Subroutine fail_if_returned_late: called CC=1 SCAR=0.0
Pod documented
332  
333 120 ▶sub _show_header {
Subroutine _show_header: called CC=3 SCAR=11.0
334 120 my ($self, @tests) = @_;
335 120 ▶ return if $Builder->has_plan;
Branch: 1 branch
BranchTrueFalseTotal
if $Builder->has_plan 110 10 120
336 10 my $num_tests = Test::Class->expected_tests(@tests);
337 10 ▶ if ($num_tests eq NO_PLAN) {
Branch: 1 branch
BranchTrueFalseTotal
if ($num_tests eq 'no_plan') { } 1 9 10
338 1 $Builder->no_plan;
339 } else {
340 9 $Builder->expected_tests($num_tests);
341 }
342 }
343  
344 55 my %SKIP_THIS_CLASS = ();
345  
346 116 ▶sub SKIP_CLASS {
Subroutine SKIP_CLASS: called CC=2 SCAR=6.9
Pod documented
347 116 my $class = shift;
348 116 ▶ $SKIP_THIS_CLASS{ $class } = shift if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 3 113 116
349 116 return $SKIP_THIS_CLASS{ $class };
350 }
351  
352 143 ▶sub _isa_class {
Subroutine _isa_class: called CC=4 SCAR=13.9
353 143 my ( $class, $object_or_class ) = @_;
354 143 ▶ return unless defined $object_or_class;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $object_or_class 1 142 143
355 142 ▶ return if $object_or_class eq 'Contextual::Return::Value';
Branch: 1 branch
BranchTrueFalseTotal
if $object_or_class eq "Contextual::Return::Value" 0 142 142
356 142 return eval {
357 142 ▶ $object_or_class->isa( $class ) and $object_or_class->can( 'runtests' )
Branch: 1 branch
BranchTrueFalseTotal
$object_or_class->isa($class) and $object_or_class->can("runtests") 130 12 142
358 };
359 }
360  
361 41 ▶sub _test_classes {
Subroutine _test_classes: called CC=1 SCAR=0.0
362 41 my $class = shift;
363 41 return( @{mro::get_isarev($class)}, $class );
364 }
365  
366 49 ▶sub runtests {
Subroutine runtests: called CC=26 SCAR=32.6
Pod documented
367 49 ▶ die "Test::Class was loaded too late (after the CHECK block was run), or you may have redefined a test_ sub. See 'A NOTE ON LOADING TEST CLASSES' in perldoc Test::Class for more details\n"
Branch: 1 branch
BranchTrueFalseTotal
unless $Check_block_has_run 1 48 49
368 unless $Check_block_has_run;
369 48 my @tests = @_;
370 48 ▶ if (@tests == 1 && !ref($tests[0])) {
Branch: 1 branch
BranchTrueFalseTotal
if (@tests == 1 and not ref $tests[0]) 39 9 48
Condition100%3/3
@tests == 1 and not ref $tests[0]
!ll&&!rl&&r
4539
MC/DC100%2/2
@tests == 1 and not ref $tests[0]
@tests == 1 not ref $tests[0]
Truth table100%3/3
A and not(B)
A= @tests == 1B= not ref $tests[0]
ABresult
0X0
100
111
371 39 my $base_class = shift @tests;
372 39 @tests = _test_classes( $base_class );
373 }
374 48 my $all_passed = 1;
375 48 TEST_OBJECT: foreach my $t (@tests) {
376 # SHOULD ALSO ALLOW NO_PLAN
377 67 ▶ next if $t =~ m/^\d+$/;
Branch: 1 branch
BranchTrueFalseTotal
if $t =~ /^\d+$/ 3 64 67
378 64 ▶ croak "$t is not Test::Class or integer"
Branch: 1 branch
BranchTrueFalseTotal
unless _isa_class(__PACKAGE__, $t) 1 63 64
379 unless _isa_class( __PACKAGE__, $t );
380 63 ▶ if (my $reason = $t->SKIP_CLASS) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $reason = $t->SKIP_CLASS) { } 3 60 63
381 3 _show_header($t, @tests);
382 3 ▶ $Builder->skip( $reason ) unless $reason eq "1";
Branch: 1 branch
BranchTrueFalseTotal
unless $reason eq 1 1 2 3
383 } else {
384 60 ▶ $t = $t->new unless ref($t);
Branch: 1 branch
BranchTrueFalseTotal
unless ref $t 55 5 60
385 60 my @test_methods = _get_methods($t, TEST);
386 58 ▶ if ( @test_methods ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@test_methods) 45 13 58
387 45 foreach my $method (_get_methods($t, STARTUP)) {
388 8 ▶ _show_header($t, @tests) unless _has_no_tests($t, $method);
Branch: 1 branch
BranchTrueFalseTotal
unless _has_no_tests($t, $method) 7 1 8
389 8 my $method_passed = _run_method($t, $method, \@tests);
390 8 ▶ $all_passed = 0 unless $method_passed;
Branch: 1 branch
BranchTrueFalseTotal
unless $method_passed 1 7 8
391 8 ▶ next TEST_OBJECT unless $method_passed;
Branch: 1 branch
BranchTrueFalseTotal
unless $method_passed 1 7 8
392 }
393 44 my $class = ref($t);
394 44 my @setup = _get_methods($t, SETUP);
395 44 my @teardown = _get_methods($t, TEARDOWN);
396 44 foreach my $test ( @test_methods ) {
397 64 local $Current_method = $test;
398 64 ▶ $Builder->diag("\n$class->$test") if $ENV{TEST_VERBOSE};
Branch: 1 branch
BranchTrueFalseTotal
if $ENV{"TEST_VERBOSE"} 3 61 64
399 64 my @methods_to_run = (@setup, $test, @teardown);
400 64 ▶ while ( my $method = shift @methods_to_run ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $method = shift @methods_to_run) 100 60 160
401 100 ▶ _show_header($t, @tests) unless _has_no_tests($t, $method);
Branch: 1 branch
BranchTrueFalseTotal
unless _has_no_tests($t, $method) 94 6 100
402 100 ▶ $all_passed = 0 unless _run_method($t, $method, \@tests);
Branch: 1 branch
BranchTrueFalseTotal
unless _run_method($t, $method, \@tests) 14 84 98
403 98 ▶ if ( _threw_exception( $t, $method ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (_threw_exception($t, $method)) 8 90 98
404 8 ▶ next if ($method eq $test);
Branch: 1 branch
BranchTrueFalseTotal
if $method eq $test 6 2 8
405 2 my $num_to_skip = _total_num_tests($t, @methods_to_run);
406 2 $Builder->skip( "$method died" ) for ( 1 .. $num_to_skip );
407 2 last;
408 }
409 }
410 }
411 42 foreach my $method (_get_methods($t, SHUTDOWN)) {
412 8 ▶ _show_header($t, @tests) unless _has_no_tests($t, $method);
Branch: 1 branch
BranchTrueFalseTotal
unless _has_no_tests($t, $method) 7 1 8
413 8 ▶ $all_passed = 0 unless _run_method($t, $method, \@tests);
Branch: 1 branch
BranchTrueFalseTotal
unless _run_method($t, $method, \@tests) 0 8 8
414 }
415 }
416  
417 }
418 }
419 43 return($all_passed);
420 }
421  
422 21 ▶sub _find_calling_test_class {
Subroutine _find_calling_test_class: called CC=4 SCAR=13.9
423 21 my $level = 0;
424 21 ▶ while (my $class = caller(++$level)) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $class = caller ++$level) 35 1 36
425 35 ▶ next if $class eq __PACKAGE__;
Branch: 1 branch
BranchTrueFalseTotal
if $class eq __PACKAGE__ 9 26 35
426 26 ▶ return $class if _isa_class( __PACKAGE__, $class );
Branch: 1 branch
BranchTrueFalseTotal
if _isa_class(__PACKAGE__, $class) 20 6 26
427 }
428 1 return(undef);
429 }
430  
431 21 ▶sub num_method_tests {
Subroutine num_method_tests: called CC=4 SCAR=13.9
Pod documented
432 21 my ($self, $method, $n) = @_;
433 21 ▶ my $class = _find_calling_test_class( $self )
Branch: 1 branch
BranchTrueFalseTotal
my $class = _find_calling_test_class($self) or croak("not called in a Test::Class") 20 1 21
434 or croak "not called in a Test::Class";
435 20 ▶ my $info = _method_info($self, $class, $method)
Branch: 1 branch
BranchTrueFalseTotal
my $info = _method_info($self, $class, $method) or croak("$method is not a test method of class $class") 19 1 20
436 or croak "$method is not a test method of class $class";
437 19 ▶ $info->num_tests($n) if defined($n);
Branch: 1 branch
BranchTrueFalseTotal
if defined $n 6 13 19
438 18 return( $info->num_tests );
439 }
440  
441 9 ▶sub num_tests {
Subroutine num_tests: called CC=2 SCAR=7.1
Pod documented
442 9 my $self = shift;
443 9 ▶ croak "num_tests need to be called within a test method"
Branch: 1 branch
BranchTrueFalseTotal
unless defined $Test::Class::Current_method 0 9 9
444 unless defined $Current_method;
445 9 return( $self->num_method_tests( $Current_method, @_ ) );
446 }
447  
448 1 ▶sub BAILOUT {
Subroutine BAILOUT: called CC=1 SCAR=0.0
Pod documented
449 1 my ($self, $reason) = @_;
450 1 $Builder->BAILOUT($reason);
451 }
452  
453 4 ▶sub _last_test_if_exiting_immediately {
Subroutine _last_test_if_exiting_immediately: called CC=2 SCAR=6.9
454 4 ▶ $Builder->expected_tests || $Builder->current_test+1
Branch: 1 branch
BranchTrueFalseTotal
$Builder->expected_tests or $Builder->current_test + 1 3 1 4
455 }
456  
457 3 ▶sub FAIL_ALL {
Subroutine FAIL_ALL: called CC=5 SCAR=16.6
Pod documented
458 3 my ($self, $reason) = @_;
459 3 my $last_test = _last_test_if_exiting_immediately();
460 3 ▶ $Builder->expected_tests( $last_test ) unless $Builder->has_plan;
Branch: 1 branch
BranchTrueFalseTotal
unless $Builder->has_plan 0 3 3
461 3 ▶ $Builder->ok(0, $reason) until $Builder->current_test >= $last_test;
Branch: 1 branch
BranchTrueFalseTotal
$Builder->current_test >= $last_test or do { $Builder->ok(0, $reason) } 3 4 7
462 3 ▶ my $num_failed = $Builder->can("history")
Branch: 1 branch
BranchTrueFalseTotal
$Builder->can('history') ? : 0 3 3
463 ? $Builder->history->fail_count : grep( !$_, $Builder->summary );
464 3 ▶ exit( $num_failed < 254 ? $num_failed : 254 );
Branch: 1 branch
BranchTrueFalseTotal
$num_failed < 254 ? : 3 0 3
465 }
466  
467 2 ▶sub SKIP_ALL {
Subroutine SKIP_ALL: called CC=3 SCAR=11.0
Pod documented
468 2 my ($self, $reason) = @_;
469 2 ▶ $Builder->skip_all( $reason ) unless $Builder->has_plan;
Branch: 1 branch
BranchTrueFalseTotal
unless $Builder->has_plan 1 1 2
470 1 my $last_test = _last_test_if_exiting_immediately();
471 1 ▶ $Builder->skip( $reason )
Branch: 1 branch
BranchTrueFalseTotal
$Builder->current_test >= $last_test or do { $Builder->skip($reason) } 1 3 4
472 until $Builder->current_test >= $last_test;
473 1 exit(0);
474 }
475  
476 6 ▶sub add_filter {
Subroutine add_filter: called CC=2 SCAR=6.9
Pod documented
477 6 my ( $class, $cb ) = @_;
478  
479 6 ▶ if ( not ref $cb eq 'CODE' ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $cb eq "CODE") 1 5 6
480 1 croak "Filter isn't a code-ref"
481 }
482  
483 5 push @Filters, $cb;
484 }
485  
486 55 1;
487  
488 __END__
↑ Summary Class/MethodInfo.pm »