line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Test::Unit::TestCase; |
2
|
2
|
|
|
2
|
|
14
|
use strict; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
113
|
|
3
|
|
|
|
|
|
|
|
4
|
2
|
|
|
2
|
|
13
|
use base qw(Test::Unit::Test); |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
177
|
|
5
|
|
|
|
|
|
|
|
6
|
2
|
|
|
2
|
|
11
|
use Test::Unit::Debug qw(debug); |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
96
|
|
7
|
2
|
|
|
2
|
|
11
|
use Test::Unit::Failure; |
|
2
|
|
|
|
|
15
|
|
|
2
|
|
|
|
|
23
|
|
8
|
2
|
|
|
2
|
|
85
|
use Test::Unit::Error; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
11
|
|
9
|
2
|
|
|
2
|
|
71
|
use Test::Unit::Result; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
91
|
|
10
|
|
|
|
|
|
|
|
11
|
2
|
|
|
2
|
|
9
|
use Devel::Symdump; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
59
|
|
12
|
2
|
|
|
2
|
|
3707
|
use Class::Inner; |
|
2
|
|
|
|
|
1437
|
|
|
2
|
|
|
|
|
56
|
|
13
|
2
|
|
|
2
|
|
13
|
use Error qw/:try/; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
13
|
|
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
sub new { |
16
|
139
|
|
|
139
|
0
|
34846
|
my $class = shift; |
17
|
139
|
|
|
|
|
229
|
my ($name) = @_; |
18
|
139
|
|
|
|
|
1456
|
bless { |
19
|
|
|
|
|
|
|
__PACKAGE__ . '_name' => $name, |
20
|
|
|
|
|
|
|
__PACKAGE__ . '_annotations' => '', |
21
|
|
|
|
|
|
|
}, $class; |
22
|
|
|
|
|
|
|
} |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
sub annotate { |
25
|
0
|
|
|
0
|
1
|
0
|
my $self = shift; |
26
|
0
|
|
|
|
|
0
|
$self->{__PACKAGE__ . '_annotations'} .= join '', @_; |
27
|
|
|
|
|
|
|
} |
28
|
|
|
|
|
|
|
|
29
|
6
|
|
|
6
|
0
|
71
|
sub annotations { $_[0]->{__PACKAGE__ . '_annotations'} } |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
sub count_test_cases { |
32
|
85
|
|
|
85
|
0
|
449
|
my $self = shift; |
33
|
85
|
|
|
|
|
552
|
return 1; |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
sub create_result { |
37
|
18
|
|
|
18
|
0
|
30
|
my $self = shift; |
38
|
18
|
|
|
|
|
121
|
return Test::Unit::Result->new(); |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
sub name { |
42
|
844
|
|
|
844
|
0
|
1457
|
my $self = shift; |
43
|
844
|
|
|
|
|
4511
|
return $self->{__PACKAGE__ . '_name'}; |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
sub run { |
47
|
126
|
|
|
126
|
0
|
488
|
my $self = shift; |
48
|
126
|
|
|
|
|
387
|
debug(ref($self), "::run() called on ", $self->name, "\n"); |
49
|
126
|
|
|
|
|
256
|
my ($result, $runner) = @_; |
50
|
126
|
|
66
|
|
|
431
|
$result ||= create_result(); |
51
|
126
|
|
|
|
|
406
|
$result->run($self); |
52
|
126
|
|
|
|
|
571
|
return $result; |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
sub run_bare { |
56
|
126
|
|
|
126
|
0
|
264
|
my $self = shift; |
57
|
126
|
|
|
|
|
356
|
debug(" ", ref($self), "::run_bare() called on ", $self->name, "\n"); |
58
|
126
|
|
|
|
|
709
|
$self->set_up(); |
59
|
|
|
|
|
|
|
# Make sure tear_down happens if and only if set_up() succeeds. |
60
|
|
|
|
|
|
|
try { |
61
|
123
|
|
|
123
|
|
2233
|
$self->run_test(); |
62
|
99
|
|
|
|
|
7788
|
1; |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
finally { |
65
|
123
|
|
|
123
|
|
4747
|
$self->tear_down; |
66
|
123
|
|
|
|
|
815
|
}; |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
sub run_test { |
70
|
64
|
|
|
64
|
0
|
108
|
my $self = shift; |
71
|
64
|
|
|
|
|
229
|
debug(" ", ref($self) . "::run_test() called on ", $self->name, "\n"); |
72
|
64
|
|
|
|
|
171
|
my $method = $self->name(); |
73
|
64
|
100
|
|
|
|
437
|
if ($self->can($method)) { |
74
|
63
|
|
|
|
|
252
|
debug(" running `$method'\n"); |
75
|
63
|
|
|
|
|
280
|
$self->$method(); |
76
|
|
|
|
|
|
|
} else { |
77
|
1
|
|
|
|
|
10
|
$self->fail(" Method `$method' not found"); |
78
|
|
|
|
|
|
|
} |
79
|
|
|
|
|
|
|
} |
80
|
|
|
|
|
|
|
|
81
|
106
|
|
|
106
|
1
|
174
|
sub set_up { 1 } |
82
|
|
|
|
|
|
|
|
83
|
113
|
|
|
113
|
1
|
279
|
sub tear_down { 1 } |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
sub to_string { |
86
|
19
|
|
|
19
|
0
|
45
|
my $self = shift; |
87
|
19
|
|
|
|
|
33
|
my $class = ref($self); |
88
|
19
|
|
50
|
|
|
44
|
return ($self->name() || "ANON") . "(" . $class . ")"; |
89
|
|
|
|
|
|
|
} |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
sub make_test_from_coderef { |
92
|
40
|
|
|
40
|
1
|
470
|
my ($self, $coderef, @args) = @_; |
93
|
40
|
50
|
|
|
|
87
|
die "Need a coderef argument" unless $coderef; |
94
|
40
|
|
33
|
|
|
524
|
return Class::Inner->new(parent => ($self || ref $self), |
95
|
|
|
|
|
|
|
methods => {run_test => $coderef}, |
96
|
|
|
|
|
|
|
args => [ @args ]); |
97
|
|
|
|
|
|
|
} |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
# Returns a list of the tests run by this class and its superclasses. |
101
|
|
|
|
|
|
|
# DO NOT OVERRIDE THIS UNLESS YOU KNOW WHAT YOU ARE DOING! |
102
|
|
|
|
|
|
|
sub list_tests { |
103
|
49
|
|
33
|
49
|
1
|
219
|
my $class = ref($_[0]) || $_[0]; |
104
|
49
|
|
|
|
|
86
|
my @tests = (); |
105
|
2
|
|
|
2
|
|
1627
|
no strict 'refs'; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
1050
|
|
106
|
49
|
50
|
|
|
|
56
|
if (defined(@{"$class\::TESTS"})) { |
|
49
|
|
|
|
|
328
|
|
107
|
0
|
|
|
|
|
0
|
push @tests, @{"$class\::TESTS"}; |
|
0
|
|
|
|
|
0
|
|
108
|
|
|
|
|
|
|
} |
109
|
|
|
|
|
|
|
else { |
110
|
49
|
|
|
|
|
307
|
push @tests, $class->get_matching_methods(qr/::(test[^:]*)$/); |
111
|
|
|
|
|
|
|
} |
112
|
49
|
100
|
|
|
|
168
|
push @tests, map {$_->can('list_tests') ? $_->list_tests : () } @{"$class\::ISA"}; |
|
52
|
|
|
|
|
575
|
|
|
49
|
|
|
|
|
248
|
|
113
|
49
|
|
|
|
|
105
|
my %tests = map {$_ => ''} @tests; |
|
95
|
|
|
|
|
288
|
|
114
|
49
|
|
|
|
|
216
|
return keys %tests; |
115
|
|
|
|
|
|
|
} |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
sub get_matching_methods { |
118
|
49
|
|
33
|
49
|
1
|
153
|
my $class = ref($_[0]) || $_[0]; |
119
|
49
|
|
|
|
|
66
|
my $re = $_[1]; |
120
|
49
|
|
|
|
|
35033
|
my $st = Devel::Symdump->new($class); |
121
|
49
|
100
|
|
|
|
2536
|
return map { /$re/ ? $1 : () } $st->functions(); |
|
620
|
|
|
|
|
2708
|
|
122
|
|
|
|
|
|
|
} |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
sub list { |
125
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
126
|
0
|
|
|
|
|
|
my $show_testcases = shift; |
127
|
0
|
0
|
0
|
|
|
|
return $show_testcases ? |
128
|
|
|
|
|
|
|
[ ($self->name() || 'anonymous testcase') . "\n" ] |
129
|
|
|
|
|
|
|
: []; |
130
|
|
|
|
|
|
|
} |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
1; |
133
|
|
|
|
|
|
|
__END__ |