line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Test::Kantan::Builder; |
2
|
4
|
|
|
4
|
|
555
|
use strict; |
|
4
|
|
|
|
|
8
|
|
|
4
|
|
|
|
|
150
|
|
3
|
4
|
|
|
4
|
|
19
|
use warnings; |
|
4
|
|
|
|
|
5
|
|
|
4
|
|
|
|
|
105
|
|
4
|
4
|
|
|
4
|
|
19
|
use utf8; |
|
4
|
|
|
|
|
8
|
|
|
4
|
|
|
|
|
27
|
|
5
|
4
|
|
|
4
|
|
179
|
use 5.010_001; |
|
4
|
|
|
|
|
21
|
|
|
4
|
|
|
|
|
145
|
|
6
|
4
|
|
|
4
|
|
4659
|
use Module::Load; |
|
4
|
|
|
|
|
4699
|
|
|
4
|
|
|
|
|
44
|
|
7
|
4
|
|
|
4
|
|
210
|
use Try::Tiny; |
|
4
|
|
|
|
|
7
|
|
|
4
|
|
|
|
|
379
|
|
8
|
4
|
|
|
4
|
|
19
|
use File::Spec; |
|
4
|
|
|
|
|
7
|
|
|
4
|
|
|
|
|
79
|
|
9
|
4
|
|
|
4
|
|
20
|
use File::Path; |
|
4
|
|
|
|
|
8
|
|
|
4
|
|
|
|
|
236
|
|
10
|
|
|
|
|
|
|
|
11
|
4
|
|
|
4
|
|
22
|
use Test::Kantan::State; |
|
4
|
|
|
|
|
8
|
|
|
4
|
|
|
|
|
90
|
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
# Do not call this interface directly from your code. |
14
|
|
|
|
|
|
|
# After release TB2 and TB2 is good enough to me, I will replace this part with TB2. |
15
|
|
|
|
|
|
|
|
16
|
4
|
|
|
4
|
|
17
|
use Moo; |
|
4
|
|
|
|
|
24
|
|
|
4
|
|
|
|
|
27
|
|
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
has color => ( is => 'lazy' ); |
19
|
|
|
|
|
|
|
has state => ( is => 'lazy' ); |
20
|
|
|
|
|
|
|
has reporter => ( is => 'ro', 'builder' => '_build_reporter' ); |
21
|
|
|
|
|
|
|
has finished => ( is => 'rw', default => sub { 0 } ); |
22
|
|
|
|
|
|
|
has pid => (is => 'ro', default => sub { $$ }); |
23
|
|
|
|
|
|
|
has message_dir => (is => 'ro', 'builder' => '_build_message_dir' ); |
24
|
|
|
|
|
|
|
|
25
|
4
|
|
|
4
|
|
1680
|
no Moo; |
|
4
|
|
|
|
|
8
|
|
|
4
|
|
|
|
|
55
|
|
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
sub _build_color { |
28
|
3
|
50
|
|
3
|
|
1502
|
$ENV{KANTAN_COLOR} || -t *STDOUT; |
29
|
|
|
|
|
|
|
} |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
sub _build_state { |
32
|
61
|
|
|
61
|
|
3564
|
Test::Kantan::State->new(); |
33
|
|
|
|
|
|
|
} |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
sub _build_message_dir { |
36
|
61
|
|
|
61
|
|
330
|
my $self = shift; |
37
|
61
|
|
|
|
|
134
|
my $time = time; |
38
|
61
|
|
|
|
|
3488
|
File::Spec->catfile(File::Spec->tmpdir, "kantan.$$.${time}"); |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
sub _build_reporter { |
42
|
3
|
|
|
3
|
|
68
|
my $self = shift; |
43
|
|
|
|
|
|
|
|
44
|
3
|
|
|
|
|
5
|
my $reporter_class = do { |
45
|
3
|
|
50
|
|
|
27
|
my $s = $ENV{KANTAN_REPORTER} || 'Spec'; |
46
|
3
|
50
|
|
|
|
16
|
my $klass = ($s =~ s/\A\+// ? $s : "Test::Kantan::Reporter::${s}"); |
47
|
3
|
|
|
|
|
19
|
Module::Load::load $klass; |
48
|
3
|
|
|
|
|
41
|
$klass; |
49
|
|
|
|
|
|
|
}; |
50
|
3
|
|
|
|
|
39
|
my $reporter = $reporter_class->new( |
51
|
|
|
|
|
|
|
color => $self->color, |
52
|
|
|
|
|
|
|
state => $self->state, |
53
|
|
|
|
|
|
|
); |
54
|
3
|
|
|
|
|
39
|
$reporter->start; |
55
|
3
|
|
|
|
|
91
|
return $reporter; |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
sub ok { |
59
|
61
|
|
|
61
|
0
|
237
|
my ($self, %args) = @_; |
60
|
61
|
50
|
|
|
|
199
|
return if $self->care_child(\%args); |
61
|
|
|
|
|
|
|
|
62
|
61
|
|
|
|
|
212
|
my $caller = param(\%args, 'caller'); |
63
|
61
|
|
|
|
|
141
|
my $value = param(\%args, 'value'); |
64
|
61
|
|
|
|
|
238
|
my $description = param(\%args, 'description', {optional => 1}); |
65
|
|
|
|
|
|
|
|
66
|
61
|
100
|
|
|
|
184
|
if ($value) { |
67
|
39
|
|
|
|
|
1070
|
$self->state->passed(); |
68
|
39
|
|
|
|
|
212
|
$self->reporter->pass( |
69
|
|
|
|
|
|
|
caller => $caller, |
70
|
|
|
|
|
|
|
description => $description, |
71
|
|
|
|
|
|
|
); |
72
|
39
|
|
|
|
|
976
|
return 1; |
73
|
|
|
|
|
|
|
} else { |
74
|
22
|
|
|
|
|
648
|
$self->state->failed(); |
75
|
22
|
|
|
|
|
123
|
$self->reporter->fail( |
76
|
|
|
|
|
|
|
caller => $caller, |
77
|
|
|
|
|
|
|
description => $description, |
78
|
|
|
|
|
|
|
); |
79
|
22
|
|
|
|
|
631
|
return 0; |
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
sub care_child { |
84
|
62
|
|
|
62
|
0
|
112
|
my ($self, $args) = @_; |
85
|
62
|
50
|
|
|
|
502
|
return if $$ eq $self->pid; |
86
|
0
|
|
|
|
|
0
|
(my $meth = [caller(1)]->[3]) =~ s/.*:://; |
87
|
|
|
|
|
|
|
|
88
|
0
|
|
|
|
|
0
|
$self->push_child_message($meth, $args); |
89
|
|
|
|
|
|
|
} |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
sub exception { |
92
|
0
|
|
|
0
|
0
|
0
|
my ($self, %args) = @_; |
93
|
0
|
0
|
|
|
|
0
|
return if $self->care_child(\%args); |
94
|
0
|
|
|
|
|
0
|
my $message = param(\%args, 'message'); |
95
|
|
|
|
|
|
|
|
96
|
0
|
|
|
|
|
0
|
$self->state->failed(); |
97
|
0
|
|
|
|
|
0
|
$self->reporter->exception( |
98
|
|
|
|
|
|
|
message => $message, |
99
|
|
|
|
|
|
|
); |
100
|
|
|
|
|
|
|
} |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
sub param { |
103
|
195
|
|
|
195
|
0
|
321
|
my ($args, $key, $opts) = @_; |
104
|
|
|
|
|
|
|
|
105
|
195
|
50
|
66
|
|
|
558
|
if (exists $opts->{default} && not exists $args->{$key}) { |
106
|
0
|
|
|
|
|
0
|
$args->{$key} = $opts->{default}; |
107
|
|
|
|
|
|
|
} |
108
|
|
|
|
|
|
|
|
109
|
195
|
100
|
|
|
|
427
|
if (exists $args->{$key}) { |
110
|
171
|
|
|
|
|
467
|
delete $args->{$key}; |
111
|
|
|
|
|
|
|
} else { |
112
|
24
|
50
|
|
|
|
108
|
if ($opts->{optional}) { |
113
|
24
|
|
|
|
|
60
|
return undef; |
114
|
|
|
|
|
|
|
} else { |
115
|
0
|
|
|
|
|
0
|
Carp::confess "Missing mandatory parameter: ${key}"; |
116
|
|
|
|
|
|
|
} |
117
|
|
|
|
|
|
|
} |
118
|
|
|
|
|
|
|
} |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
sub diag { |
121
|
1
|
|
|
1
|
0
|
5
|
my ($self, %args) = @_; |
122
|
1
|
50
|
|
|
|
4
|
return if $self->care_child(\%args); |
123
|
1
|
|
|
|
|
4
|
my $message = param(\%args, 'message'); |
124
|
1
|
|
|
|
|
8
|
my $cutoff = param(\%args, 'cutoff', { default => $self->reporter->cutoff }); |
125
|
1
|
|
|
|
|
4
|
my $caller = param(\%args, 'caller'); |
126
|
|
|
|
|
|
|
|
127
|
1
|
|
|
|
|
8
|
$self->reporter->diag( |
128
|
|
|
|
|
|
|
message => $message, |
129
|
|
|
|
|
|
|
cutoff => $cutoff, |
130
|
|
|
|
|
|
|
caller => $caller, |
131
|
|
|
|
|
|
|
); |
132
|
|
|
|
|
|
|
} |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
sub subtest { |
135
|
3
|
|
|
3
|
0
|
15
|
my ($self, %args) = @_; |
136
|
3
|
|
|
|
|
13
|
my $title = param(\%args, 'title'); |
137
|
3
|
|
|
|
|
9
|
my $code = param(\%args, 'code'); |
138
|
3
|
|
|
|
|
9
|
my $suite = param(\%args, 'suite'); |
139
|
|
|
|
|
|
|
|
140
|
3
|
|
|
|
|
21
|
my $guard = $self->reporter->suite($title); |
141
|
|
|
|
|
|
|
|
142
|
3
|
|
|
|
|
54
|
$suite->parent->call_trigger('setup'); |
143
|
|
|
|
|
|
|
try { |
144
|
3
|
|
|
3
|
|
120
|
$code->(); |
145
|
|
|
|
|
|
|
} catch { |
146
|
0
|
|
|
0
|
|
0
|
$self->exception(message => $_); |
147
|
3
|
|
|
|
|
25
|
}; |
148
|
|
|
|
|
|
|
|
149
|
3
|
50
|
|
|
|
211
|
if (-d $self->message_dir) { |
150
|
0
|
|
|
|
|
0
|
require Storable; |
151
|
0
|
|
|
|
|
0
|
for my $fname (glob($self->message_dir . "/*")) { |
152
|
0
|
0
|
|
|
|
0
|
open my $fh, '<', $fname |
153
|
|
|
|
|
|
|
or die; |
154
|
0
|
|
|
|
|
0
|
my $dat = Storable::thaw(do { local $/; <$fh> }); |
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
155
|
0
|
|
|
|
|
0
|
close $fh; |
156
|
0
|
|
|
|
|
0
|
unlink $fname; |
157
|
|
|
|
|
|
|
|
158
|
0
|
|
|
|
|
0
|
my ($method, $args) = @$dat; |
159
|
0
|
|
|
|
|
0
|
$self->$method(%$args); |
160
|
|
|
|
|
|
|
} |
161
|
0
|
|
|
|
|
0
|
rmdir $self->message_dir; |
162
|
|
|
|
|
|
|
} |
163
|
|
|
|
|
|
|
|
164
|
3
|
|
|
|
|
20
|
$suite->parent->call_trigger('teardown'); |
165
|
|
|
|
|
|
|
} |
166
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
sub done_testing { |
168
|
2
|
|
|
2
|
0
|
5
|
my ($self) = @_; |
169
|
2
|
50
|
|
|
|
14
|
return if $self->{finished}++; |
170
|
|
|
|
|
|
|
|
171
|
2
|
|
|
|
|
16
|
$self->reporter->finalize(); |
172
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
# Test::Pretty was loaded |
174
|
2
|
50
|
|
|
|
189
|
if (Test::Pretty->can('_subtest')) { |
175
|
|
|
|
|
|
|
# Do not run Test::Pretty's finalization |
176
|
0
|
|
|
|
|
0
|
$Test::Pretty::NO_ENDING=1; |
177
|
|
|
|
|
|
|
} |
178
|
|
|
|
|
|
|
} |
179
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
sub push_child_message { |
181
|
0
|
|
|
0
|
0
|
0
|
my ($self, $type, $args) = @_; |
182
|
|
|
|
|
|
|
|
183
|
0
|
|
|
|
|
0
|
require Time::HiRes; |
184
|
0
|
|
|
|
|
0
|
require Storable; |
185
|
|
|
|
|
|
|
|
186
|
0
|
|
|
|
|
0
|
mkdir $self->message_dir; |
187
|
|
|
|
|
|
|
|
188
|
0
|
|
|
|
|
0
|
my $fname = File::Spec->catfile($self->message_dir, "$$." . Time::HiRes::time()); |
189
|
0
|
0
|
|
|
|
0
|
open my $fh, '>>', $fname |
190
|
|
|
|
|
|
|
or die "$fname: $!"; |
191
|
0
|
|
|
|
|
0
|
print {$fh} Storable::nfreeze([$type, $args]) . "\n"; |
|
0
|
|
|
|
|
0
|
|
192
|
0
|
|
|
|
|
0
|
close $fh; |
193
|
|
|
|
|
|
|
} |
194
|
|
|
|
|
|
|
|
195
|
|
|
|
|
|
|
sub DESTROY { |
196
|
58
|
|
|
58
|
|
589
|
my $self = shift; |
197
|
58
|
50
|
|
|
|
311
|
if ($$ == $self->pid) { |
198
|
58
|
|
|
|
|
9165
|
File::Path::rmtree($self->message_dir); # 為念 |
199
|
|
|
|
|
|
|
} |
200
|
|
|
|
|
|
|
} |
201
|
|
|
|
|
|
|
|
202
|
|
|
|
|
|
|
1; |
203
|
|
|
|
|
|
|
|