line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Test::Builder; |
2
|
|
|
|
|
|
|
|
3
|
166
|
|
|
166
|
|
82475
|
use 5.006; |
|
166
|
|
|
|
|
900
|
|
4
|
166
|
|
|
166
|
|
1040
|
use strict; |
|
166
|
|
|
|
|
557
|
|
|
166
|
|
|
|
|
3908
|
|
5
|
166
|
|
|
166
|
|
1017
|
use warnings; |
|
165
|
|
|
|
|
446
|
|
|
165
|
|
|
|
|
14306
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
our $VERSION = '1.302180'; |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
BEGIN { |
10
|
164
|
50
|
|
166
|
|
5729
|
if( $] < 5.008 ) { |
11
|
2
|
|
|
|
|
107
|
require Test::Builder::IO::Scalar; |
12
|
|
|
|
|
|
|
} |
13
|
|
|
|
|
|
|
} |
14
|
|
|
|
|
|
|
|
15
|
164
|
|
|
166
|
|
3265
|
use Scalar::Util qw/blessed reftype weaken/; |
|
164
|
|
|
|
|
450
|
|
|
164
|
|
|
|
|
23184
|
|
16
|
|
|
|
|
|
|
|
17
|
164
|
|
|
166
|
|
54497
|
use Test2::Util qw/USE_THREADS try get_tid/; |
|
164
|
|
|
|
|
527
|
|
|
164
|
|
|
|
|
11865
|
|
18
|
164
|
|
|
165
|
|
79447
|
use Test2::API qw/context release/; |
|
164
|
|
|
|
|
564
|
|
|
164
|
|
|
|
|
24095
|
|
19
|
|
|
|
|
|
|
# Make Test::Builder thread-safe for ithreads. |
20
|
|
|
|
|
|
|
BEGIN { |
21
|
164
|
100
|
66
|
165
|
|
1044
|
warn "Test::Builder was loaded after Test2 initialization, this is not recommended." |
22
|
|
|
|
|
|
|
if Test2::API::test2_init_done() || Test2::API::test2_load_done(); |
23
|
|
|
|
|
|
|
|
24
|
164
|
|
|
|
|
3428
|
if (USE_THREADS && ! Test2::API::test2_ipc_disabled()) { |
25
|
|
|
|
|
|
|
require Test2::IPC; |
26
|
|
|
|
|
|
|
require Test2::IPC::Driver::Files; |
27
|
|
|
|
|
|
|
Test2::IPC::Driver::Files->import; |
28
|
|
|
|
|
|
|
Test2::API::test2_ipc_enable_polling(); |
29
|
|
|
|
|
|
|
Test2::API::test2_no_wait(1); |
30
|
|
|
|
|
|
|
} |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
|
33
|
164
|
|
|
164
|
|
1156
|
use Test2::Event::Subtest; |
|
164
|
|
|
|
|
434
|
|
|
164
|
|
|
|
|
4790
|
|
34
|
164
|
|
|
164
|
|
1049
|
use Test2::Hub::Subtest; |
|
164
|
|
|
|
|
408
|
|
|
164
|
|
|
|
|
5460
|
|
35
|
|
|
|
|
|
|
|
36
|
164
|
|
|
164
|
|
67035
|
use Test::Builder::Formatter; |
|
164
|
|
|
|
|
543
|
|
|
164
|
|
|
|
|
1311
|
|
37
|
164
|
|
|
164
|
|
68527
|
use Test::Builder::TodoDiag; |
|
164
|
|
|
|
|
507
|
|
|
164
|
|
|
|
|
19855
|
|
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
our $Level = 1; |
40
|
|
|
|
|
|
|
our $Test = $ENV{TB_NO_EARLY_INIT} ? undef : Test::Builder->new; |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
sub _add_ts_hooks { |
43
|
361
|
|
|
362
|
|
788
|
my $self = shift; |
44
|
|
|
|
|
|
|
|
45
|
361
|
|
|
|
|
1775
|
my $hub = $self->{Stack}->top; |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
# Take a reference to the hash key, we do this to avoid closing over $self |
48
|
|
|
|
|
|
|
# which is the singleton. We use a reference because the value could change |
49
|
|
|
|
|
|
|
# in rare cases. |
50
|
361
|
|
|
|
|
900
|
my $epkgr = \$self->{Exported_To}; |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
#$hub->add_context_aquire(sub {$_[0]->{level} += $Level - 1}); |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
$hub->pre_filter( |
55
|
|
|
|
|
|
|
sub { |
56
|
4416
|
|
|
4417
|
|
8744
|
my ($active_hub, $e) = @_; |
57
|
|
|
|
|
|
|
|
58
|
4416
|
|
|
|
|
7508
|
my $epkg = $$epkgr; |
59
|
4416
|
50
|
|
|
|
13244
|
my $cpkg = $e->{trace} ? $e->{trace}->{frame}->[0] : undef; |
60
|
|
|
|
|
|
|
|
61
|
164
|
|
|
164
|
|
1258
|
no strict 'refs'; |
|
164
|
|
|
|
|
450
|
|
|
163
|
|
|
|
|
6409
|
|
62
|
163
|
|
|
164
|
|
964
|
no warnings 'once'; |
|
163
|
|
|
|
|
437
|
|
|
163
|
|
|
|
|
44850
|
|
63
|
4416
|
|
|
|
|
6346
|
my $todo; |
64
|
4416
|
50
|
|
|
|
8905
|
$todo = ${"$cpkg\::TODO"} if $cpkg; |
|
4416
|
|
|
|
|
14731
|
|
65
|
4416
|
100
|
100
|
|
|
14613
|
$todo = ${"$epkg\::TODO"} if $epkg && !$todo; |
|
2961
|
|
|
|
|
5866
|
|
66
|
|
|
|
|
|
|
|
67
|
4416
|
100
|
|
|
|
13736
|
return $e unless defined($todo); |
68
|
324
|
100
|
|
|
|
668
|
return $e unless length($todo); |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
# Turn a diag into a todo diag |
71
|
322
|
100
|
|
|
|
1177
|
return Test::Builder::TodoDiag->new(%$e) if ref($e) eq 'Test2::Event::Diag'; |
72
|
|
|
|
|
|
|
|
73
|
208
|
100
|
|
|
|
1104
|
$e->set_todo($todo) if $e->can('set_todo'); |
74
|
208
|
|
|
|
|
1027
|
$e->add_amnesty({tag => 'TODO', details => $todo}); |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
# Set todo on ok's |
77
|
208
|
100
|
|
|
|
908
|
if ($e->isa('Test2::Event::Ok')) { |
78
|
133
|
|
|
|
|
387
|
$e->set_effective_pass(1); |
79
|
|
|
|
|
|
|
|
80
|
133
|
100
|
|
|
|
459
|
if (my $result = $e->get_meta(__PACKAGE__)) { |
81
|
131
|
|
100
|
|
|
525
|
$result->{reason} ||= $todo; |
82
|
131
|
|
100
|
|
|
460
|
$result->{type} ||= 'todo'; |
83
|
131
|
|
|
|
|
235
|
$result->{ok} = 1; |
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
} |
86
|
|
|
|
|
|
|
|
87
|
208
|
|
|
|
|
528
|
return $e; |
88
|
|
|
|
|
|
|
}, |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
inherit => 1, |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
intercept_inherit => { |
93
|
|
|
|
|
|
|
clean => sub { |
94
|
23
|
|
|
24
|
|
90
|
my %params = @_; |
95
|
|
|
|
|
|
|
|
96
|
23
|
|
|
|
|
68
|
my $state = $params{state}; |
97
|
23
|
|
|
|
|
50
|
my $trace = $params{trace}; |
98
|
|
|
|
|
|
|
|
99
|
23
|
|
|
|
|
58
|
my $epkg = $$epkgr; |
100
|
23
|
|
|
|
|
113
|
my $cpkg = $trace->{frame}->[0]; |
101
|
|
|
|
|
|
|
|
102
|
163
|
|
|
164
|
|
1285
|
no strict 'refs'; |
|
163
|
|
|
|
|
440
|
|
|
163
|
|
|
|
|
6586
|
|
103
|
163
|
|
|
164
|
|
1087
|
no warnings 'once'; |
|
163
|
|
|
|
|
411
|
|
|
163
|
|
|
|
|
31099
|
|
104
|
|
|
|
|
|
|
|
105
|
23
|
|
|
|
|
74
|
$state->{+__PACKAGE__} = {}; |
106
|
23
|
50
|
|
|
|
74
|
$state->{+__PACKAGE__}->{"$cpkg\::TODO"} = ${"$cpkg\::TODO"} if $cpkg; |
|
23
|
|
|
|
|
146
|
|
107
|
23
|
100
|
|
|
|
72
|
$state->{+__PACKAGE__}->{"$epkg\::TODO"} = ${"$epkg\::TODO"} if $epkg; |
|
13
|
|
|
|
|
57
|
|
108
|
|
|
|
|
|
|
|
109
|
23
|
50
|
|
|
|
72
|
${"$cpkg\::TODO"} = undef if $cpkg; |
|
23
|
|
|
|
|
106
|
|
110
|
23
|
100
|
|
|
|
97
|
${"$epkg\::TODO"} = undef if $epkg; |
|
13
|
|
|
|
|
71
|
|
111
|
|
|
|
|
|
|
}, |
112
|
|
|
|
|
|
|
restore => sub { |
113
|
25
|
|
|
26
|
|
142
|
my %params = @_; |
114
|
25
|
|
|
|
|
67
|
my $state = $params{state}; |
115
|
|
|
|
|
|
|
|
116
|
163
|
|
|
164
|
|
1229
|
no strict 'refs'; |
|
163
|
|
|
|
|
409
|
|
|
163
|
|
|
|
|
6605
|
|
117
|
163
|
|
|
164
|
|
1025
|
no warnings 'once'; |
|
163
|
|
|
|
|
406
|
|
|
163
|
|
|
|
|
10674
|
|
118
|
|
|
|
|
|
|
|
119
|
25
|
|
|
|
|
45
|
for my $item (keys %{$state->{+__PACKAGE__}}) { |
|
25
|
|
|
|
|
113
|
|
120
|
163
|
|
|
164
|
|
1194
|
no strict 'refs'; |
|
163
|
|
|
|
|
456
|
|
|
163
|
|
|
|
|
5694
|
|
121
|
163
|
|
|
164
|
|
1051
|
no warnings 'once'; |
|
163
|
|
|
|
|
420
|
|
|
163
|
|
|
|
|
17423
|
|
122
|
|
|
|
|
|
|
|
123
|
25
|
|
|
|
|
58
|
${"$item"} = $state->{+__PACKAGE__}->{$item}; |
|
25
|
|
|
|
|
154
|
|
124
|
|
|
|
|
|
|
} |
125
|
|
|
|
|
|
|
}, |
126
|
|
|
|
|
|
|
}, |
127
|
361
|
|
|
|
|
5896
|
); |
128
|
|
|
|
|
|
|
} |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
{ |
131
|
163
|
|
|
164
|
|
1228
|
no warnings; |
|
163
|
|
|
|
|
396
|
|
|
162
|
|
|
|
|
7278
|
|
132
|
|
|
|
|
|
|
INIT { |
133
|
162
|
|
|
164
|
|
1136
|
use warnings; |
|
162
|
|
|
|
|
356
|
|
|
162
|
|
|
|
|
562076
|
|
134
|
151
|
100
|
|
152
|
|
907
|
Test2::API::test2_load() unless Test2::API::test2_in_preload(); |
135
|
|
|
|
|
|
|
} |
136
|
|
|
|
|
|
|
} |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
sub new { |
139
|
2150
|
|
|
2151
|
1
|
51534
|
my($class) = shift; |
140
|
2150
|
100
|
|
|
|
5817
|
unless($Test) { |
141
|
157
|
|
|
|
|
560
|
$Test = $class->create(singleton => 1); |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
Test2::API::test2_add_callback_post_load( |
144
|
|
|
|
|
|
|
sub { |
145
|
157
|
50
|
33
|
158
|
|
1409
|
$Test->{Original_Pid} = $$ if !$Test->{Original_Pid} || $Test->{Original_Pid} == 0; |
146
|
157
|
|
|
|
|
767
|
$Test->reset(singleton => 1); |
147
|
157
|
|
|
|
|
686
|
$Test->_add_ts_hooks; |
148
|
|
|
|
|
|
|
} |
149
|
157
|
|
|
|
|
1168
|
); |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
# Non-TB tools normally expect 0 added to the level. $Level is normally 1. So |
152
|
|
|
|
|
|
|
# we only want the level to change if $Level != 1. |
153
|
|
|
|
|
|
|
# TB->ctx compensates for this later. |
154
|
157
|
|
|
10495
|
|
900
|
Test2::API::test2_add_callback_context_aquire(sub { $_[0]->{level} += $Level - 1 }); |
|
10494
|
|
|
|
|
29657
|
|
155
|
|
|
|
|
|
|
|
156
|
157
|
|
|
136
|
|
916
|
Test2::API::test2_add_callback_exit(sub { $Test->_ending(@_) }); |
|
135
|
|
|
|
|
870
|
|
157
|
|
|
|
|
|
|
|
158
|
157
|
50
|
|
|
|
605
|
Test2::API::test2_ipc()->set_no_fatal(1) if Test2::API::test2_has_ipc(); |
159
|
|
|
|
|
|
|
} |
160
|
2150
|
|
|
|
|
5353
|
return $Test; |
161
|
|
|
|
|
|
|
} |
162
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
sub create { |
164
|
209
|
|
|
210
|
1
|
1084
|
my $class = shift; |
165
|
209
|
|
|
|
|
750
|
my %params = @_; |
166
|
|
|
|
|
|
|
|
167
|
209
|
|
|
|
|
697
|
my $self = bless {}, $class; |
168
|
209
|
100
|
|
|
|
743
|
if ($params{singleton}) { |
169
|
162
|
|
|
|
|
883
|
$self->{Stack} = Test2::API::test2_stack(); |
170
|
|
|
|
|
|
|
} |
171
|
|
|
|
|
|
|
else { |
172
|
47
|
|
|
|
|
372
|
$self->{Stack} = Test2::API::Stack->new; |
173
|
|
|
|
|
|
|
$self->{Stack}->new_hub( |
174
|
47
|
|
|
|
|
422
|
formatter => Test::Builder::Formatter->new, |
175
|
|
|
|
|
|
|
ipc => Test2::API::test2_ipc(), |
176
|
|
|
|
|
|
|
); |
177
|
|
|
|
|
|
|
|
178
|
47
|
|
|
|
|
360
|
$self->reset(%params); |
179
|
47
|
|
|
|
|
264
|
$self->_add_ts_hooks; |
180
|
|
|
|
|
|
|
} |
181
|
|
|
|
|
|
|
|
182
|
209
|
|
|
|
|
749
|
return $self; |
183
|
|
|
|
|
|
|
} |
184
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
sub ctx { |
186
|
10810
|
|
|
10811
|
0
|
18069
|
my $self = shift; |
187
|
|
|
|
|
|
|
context( |
188
|
|
|
|
|
|
|
# 1 for our frame, another for the -1 off of $Level in our hook at the top. |
189
|
|
|
|
|
|
|
level => 2, |
190
|
|
|
|
|
|
|
fudge => 1, |
191
|
|
|
|
|
|
|
stack => $self->{Stack}, |
192
|
|
|
|
|
|
|
hub => $self->{Hub}, |
193
|
10810
|
|
|
|
|
53165
|
wrapped => 1, |
194
|
|
|
|
|
|
|
@_ |
195
|
|
|
|
|
|
|
); |
196
|
|
|
|
|
|
|
} |
197
|
|
|
|
|
|
|
|
198
|
|
|
|
|
|
|
sub parent { |
199
|
148
|
|
|
149
|
0
|
275
|
my $self = shift; |
200
|
148
|
|
|
|
|
299
|
my $ctx = $self->ctx; |
201
|
148
|
|
66
|
|
|
558
|
my $chub = $self->{Hub} || $ctx->hub; |
202
|
148
|
|
|
|
|
998
|
$ctx->release; |
203
|
|
|
|
|
|
|
|
204
|
148
|
|
|
|
|
583
|
my $meta = $chub->meta(__PACKAGE__, {}); |
205
|
148
|
|
|
|
|
366
|
my $parent = $meta->{parent}; |
206
|
|
|
|
|
|
|
|
207
|
148
|
100
|
|
|
|
346
|
return undef unless $parent; |
208
|
|
|
|
|
|
|
|
209
|
|
|
|
|
|
|
return bless { |
210
|
|
|
|
|
|
|
Original_Pid => $$, |
211
|
|
|
|
|
|
|
Stack => $self->{Stack}, |
212
|
147
|
|
|
|
|
1194
|
Hub => $parent, |
213
|
|
|
|
|
|
|
}, blessed($self); |
214
|
|
|
|
|
|
|
} |
215
|
|
|
|
|
|
|
|
216
|
|
|
|
|
|
|
sub child { |
217
|
151
|
|
|
152
|
0
|
420
|
my( $self, $name ) = @_; |
218
|
|
|
|
|
|
|
|
219
|
151
|
|
66
|
|
|
368
|
$name ||= "Child of " . $self->name; |
220
|
151
|
|
|
|
|
397
|
my $ctx = $self->ctx; |
221
|
|
|
|
|
|
|
|
222
|
151
|
|
|
|
|
631
|
my $parent = $ctx->hub; |
223
|
151
|
|
|
|
|
625
|
my $pmeta = $parent->meta(__PACKAGE__, {}); |
224
|
|
|
|
|
|
|
$self->croak("You already have a child named ($pmeta->{child}) running") |
225
|
151
|
50
|
|
|
|
461
|
if $pmeta->{child}; |
226
|
|
|
|
|
|
|
|
227
|
151
|
|
|
|
|
346
|
$pmeta->{child} = $name; |
228
|
|
|
|
|
|
|
|
229
|
|
|
|
|
|
|
# Clear $TODO for the child. |
230
|
151
|
|
|
|
|
461
|
my $orig_TODO = $self->find_TODO(undef, 1, undef); |
231
|
|
|
|
|
|
|
|
232
|
151
|
|
|
|
|
339
|
my $subevents = []; |
233
|
|
|
|
|
|
|
|
234
|
151
|
|
|
|
|
545
|
my $hub = $ctx->stack->new_hub( |
235
|
|
|
|
|
|
|
class => 'Test2::Hub::Subtest', |
236
|
|
|
|
|
|
|
); |
237
|
|
|
|
|
|
|
|
238
|
|
|
|
|
|
|
$hub->pre_filter(sub { |
239
|
114
|
|
|
115
|
|
215
|
my ($active_hub, $e) = @_; |
240
|
|
|
|
|
|
|
|
241
|
|
|
|
|
|
|
# Turn a diag into a todo diag |
242
|
114
|
100
|
|
|
|
405
|
return Test::Builder::TodoDiag->new(%$e) if ref($e) eq 'Test2::Event::Diag'; |
243
|
|
|
|
|
|
|
|
244
|
78
|
|
|
|
|
143
|
return $e; |
245
|
151
|
100
|
|
|
|
522
|
}, inherit => 1) if $orig_TODO; |
246
|
|
|
|
|
|
|
|
247
|
151
|
|
|
603
|
|
1059
|
$hub->listen(sub { push @$subevents => $_[1] }); |
|
602
|
|
|
|
|
1798
|
|
248
|
|
|
|
|
|
|
|
249
|
151
|
|
|
|
|
414
|
$hub->set_nested( $parent->nested + 1 ); |
250
|
|
|
|
|
|
|
|
251
|
151
|
|
|
|
|
555
|
my $meta = $hub->meta(__PACKAGE__, {}); |
252
|
151
|
|
|
|
|
382
|
$meta->{Name} = $name; |
253
|
151
|
|
|
|
|
293
|
$meta->{TODO} = $orig_TODO; |
254
|
151
|
|
|
|
|
381
|
$meta->{TODO_PKG} = $ctx->trace->package; |
255
|
151
|
|
|
|
|
343
|
$meta->{parent} = $parent; |
256
|
151
|
|
|
|
|
302
|
$meta->{Test_Results} = []; |
257
|
151
|
|
|
|
|
300
|
$meta->{subevents} = $subevents; |
258
|
151
|
|
|
|
|
752
|
$meta->{subtest_id} = $hub->id; |
259
|
151
|
|
|
|
|
559
|
$meta->{subtest_uuid} = $hub->uuid; |
260
|
151
|
100
|
|
|
|
441
|
$meta->{subtest_buffered} = $parent->format ? 0 : 1; |
261
|
|
|
|
|
|
|
|
262
|
151
|
|
|
|
|
504
|
$self->_add_ts_hooks; |
263
|
|
|
|
|
|
|
|
264
|
151
|
|
|
|
|
609
|
$ctx->release; |
265
|
151
|
|
|
|
|
1403
|
return bless { Original_Pid => $$, Stack => $self->{Stack}, Hub => $hub, no_log_results => $self->{no_log_results} }, blessed($self); |
266
|
|
|
|
|
|
|
} |
267
|
|
|
|
|
|
|
|
268
|
|
|
|
|
|
|
sub finalize { |
269
|
147
|
|
|
148
|
0
|
311
|
my $self = shift; |
270
|
147
|
|
|
|
|
250
|
my $ok = 1; |
271
|
147
|
100
|
|
|
|
418
|
($ok) = @_ if @_; |
272
|
|
|
|
|
|
|
|
273
|
147
|
|
|
|
|
446
|
my $st_ctx = $self->ctx; |
274
|
147
|
|
50
|
|
|
550
|
my $chub = $self->{Hub} || return $st_ctx->release; |
275
|
|
|
|
|
|
|
|
276
|
147
|
|
|
|
|
580
|
my $meta = $chub->meta(__PACKAGE__, {}); |
277
|
147
|
50
|
|
|
|
456
|
if ($meta->{child}) { |
278
|
0
|
|
|
|
|
0
|
$self->croak("Can't call finalize() with child ($meta->{child}) active"); |
279
|
|
|
|
|
|
|
} |
280
|
|
|
|
|
|
|
|
281
|
147
|
|
|
|
|
515
|
local $? = 0; # don't fail if $subtests happened to set $? nonzero |
282
|
|
|
|
|
|
|
|
283
|
147
|
|
|
|
|
690
|
$self->{Stack}->pop($chub); |
284
|
|
|
|
|
|
|
|
285
|
147
|
|
|
|
|
555
|
$self->find_TODO($meta->{TODO_PKG}, 1, $meta->{TODO}); |
286
|
|
|
|
|
|
|
|
287
|
147
|
|
|
|
|
451
|
my $parent = $self->parent; |
288
|
147
|
|
|
|
|
401
|
my $ctx = $parent->ctx; |
289
|
147
|
|
|
|
|
768
|
my $trace = $ctx->trace; |
290
|
147
|
|
|
|
|
375
|
delete $ctx->hub->meta(__PACKAGE__, {})->{child}; |
291
|
|
|
|
|
|
|
|
292
|
147
|
100
|
66
|
|
|
696
|
$chub->finalize($trace->snapshot(hid => $chub->hid, nested => $chub->nested), 1) |
|
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
293
|
|
|
|
|
|
|
if $ok |
294
|
|
|
|
|
|
|
&& $chub->count |
295
|
|
|
|
|
|
|
&& !$chub->no_ending |
296
|
|
|
|
|
|
|
&& !$chub->ended; |
297
|
|
|
|
|
|
|
|
298
|
147
|
|
100
|
|
|
571
|
my $plan = $chub->plan || 0; |
299
|
147
|
|
|
|
|
396
|
my $count = $chub->count; |
300
|
147
|
|
|
|
|
421
|
my $failed = $chub->failed; |
301
|
147
|
|
|
|
|
575
|
my $passed = $chub->is_passing; |
302
|
|
|
|
|
|
|
|
303
|
147
|
100
|
|
|
|
597
|
my $num_extra = $plan =~ m/\D/ ? 0 : $count - $plan; |
304
|
147
|
100
|
100
|
|
|
560
|
if ($count && $num_extra != 0) { |
305
|
12
|
50
|
|
|
|
30
|
my $s = $plan == 1 ? '' : 's'; |
306
|
12
|
|
|
|
|
61
|
$st_ctx->diag(<<"FAIL"); |
307
|
|
|
|
|
|
|
Looks like you planned $plan test$s but ran $count. |
308
|
|
|
|
|
|
|
FAIL |
309
|
|
|
|
|
|
|
} |
310
|
|
|
|
|
|
|
|
311
|
147
|
100
|
|
|
|
362
|
if ($failed) { |
312
|
61
|
100
|
|
|
|
192
|
my $s = $failed == 1 ? '' : 's'; |
313
|
|
|
|
|
|
|
|
314
|
61
|
100
|
|
|
|
143
|
my $qualifier = $num_extra == 0 ? '' : ' run'; |
315
|
|
|
|
|
|
|
|
316
|
61
|
|
|
|
|
347
|
$st_ctx->diag(<<"FAIL"); |
317
|
|
|
|
|
|
|
Looks like you failed $failed test$s of $count$qualifier. |
318
|
|
|
|
|
|
|
FAIL |
319
|
|
|
|
|
|
|
} |
320
|
|
|
|
|
|
|
|
321
|
147
|
50
|
100
|
|
|
672
|
if (!$passed && !$failed && $count && !$num_extra) { |
|
|
|
66
|
|
|
|
|
|
|
|
33
|
|
|
|
|
322
|
0
|
|
|
|
|
0
|
$st_ctx->diag(<<"FAIL"); |
323
|
|
|
|
|
|
|
All assertions inside the subtest passed, but errors were encountered. |
324
|
|
|
|
|
|
|
FAIL |
325
|
|
|
|
|
|
|
} |
326
|
|
|
|
|
|
|
|
327
|
147
|
|
|
|
|
521
|
$st_ctx->release; |
328
|
|
|
|
|
|
|
|
329
|
147
|
50
|
|
|
|
535
|
unless ($chub->bailed_out) { |
330
|
147
|
|
|
|
|
398
|
my $plan = $chub->plan; |
331
|
147
|
100
|
100
|
|
|
977
|
if ( $plan && $plan eq 'SKIP' ) { |
|
|
100
|
|
|
|
|
|
332
|
2
|
|
|
|
|
32
|
$parent->skip($chub->skip_reason, $meta->{Name}); |
333
|
|
|
|
|
|
|
} |
334
|
|
|
|
|
|
|
elsif ( !$chub->count ) { |
335
|
54
|
|
|
|
|
365
|
$parent->ok( 0, sprintf q[No tests run for subtest "%s"], $meta->{Name} ); |
336
|
|
|
|
|
|
|
} |
337
|
|
|
|
|
|
|
else { |
338
|
91
|
|
|
|
|
219
|
$parent->{subevents} = $meta->{subevents}; |
339
|
91
|
|
|
|
|
203
|
$parent->{subtest_id} = $meta->{subtest_id}; |
340
|
91
|
|
|
|
|
191
|
$parent->{subtest_uuid} = $meta->{subtest_uuid}; |
341
|
91
|
|
|
|
|
183
|
$parent->{subtest_buffered} = $meta->{subtest_buffered}; |
342
|
91
|
|
|
|
|
311
|
$parent->ok( $chub->is_passing, $meta->{Name} ); |
343
|
|
|
|
|
|
|
} |
344
|
|
|
|
|
|
|
} |
345
|
|
|
|
|
|
|
|
346
|
147
|
|
|
|
|
489
|
$ctx->release; |
347
|
147
|
|
|
|
|
505
|
return $chub->is_passing; |
348
|
|
|
|
|
|
|
} |
349
|
|
|
|
|
|
|
|
350
|
|
|
|
|
|
|
sub subtest { |
351
|
142
|
|
|
143
|
1
|
290
|
my $self = shift; |
352
|
142
|
|
|
|
|
344
|
my ($name, $code, @args) = @_; |
353
|
142
|
|
|
|
|
369
|
my $ctx = $self->ctx; |
354
|
142
|
100
|
66
|
|
|
1060
|
$ctx->throw("subtest()'s second argument must be a code ref") |
355
|
|
|
|
|
|
|
unless $code && reftype($code) eq 'CODE'; |
356
|
|
|
|
|
|
|
|
357
|
140
|
|
33
|
|
|
466
|
$name ||= "Child of " . $self->name; |
358
|
|
|
|
|
|
|
|
359
|
|
|
|
|
|
|
|
360
|
|
|
|
|
|
|
$_->($name,$code,@args) |
361
|
140
|
|
|
|
|
410
|
for Test2::API::test2_list_pre_subtest_callbacks(); |
362
|
|
|
|
|
|
|
|
363
|
140
|
|
|
|
|
722
|
$ctx->note("Subtest: $name"); |
364
|
|
|
|
|
|
|
|
365
|
140
|
|
|
|
|
541
|
my $child = $self->child($name); |
366
|
|
|
|
|
|
|
|
367
|
140
|
|
|
|
|
330
|
my $start_pid = $$; |
368
|
140
|
|
|
|
|
253
|
my $st_ctx; |
369
|
140
|
|
|
|
|
287
|
my ($ok, $err, $finished, $child_error); |
370
|
|
|
|
|
|
|
T2_SUBTEST_WRAPPER: { |
371
|
140
|
|
|
|
|
228
|
my $ctx = $self->ctx; |
|
140
|
|
|
|
|
391
|
|
372
|
140
|
|
|
|
|
559
|
$st_ctx = $ctx->snapshot; |
373
|
140
|
|
|
|
|
467
|
$ctx->release; |
374
|
140
|
|
|
|
|
262
|
$ok = eval { local $Level = 1; $code->(@args); 1 }; |
|
140
|
|
|
|
|
284
|
|
|
140
|
|
|
|
|
541
|
|
|
134
|
|
|
|
|
378
|
|
375
|
135
|
|
|
|
|
391
|
($err, $child_error) = ($@, $?); |
376
|
|
|
|
|
|
|
|
377
|
|
|
|
|
|
|
# They might have done 'BEGIN { skip_all => "whatever" }' |
378
|
135
|
50
|
66
|
|
|
967
|
if (!$ok && $err =~ m/Label not found for "last T2_SUBTEST_WRAPPER"/ || (blessed($err) && blessed($err) eq 'Test::Builder::Exception')) { |
|
|
|
33
|
|
|
|
|
|
|
|
33
|
|
|
|
|
379
|
0
|
|
|
|
|
0
|
$ok = undef; |
380
|
0
|
|
|
|
|
0
|
$err = undef; |
381
|
|
|
|
|
|
|
} |
382
|
|
|
|
|
|
|
else { |
383
|
135
|
|
|
|
|
406
|
$finished = 1; |
384
|
|
|
|
|
|
|
} |
385
|
|
|
|
|
|
|
} |
386
|
|
|
|
|
|
|
|
387
|
139
|
50
|
33
|
|
|
556
|
if ($start_pid != $$ && !$INC{'Test2/IPC.pm'}) { |
388
|
0
|
0
|
|
|
|
0
|
warn $ok ? "Forked inside subtest, but subtest never finished!\n" : $err; |
389
|
0
|
|
|
|
|
0
|
exit 255; |
390
|
|
|
|
|
|
|
} |
391
|
|
|
|
|
|
|
|
392
|
139
|
|
|
|
|
410
|
my $trace = $ctx->trace; |
393
|
|
|
|
|
|
|
|
394
|
139
|
100
|
|
|
|
366
|
if (!$finished) { |
395
|
4
|
100
|
|
|
|
11
|
if(my $bailed = $st_ctx->hub->bailed_out) { |
396
|
2
|
|
|
|
|
4
|
my $chub = $child->{Hub}; |
397
|
2
|
|
|
|
|
9
|
$self->{Stack}->pop($chub); |
398
|
2
|
|
|
|
|
7
|
$ctx->bail($bailed->reason); |
399
|
|
|
|
|
|
|
} |
400
|
2
|
|
|
|
|
7
|
my $code = $st_ctx->hub->exit_code; |
401
|
2
|
|
|
|
|
5
|
$ok = !$code; |
402
|
2
|
50
|
|
|
|
8
|
$err = "Subtest ended with exit code $code" if $code; |
403
|
|
|
|
|
|
|
} |
404
|
|
|
|
|
|
|
|
405
|
137
|
|
|
|
|
346
|
my $st_hub = $st_ctx->hub; |
406
|
137
|
|
|
|
|
452
|
my $plan = $st_hub->plan; |
407
|
137
|
|
|
|
|
485
|
my $count = $st_hub->count; |
408
|
|
|
|
|
|
|
|
409
|
137
|
100
|
100
|
|
|
508
|
if (!$count && (!defined($plan) || "$plan" ne 'SKIP')) { |
|
|
|
100
|
|
|
|
|
410
|
50
|
100
|
|
|
|
154
|
$st_ctx->plan(0) unless defined $plan; |
411
|
50
|
|
|
|
|
138
|
$st_ctx->diag('No tests run!'); |
412
|
|
|
|
|
|
|
} |
413
|
|
|
|
|
|
|
|
414
|
137
|
|
|
|
|
376
|
$child->finalize($st_ctx->trace); |
415
|
|
|
|
|
|
|
|
416
|
137
|
|
|
|
|
522
|
$ctx->release; |
417
|
|
|
|
|
|
|
|
418
|
137
|
100
|
|
|
|
400
|
die $err unless $ok; |
419
|
|
|
|
|
|
|
|
420
|
136
|
100
|
|
|
|
369
|
$? = $child_error if defined $child_error; |
421
|
|
|
|
|
|
|
|
422
|
136
|
|
|
|
|
346
|
return $st_hub->is_passing; |
423
|
|
|
|
|
|
|
} |
424
|
|
|
|
|
|
|
|
425
|
|
|
|
|
|
|
sub name { |
426
|
6
|
|
|
7
|
1
|
15
|
my $self = shift; |
427
|
6
|
|
|
|
|
16
|
my $ctx = $self->ctx; |
428
|
6
|
|
|
|
|
27
|
release $ctx, $ctx->hub->meta(__PACKAGE__, {})->{Name}; |
429
|
|
|
|
|
|
|
} |
430
|
|
|
|
|
|
|
|
431
|
|
|
|
|
|
|
sub reset { ## no critic (Subroutines::ProhibitBuiltinHomonyms) |
432
|
217
|
|
|
218
|
1
|
813
|
my ($self, %params) = @_; |
433
|
|
|
|
|
|
|
|
434
|
217
|
|
|
|
|
946
|
Test2::API::test2_unset_is_end(); |
435
|
|
|
|
|
|
|
|
436
|
|
|
|
|
|
|
# We leave this a global because it has to be localized and localizing |
437
|
|
|
|
|
|
|
# hash keys is just asking for pain. Also, it was documented. |
438
|
217
|
|
|
|
|
414
|
$Level = 1; |
439
|
|
|
|
|
|
|
|
440
|
|
|
|
|
|
|
$self->{no_log_results} = $ENV{TEST_NO_LOG_RESULTS} ? 1 : 0 |
441
|
217
|
50
|
|
|
|
875
|
unless $params{singleton}; |
|
|
100
|
|
|
|
|
|
442
|
|
|
|
|
|
|
|
443
|
217
|
50
|
|
|
|
669
|
$self->{Original_Pid} = Test2::API::test2_in_preload() ? -1 : $$; |
444
|
|
|
|
|
|
|
|
445
|
217
|
|
|
|
|
849
|
my $ctx = $self->ctx; |
446
|
217
|
|
|
|
|
1313
|
my $hub = $ctx->hub; |
447
|
217
|
|
|
|
|
1356
|
$ctx->release; |
448
|
217
|
100
|
|
|
|
977
|
unless ($params{singleton}) { |
449
|
55
|
|
|
|
|
314
|
$hub->reset_state(); |
450
|
55
|
|
|
|
|
221
|
$hub->_tb_reset(); |
451
|
|
|
|
|
|
|
} |
452
|
|
|
|
|
|
|
|
453
|
217
|
|
|
|
|
741
|
$ctx = $self->ctx; |
454
|
|
|
|
|
|
|
|
455
|
217
|
|
|
|
|
1083
|
my $meta = $ctx->hub->meta(__PACKAGE__, {}); |
456
|
|
|
|
|
|
|
%$meta = ( |
457
|
|
|
|
|
|
|
Name => $0, |
458
|
|
|
|
|
|
|
Ending => 0, |
459
|
|
|
|
|
|
|
Done_Testing => undef, |
460
|
|
|
|
|
|
|
Skip_All => 0, |
461
|
|
|
|
|
|
|
Test_Results => [], |
462
|
|
|
|
|
|
|
parent => $meta->{parent}, |
463
|
217
|
|
|
|
|
1727
|
); |
464
|
|
|
|
|
|
|
|
465
|
217
|
100
|
|
|
|
938
|
$self->{Exported_To} = undef unless $params{singleton}; |
466
|
|
|
|
|
|
|
|
467
|
217
|
|
66
|
|
|
1200
|
$self->{Orig_Handles} ||= do { |
468
|
209
|
|
|
|
|
955
|
my $format = $ctx->hub->format; |
469
|
209
|
|
|
|
|
493
|
my $out; |
470
|
209
|
100
|
66
|
|
|
3023
|
if ($format && $format->isa('Test2::Formatter::TAP')) { |
471
|
208
|
|
|
|
|
1857
|
$out = $format->handles; |
472
|
|
|
|
|
|
|
} |
473
|
209
|
100
|
|
|
|
1330
|
$out ? [@$out] : []; |
474
|
|
|
|
|
|
|
}; |
475
|
|
|
|
|
|
|
|
476
|
217
|
|
|
|
|
1007
|
$self->use_numbers(1); |
477
|
217
|
100
|
|
|
|
1067
|
$self->no_header(0) unless $params{singleton}; |
478
|
217
|
100
|
|
|
|
1162
|
$self->no_ending(0) unless $params{singleton}; |
479
|
217
|
|
|
|
|
1037
|
$self->reset_outputs; |
480
|
|
|
|
|
|
|
|
481
|
217
|
|
|
|
|
776
|
$ctx->release; |
482
|
|
|
|
|
|
|
|
483
|
217
|
|
|
|
|
599
|
return; |
484
|
|
|
|
|
|
|
} |
485
|
|
|
|
|
|
|
|
486
|
|
|
|
|
|
|
|
487
|
|
|
|
|
|
|
my %plan_cmds = ( |
488
|
|
|
|
|
|
|
no_plan => \&no_plan, |
489
|
|
|
|
|
|
|
skip_all => \&skip_all, |
490
|
|
|
|
|
|
|
tests => \&_plan_tests, |
491
|
|
|
|
|
|
|
); |
492
|
|
|
|
|
|
|
|
493
|
|
|
|
|
|
|
sub plan { |
494
|
281
|
|
|
282
|
1
|
1201
|
my( $self, $cmd, $arg ) = @_; |
495
|
|
|
|
|
|
|
|
496
|
281
|
100
|
|
|
|
917
|
return unless $cmd; |
497
|
|
|
|
|
|
|
|
498
|
208
|
|
|
|
|
614
|
my $ctx = $self->ctx; |
499
|
208
|
|
|
|
|
966
|
my $hub = $ctx->hub; |
500
|
|
|
|
|
|
|
|
501
|
208
|
100
|
|
|
|
1017
|
$ctx->throw("You tried to plan twice") if $hub->plan; |
502
|
|
|
|
|
|
|
|
503
|
206
|
|
|
|
|
687
|
local $Level = $Level + 1; |
504
|
|
|
|
|
|
|
|
505
|
206
|
100
|
|
|
|
841
|
if( my $method = $plan_cmds{$cmd} ) { |
506
|
203
|
|
|
|
|
484
|
local $Level = $Level + 1; |
507
|
203
|
|
|
|
|
681
|
$self->$method($arg); |
508
|
|
|
|
|
|
|
} |
509
|
|
|
|
|
|
|
else { |
510
|
3
|
|
|
|
|
8
|
my @args = grep { defined } ( $cmd, $arg ); |
|
6
|
|
|
|
|
15
|
|
511
|
3
|
|
|
|
|
17
|
$ctx->throw("plan() doesn't understand @args"); |
512
|
|
|
|
|
|
|
} |
513
|
|
|
|
|
|
|
|
514
|
185
|
|
|
|
|
785
|
release $ctx, 1; |
515
|
|
|
|
|
|
|
} |
516
|
|
|
|
|
|
|
|
517
|
|
|
|
|
|
|
|
518
|
|
|
|
|
|
|
sub _plan_tests { |
519
|
166
|
|
|
167
|
|
493
|
my($self, $arg) = @_; |
520
|
|
|
|
|
|
|
|
521
|
166
|
|
|
|
|
567
|
my $ctx = $self->ctx; |
522
|
|
|
|
|
|
|
|
523
|
166
|
100
|
|
|
|
744
|
if($arg) { |
|
|
100
|
|
|
|
|
|
524
|
163
|
|
|
|
|
463
|
local $Level = $Level + 1; |
525
|
163
|
|
|
|
|
651
|
$self->expected_tests($arg); |
526
|
|
|
|
|
|
|
} |
527
|
|
|
|
|
|
|
elsif( !defined $arg ) { |
528
|
1
|
|
|
|
|
4
|
$ctx->throw("Got an undefined number of tests"); |
529
|
|
|
|
|
|
|
} |
530
|
|
|
|
|
|
|
else { |
531
|
2
|
|
|
|
|
8
|
$ctx->throw("You said to run 0 tests"); |
532
|
|
|
|
|
|
|
} |
533
|
|
|
|
|
|
|
|
534
|
159
|
|
|
|
|
527
|
$ctx->release; |
535
|
|
|
|
|
|
|
} |
536
|
|
|
|
|
|
|
|
537
|
|
|
|
|
|
|
|
538
|
|
|
|
|
|
|
sub expected_tests { |
539
|
252
|
|
|
253
|
1
|
573
|
my $self = shift; |
540
|
252
|
|
|
|
|
606
|
my($max) = @_; |
541
|
|
|
|
|
|
|
|
542
|
252
|
|
|
|
|
752
|
my $ctx = $self->ctx; |
543
|
|
|
|
|
|
|
|
544
|
252
|
100
|
|
|
|
1100
|
if(@_) { |
545
|
163
|
100
|
|
|
|
1341
|
$self->croak("Number of tests must be a positive integer. You gave it '$max'") |
546
|
|
|
|
|
|
|
unless $max =~ /^\+?\d+$/; |
547
|
|
|
|
|
|
|
|
548
|
159
|
|
|
|
|
790
|
$ctx->plan($max); |
549
|
|
|
|
|
|
|
} |
550
|
|
|
|
|
|
|
|
551
|
248
|
|
|
|
|
1057
|
my $hub = $ctx->hub; |
552
|
|
|
|
|
|
|
|
553
|
248
|
|
|
|
|
1036
|
$ctx->release; |
554
|
|
|
|
|
|
|
|
555
|
248
|
|
|
|
|
950
|
my $plan = $hub->plan; |
556
|
248
|
100
|
|
|
|
1063
|
return 0 unless $plan; |
557
|
202
|
100
|
|
|
|
1047
|
return 0 if $plan =~ m/\D/; |
558
|
201
|
|
|
|
|
793
|
return $plan; |
559
|
|
|
|
|
|
|
} |
560
|
|
|
|
|
|
|
|
561
|
|
|
|
|
|
|
|
562
|
|
|
|
|
|
|
sub no_plan { |
563
|
27
|
|
|
27
|
1
|
102
|
my($self, $arg) = @_; |
564
|
|
|
|
|
|
|
|
565
|
27
|
|
|
|
|
106
|
my $ctx = $self->ctx; |
566
|
|
|
|
|
|
|
|
567
|
27
|
100
|
|
|
|
142
|
if (defined $ctx->hub->plan) { |
568
|
1
|
|
|
|
|
14
|
warn "Plan already set, no_plan() is a no-op, this will change to a hard failure in the future."; |
569
|
1
|
|
|
|
|
9
|
$ctx->release; |
570
|
1
|
|
|
|
|
4
|
return; |
571
|
|
|
|
|
|
|
} |
572
|
|
|
|
|
|
|
|
573
|
26
|
100
|
|
|
|
89
|
$ctx->alert("no_plan takes no arguments") if $arg; |
574
|
|
|
|
|
|
|
|
575
|
26
|
|
|
|
|
97
|
$ctx->hub->plan('NO PLAN'); |
576
|
|
|
|
|
|
|
|
577
|
26
|
|
|
|
|
109
|
release $ctx, 1; |
578
|
|
|
|
|
|
|
} |
579
|
|
|
|
|
|
|
|
580
|
|
|
|
|
|
|
|
581
|
|
|
|
|
|
|
sub done_testing { |
582
|
68
|
|
|
68
|
1
|
339
|
my($self, $num_tests) = @_; |
583
|
|
|
|
|
|
|
|
584
|
68
|
|
|
|
|
262
|
my $ctx = $self->ctx; |
585
|
|
|
|
|
|
|
|
586
|
68
|
|
|
|
|
464
|
my $meta = $ctx->hub->meta(__PACKAGE__, {}); |
587
|
|
|
|
|
|
|
|
588
|
68
|
100
|
|
|
|
322
|
if ($meta->{Done_Testing}) { |
589
|
2
|
|
|
|
|
4
|
my ($file, $line) = @{$meta->{Done_Testing}}[1,2]; |
|
2
|
|
|
|
|
6
|
|
590
|
2
|
|
|
|
|
5
|
local $ctx->hub->{ended}; # OMG This is awful. |
591
|
2
|
|
|
|
|
11
|
$self->ok(0, "done_testing() was already called at $file line $line"); |
592
|
2
|
|
|
|
|
7
|
$ctx->release; |
593
|
2
|
|
|
|
|
6
|
return; |
594
|
|
|
|
|
|
|
} |
595
|
66
|
|
|
|
|
285
|
$meta->{Done_Testing} = [$ctx->trace->call]; |
596
|
|
|
|
|
|
|
|
597
|
66
|
|
|
|
|
307
|
my $plan = $ctx->hub->plan; |
598
|
66
|
|
|
|
|
326
|
my $count = $ctx->hub->count; |
599
|
|
|
|
|
|
|
|
600
|
|
|
|
|
|
|
# If done_testing() specified the number of tests, shut off no_plan |
601
|
66
|
100
|
66
|
|
|
990
|
if( defined $num_tests ) { |
|
|
50
|
33
|
|
|
|
|
602
|
19
|
100
|
100
|
|
|
297
|
$ctx->plan($num_tests) if !$plan || $plan eq 'NO PLAN'; |
603
|
|
|
|
|
|
|
} |
604
|
|
|
|
|
|
|
elsif ($count && defined $num_tests && $count != $num_tests) { |
605
|
0
|
|
|
|
|
0
|
$self->ok(0, "planned to run @{[ $self->expected_tests ]} but done_testing() expects $num_tests"); |
|
0
|
|
|
|
|
0
|
|
606
|
|
|
|
|
|
|
} |
607
|
|
|
|
|
|
|
else { |
608
|
47
|
|
|
|
|
214
|
$num_tests = $self->current_test; |
609
|
|
|
|
|
|
|
} |
610
|
|
|
|
|
|
|
|
611
|
66
|
100
|
100
|
|
|
404
|
if( $self->expected_tests && $num_tests != $self->expected_tests ) { |
612
|
2
|
|
|
|
|
8
|
$self->ok(0, "planned to run @{[ $self->expected_tests ]} ". |
|
2
|
|
|
|
|
6
|
|
613
|
|
|
|
|
|
|
"but done_testing() expects $num_tests"); |
614
|
|
|
|
|
|
|
} |
615
|
|
|
|
|
|
|
|
616
|
66
|
100
|
100
|
|
|
340
|
$ctx->plan($num_tests) if $ctx->hub->plan && $ctx->hub->plan eq 'NO PLAN'; |
617
|
|
|
|
|
|
|
|
618
|
66
|
|
|
|
|
233
|
$ctx->hub->finalize($ctx->trace, 1); |
619
|
|
|
|
|
|
|
|
620
|
66
|
|
|
|
|
284
|
release $ctx, 1; |
621
|
|
|
|
|
|
|
} |
622
|
|
|
|
|
|
|
|
623
|
|
|
|
|
|
|
|
624
|
|
|
|
|
|
|
sub has_plan { |
625
|
11
|
|
|
11
|
1
|
27
|
my $self = shift; |
626
|
|
|
|
|
|
|
|
627
|
11
|
|
|
|
|
35
|
my $ctx = $self->ctx; |
628
|
11
|
|
|
|
|
54
|
my $plan = $ctx->hub->plan; |
629
|
11
|
|
|
|
|
49
|
$ctx->release; |
630
|
|
|
|
|
|
|
|
631
|
11
|
100
|
100
|
|
|
107
|
return( $plan ) if $plan && $plan !~ m/\D/; |
632
|
7
|
100
|
66
|
|
|
46
|
return('no_plan') if $plan && $plan eq 'NO PLAN'; |
633
|
2
|
|
|
|
|
19
|
return(undef); |
634
|
|
|
|
|
|
|
} |
635
|
|
|
|
|
|
|
|
636
|
|
|
|
|
|
|
|
637
|
|
|
|
|
|
|
sub skip_all { |
638
|
12
|
|
|
12
|
1
|
41
|
my( $self, $reason ) = @_; |
639
|
|
|
|
|
|
|
|
640
|
12
|
|
|
|
|
42
|
my $ctx = $self->ctx; |
641
|
|
|
|
|
|
|
|
642
|
12
|
|
100
|
|
|
91
|
$ctx->hub->meta(__PACKAGE__, {})->{Skip_All} = $reason || 1; |
643
|
|
|
|
|
|
|
|
644
|
|
|
|
|
|
|
# Work around old perl bug |
645
|
12
|
50
|
|
|
|
59
|
if ($] < 5.020000) { |
646
|
0
|
|
|
|
|
0
|
my $begin = 0; |
647
|
0
|
|
|
|
|
0
|
my $level = 0; |
648
|
0
|
|
|
|
|
0
|
while (my @call = caller($level++)) { |
649
|
0
|
0
|
0
|
|
|
0
|
last unless @call && $call[0]; |
650
|
0
|
0
|
|
|
|
0
|
next unless $call[3] =~ m/::BEGIN$/; |
651
|
0
|
|
|
|
|
0
|
$begin++; |
652
|
0
|
|
|
|
|
0
|
last; |
653
|
|
|
|
|
|
|
} |
654
|
|
|
|
|
|
|
# HACK! |
655
|
0
|
0
|
0
|
|
|
0
|
die 'Label not found for "last T2_SUBTEST_WRAPPER"' if $begin && $ctx->hub->meta(__PACKAGE__, {})->{parent}; |
656
|
|
|
|
|
|
|
} |
657
|
|
|
|
|
|
|
|
658
|
12
|
|
|
|
|
80
|
$ctx->plan(0, SKIP => $reason); |
659
|
|
|
|
|
|
|
} |
660
|
|
|
|
|
|
|
|
661
|
|
|
|
|
|
|
|
662
|
|
|
|
|
|
|
sub exported_to { |
663
|
250
|
|
|
250
|
1
|
644
|
my( $self, $pack ) = @_; |
664
|
|
|
|
|
|
|
|
665
|
250
|
100
|
|
|
|
732
|
if( defined $pack ) { |
666
|
140
|
|
|
|
|
383
|
$self->{Exported_To} = $pack; |
667
|
|
|
|
|
|
|
} |
668
|
250
|
|
|
|
|
599
|
return $self->{Exported_To}; |
669
|
|
|
|
|
|
|
} |
670
|
|
|
|
|
|
|
|
671
|
|
|
|
|
|
|
|
672
|
|
|
|
|
|
|
sub ok { |
673
|
2116
|
|
|
2116
|
1
|
6948
|
my( $self, $test, $name ) = @_; |
674
|
|
|
|
|
|
|
|
675
|
2116
|
|
|
|
|
5012
|
my $ctx = $self->ctx; |
676
|
|
|
|
|
|
|
|
677
|
|
|
|
|
|
|
# $test might contain an object which we don't want to accidentally |
678
|
|
|
|
|
|
|
# store, so we turn it into a boolean. |
679
|
2116
|
100
|
|
|
|
6548
|
$test = $test ? 1 : 0; |
680
|
|
|
|
|
|
|
|
681
|
|
|
|
|
|
|
# In case $name is a string overloaded object, force it to stringify. |
682
|
162
|
|
|
164
|
|
1568
|
no warnings qw/uninitialized numeric/; |
|
162
|
|
|
|
|
421
|
|
|
162
|
|
|
|
|
23486
|
|
683
|
2116
|
100
|
|
|
|
6032
|
$name = "$name" if defined $name; |
684
|
|
|
|
|
|
|
|
685
|
|
|
|
|
|
|
# Profiling showed that the regex here was a huge time waster, doing the |
686
|
|
|
|
|
|
|
# numeric addition first cuts our profile time from ~300ms to ~50ms |
687
|
2116
|
100
|
100
|
|
|
10110
|
$self->diag(<<" ERR") if 0 + $name && $name =~ /^[\d\s]+$/; |
688
|
|
|
|
|
|
|
You named your test '$name'. You shouldn't use numbers for your test names. |
689
|
|
|
|
|
|
|
Very confusing. |
690
|
|
|
|
|
|
|
ERR |
691
|
162
|
|
|
164
|
|
1317
|
use warnings qw/uninitialized numeric/; |
|
162
|
|
|
|
|
407
|
|
|
162
|
|
|
|
|
121371
|
|
692
|
|
|
|
|
|
|
|
693
|
2116
|
|
|
|
|
4251
|
my $trace = $ctx->{trace}; |
694
|
2116
|
|
|
|
|
3459
|
my $hub = $ctx->{hub}; |
695
|
|
|
|
|
|
|
|
696
|
2116
|
100
|
|
|
|
16188
|
my $result = { |
697
|
|
|
|
|
|
|
ok => $test, |
698
|
|
|
|
|
|
|
actual_ok => $test, |
699
|
|
|
|
|
|
|
reason => '', |
700
|
|
|
|
|
|
|
type => '', |
701
|
|
|
|
|
|
|
(name => defined($name) ? $name : ''), |
702
|
|
|
|
|
|
|
}; |
703
|
|
|
|
|
|
|
|
704
|
2116
|
100
|
|
|
|
9378
|
$hub->{_meta}->{+__PACKAGE__}->{Test_Results}[ $hub->{count} ] = $result unless $self->{no_log_results}; |
705
|
|
|
|
|
|
|
|
706
|
2116
|
|
|
|
|
3827
|
my $orig_name = $name; |
707
|
|
|
|
|
|
|
|
708
|
2116
|
|
|
|
|
4141
|
my @attrs; |
709
|
2116
|
|
|
|
|
3825
|
my $subevents = delete $self->{subevents}; |
710
|
2116
|
|
|
|
|
3891
|
my $subtest_id = delete $self->{subtest_id}; |
711
|
2116
|
|
|
|
|
3340
|
my $subtest_uuid = delete $self->{subtest_uuid}; |
712
|
2116
|
|
|
|
|
4269
|
my $subtest_buffered = delete $self->{subtest_buffered}; |
713
|
2116
|
|
|
|
|
4486
|
my $epkg = 'Test2::Event::Ok'; |
714
|
2116
|
100
|
|
|
|
5602
|
if ($subevents) { |
715
|
88
|
|
|
|
|
174
|
$epkg = 'Test2::Event::Subtest'; |
716
|
88
|
|
|
|
|
275
|
push @attrs => (subevents => $subevents, subtest_id => $subtest_id, subtest_uuid => $subtest_uuid, buffered => $subtest_buffered); |
717
|
|
|
|
|
|
|
} |
718
|
|
|
|
|
|
|
|
719
|
2116
|
|
|
|
|
27453
|
my $e = bless { |
720
|
|
|
|
|
|
|
trace => bless( {%$trace}, 'Test2::EventFacet::Trace'), |
721
|
|
|
|
|
|
|
pass => $test, |
722
|
|
|
|
|
|
|
name => $name, |
723
|
|
|
|
|
|
|
_meta => {'Test::Builder' => $result}, |
724
|
|
|
|
|
|
|
effective_pass => $test, |
725
|
|
|
|
|
|
|
@attrs, |
726
|
|
|
|
|
|
|
}, $epkg; |
727
|
2116
|
|
|
|
|
14511
|
$hub->send($e); |
728
|
|
|
|
|
|
|
|
729
|
2116
|
100
|
|
|
|
6175
|
$self->_ok_debug($trace, $orig_name) unless($test); |
730
|
|
|
|
|
|
|
|
731
|
2116
|
|
|
|
|
9077
|
$ctx->release; |
732
|
2116
|
|
|
|
|
17298
|
return $test; |
733
|
|
|
|
|
|
|
} |
734
|
|
|
|
|
|
|
|
735
|
|
|
|
|
|
|
sub _ok_debug { |
736
|
476
|
|
|
476
|
|
754
|
my $self = shift; |
737
|
476
|
|
|
|
|
1073
|
my ($trace, $orig_name) = @_; |
738
|
|
|
|
|
|
|
|
739
|
476
|
|
|
|
|
1210
|
my $is_todo = $self->in_todo; |
740
|
|
|
|
|
|
|
|
741
|
476
|
100
|
|
|
|
1272
|
my $msg = $is_todo ? "Failed (TODO)" : "Failed"; |
742
|
|
|
|
|
|
|
|
743
|
476
|
|
|
|
|
1390
|
my (undef, $file, $line) = $trace->call; |
744
|
476
|
100
|
|
|
|
1169
|
if (defined $orig_name) { |
745
|
447
|
|
|
|
|
2036
|
$self->diag(qq[ $msg test '$orig_name'\n at $file line $line.\n]); |
746
|
|
|
|
|
|
|
} |
747
|
|
|
|
|
|
|
else { |
748
|
29
|
|
|
|
|
251
|
$self->diag(qq[ $msg test at $file line $line.\n]); |
749
|
|
|
|
|
|
|
} |
750
|
|
|
|
|
|
|
} |
751
|
|
|
|
|
|
|
|
752
|
|
|
|
|
|
|
sub _diag_fh { |
753
|
0
|
|
|
0
|
|
0
|
my $self = shift; |
754
|
0
|
|
|
|
|
0
|
local $Level = $Level + 1; |
755
|
0
|
0
|
|
|
|
0
|
return $self->in_todo ? $self->todo_output : $self->failure_output; |
756
|
|
|
|
|
|
|
} |
757
|
|
|
|
|
|
|
|
758
|
|
|
|
|
|
|
sub _unoverload { |
759
|
662
|
|
|
662
|
|
2242
|
my ($self, $type, $thing) = @_; |
760
|
|
|
|
|
|
|
|
761
|
662
|
100
|
|
|
|
1537
|
return unless ref $$thing; |
762
|
502
|
50
|
100
|
457
|
|
2321
|
return unless blessed($$thing) || scalar $self->_try(sub{ $$thing->isa('UNIVERSAL') }); |
|
457
|
|
|
|
|
2539
|
|
763
|
|
|
|
|
|
|
{ |
764
|
45
|
|
|
|
|
92
|
local ($!, $@); |
|
45
|
|
|
|
|
143
|
|
765
|
45
|
|
|
|
|
290
|
require overload; |
766
|
|
|
|
|
|
|
} |
767
|
45
|
|
100
|
|
|
171
|
my $string_meth = overload::Method( $$thing, $type ) || return; |
768
|
8
|
|
|
|
|
431
|
$$thing = $$thing->$string_meth(); |
769
|
|
|
|
|
|
|
} |
770
|
|
|
|
|
|
|
|
771
|
|
|
|
|
|
|
sub _unoverload_str { |
772
|
335
|
|
|
335
|
|
523
|
my $self = shift; |
773
|
|
|
|
|
|
|
|
774
|
335
|
|
|
|
|
901
|
$self->_unoverload( q[""], $_ ) for @_; |
775
|
|
|
|
|
|
|
} |
776
|
|
|
|
|
|
|
|
777
|
|
|
|
|
|
|
sub _unoverload_num { |
778
|
17
|
|
|
17
|
|
30
|
my $self = shift; |
779
|
|
|
|
|
|
|
|
780
|
17
|
|
|
|
|
97
|
$self->_unoverload( '0+', $_ ) for @_; |
781
|
|
|
|
|
|
|
|
782
|
17
|
|
|
|
|
33
|
for my $val (@_) { |
783
|
23
|
100
|
|
|
|
43
|
next unless $self->_is_dualvar($$val); |
784
|
1
|
|
|
|
|
5
|
$$val = $$val + 0; |
785
|
|
|
|
|
|
|
} |
786
|
|
|
|
|
|
|
} |
787
|
|
|
|
|
|
|
|
788
|
|
|
|
|
|
|
# This is a hack to detect a dualvar such as $! |
789
|
|
|
|
|
|
|
sub _is_dualvar { |
790
|
23
|
|
|
23
|
|
45
|
my( $self, $val ) = @_; |
791
|
|
|
|
|
|
|
|
792
|
|
|
|
|
|
|
# Objects are not dualvars. |
793
|
23
|
50
|
|
|
|
39
|
return 0 if ref $val; |
794
|
|
|
|
|
|
|
|
795
|
162
|
|
|
164
|
|
1432
|
no warnings 'numeric'; |
|
162
|
|
|
|
|
444
|
|
|
162
|
|
|
|
|
201877
|
|
796
|
23
|
|
|
|
|
44
|
my $numval = $val + 0; |
797
|
23
|
|
66
|
|
|
118
|
return ($numval != 0 and $numval ne $val ? 1 : 0); |
798
|
|
|
|
|
|
|
} |
799
|
|
|
|
|
|
|
|
800
|
|
|
|
|
|
|
|
801
|
|
|
|
|
|
|
sub is_eq { |
802
|
506
|
|
|
506
|
1
|
2765
|
my( $self, $got, $expect, $name ) = @_; |
803
|
|
|
|
|
|
|
|
804
|
506
|
|
|
|
|
1351
|
my $ctx = $self->ctx; |
805
|
|
|
|
|
|
|
|
806
|
506
|
|
|
|
|
1290
|
local $Level = $Level + 1; |
807
|
|
|
|
|
|
|
|
808
|
506
|
100
|
100
|
|
|
2176
|
if( !defined $got || !defined $expect ) { |
809
|
|
|
|
|
|
|
# undef only matches undef and nothing else |
810
|
13
|
|
100
|
|
|
75
|
my $test = !defined $got && !defined $expect; |
811
|
|
|
|
|
|
|
|
812
|
13
|
|
|
|
|
55
|
$self->ok( $test, $name ); |
813
|
13
|
100
|
|
|
|
61
|
$self->_is_diag( $got, 'eq', $expect ) unless $test; |
814
|
13
|
|
|
|
|
105
|
$ctx->release; |
815
|
13
|
|
|
|
|
57
|
return $test; |
816
|
|
|
|
|
|
|
} |
817
|
|
|
|
|
|
|
|
818
|
493
|
|
|
|
|
1621
|
release $ctx, $self->cmp_ok( $got, 'eq', $expect, $name ); |
819
|
|
|
|
|
|
|
} |
820
|
|
|
|
|
|
|
|
821
|
|
|
|
|
|
|
|
822
|
|
|
|
|
|
|
sub is_num { |
823
|
65
|
|
|
65
|
1
|
1524207
|
my( $self, $got, $expect, $name ) = @_; |
824
|
65
|
|
|
|
|
555
|
my $ctx = $self->ctx; |
825
|
65
|
|
|
|
|
340
|
local $Level = $Level + 1; |
826
|
|
|
|
|
|
|
|
827
|
65
|
100
|
66
|
|
|
469
|
if( !defined $got || !defined $expect ) { |
828
|
|
|
|
|
|
|
# undef only matches undef and nothing else |
829
|
1
|
|
33
|
|
|
7
|
my $test = !defined $got && !defined $expect; |
830
|
|
|
|
|
|
|
|
831
|
1
|
|
|
|
|
4
|
$self->ok( $test, $name ); |
832
|
1
|
50
|
|
|
|
5
|
$self->_is_diag( $got, '==', $expect ) unless $test; |
833
|
1
|
|
|
|
|
5
|
$ctx->release; |
834
|
1
|
|
|
|
|
4
|
return $test; |
835
|
|
|
|
|
|
|
} |
836
|
|
|
|
|
|
|
|
837
|
64
|
|
|
|
|
365
|
release $ctx, $self->cmp_ok( $got, '==', $expect, $name ); |
838
|
|
|
|
|
|
|
} |
839
|
|
|
|
|
|
|
|
840
|
|
|
|
|
|
|
|
841
|
|
|
|
|
|
|
sub _diag_fmt { |
842
|
51
|
|
|
51
|
|
99
|
my( $self, $type, $val ) = @_; |
843
|
|
|
|
|
|
|
|
844
|
51
|
100
|
|
|
|
114
|
if( defined $$val ) { |
845
|
46
|
100
|
100
|
|
|
364
|
if( $type eq 'eq' or $type eq 'ne' ) { |
846
|
|
|
|
|
|
|
# quote and force string context |
847
|
35
|
|
|
|
|
93
|
$$val = "'$$val'"; |
848
|
|
|
|
|
|
|
} |
849
|
|
|
|
|
|
|
else { |
850
|
|
|
|
|
|
|
# force numeric context |
851
|
11
|
|
|
|
|
20
|
$self->_unoverload_num($val); |
852
|
|
|
|
|
|
|
} |
853
|
|
|
|
|
|
|
} |
854
|
|
|
|
|
|
|
else { |
855
|
5
|
|
|
|
|
10
|
$$val = 'undef'; |
856
|
|
|
|
|
|
|
} |
857
|
|
|
|
|
|
|
|
858
|
51
|
|
|
|
|
109
|
return; |
859
|
|
|
|
|
|
|
} |
860
|
|
|
|
|
|
|
|
861
|
|
|
|
|
|
|
|
862
|
|
|
|
|
|
|
sub _is_diag { |
863
|
23
|
|
|
23
|
|
67
|
my( $self, $got, $type, $expect ) = @_; |
864
|
|
|
|
|
|
|
|
865
|
23
|
|
|
|
|
94
|
$self->_diag_fmt( $type, $_ ) for \$got, \$expect; |
866
|
|
|
|
|
|
|
|
867
|
23
|
|
|
|
|
54
|
local $Level = $Level + 1; |
868
|
23
|
|
|
|
|
106
|
return $self->diag(<<"DIAGNOSTIC"); |
869
|
|
|
|
|
|
|
got: $got |
870
|
|
|
|
|
|
|
expected: $expect |
871
|
|
|
|
|
|
|
DIAGNOSTIC |
872
|
|
|
|
|
|
|
|
873
|
|
|
|
|
|
|
} |
874
|
|
|
|
|
|
|
|
875
|
|
|
|
|
|
|
sub _isnt_diag { |
876
|
5
|
|
|
5
|
|
16
|
my( $self, $got, $type ) = @_; |
877
|
|
|
|
|
|
|
|
878
|
5
|
|
|
|
|
16
|
$self->_diag_fmt( $type, \$got ); |
879
|
|
|
|
|
|
|
|
880
|
5
|
|
|
|
|
9
|
local $Level = $Level + 1; |
881
|
5
|
|
|
|
|
25
|
return $self->diag(<<"DIAGNOSTIC"); |
882
|
|
|
|
|
|
|
got: $got |
883
|
|
|
|
|
|
|
expected: anything else |
884
|
|
|
|
|
|
|
DIAGNOSTIC |
885
|
|
|
|
|
|
|
} |
886
|
|
|
|
|
|
|
|
887
|
|
|
|
|
|
|
|
888
|
|
|
|
|
|
|
sub isnt_eq { |
889
|
11
|
|
|
11
|
1
|
39
|
my( $self, $got, $dont_expect, $name ) = @_; |
890
|
11
|
|
|
|
|
33
|
my $ctx = $self->ctx; |
891
|
11
|
|
|
|
|
43
|
local $Level = $Level + 1; |
892
|
|
|
|
|
|
|
|
893
|
11
|
100
|
66
|
|
|
91
|
if( !defined $got || !defined $dont_expect ) { |
894
|
|
|
|
|
|
|
# undef only matches undef and nothing else |
895
|
4
|
|
66
|
|
|
19
|
my $test = defined $got || defined $dont_expect; |
896
|
|
|
|
|
|
|
|
897
|
4
|
|
|
|
|
13
|
$self->ok( $test, $name ); |
898
|
4
|
100
|
|
|
|
17
|
$self->_isnt_diag( $got, 'ne' ) unless $test; |
899
|
4
|
|
|
|
|
13
|
$ctx->release; |
900
|
4
|
|
|
|
|
11
|
return $test; |
901
|
|
|
|
|
|
|
} |
902
|
|
|
|
|
|
|
|
903
|
7
|
|
|
|
|
32
|
release $ctx, $self->cmp_ok( $got, 'ne', $dont_expect, $name ); |
904
|
|
|
|
|
|
|
} |
905
|
|
|
|
|
|
|
|
906
|
|
|
|
|
|
|
sub isnt_num { |
907
|
2
|
|
|
2
|
1
|
103178
|
my( $self, $got, $dont_expect, $name ) = @_; |
908
|
2
|
|
|
|
|
45
|
my $ctx = $self->ctx; |
909
|
2
|
|
|
|
|
17
|
local $Level = $Level + 1; |
910
|
|
|
|
|
|
|
|
911
|
2
|
100
|
66
|
|
|
43
|
if( !defined $got || !defined $dont_expect ) { |
912
|
|
|
|
|
|
|
# undef only matches undef and nothing else |
913
|
1
|
|
33
|
|
|
4
|
my $test = defined $got || defined $dont_expect; |
914
|
|
|
|
|
|
|
|
915
|
1
|
|
|
|
|
4
|
$self->ok( $test, $name ); |
916
|
1
|
50
|
|
|
|
5
|
$self->_isnt_diag( $got, '!=' ) unless $test; |
917
|
1
|
|
|
|
|
4
|
$ctx->release; |
918
|
1
|
|
|
|
|
4
|
return $test; |
919
|
|
|
|
|
|
|
} |
920
|
|
|
|
|
|
|
|
921
|
1
|
|
|
|
|
35
|
release $ctx, $self->cmp_ok( $got, '!=', $dont_expect, $name ); |
922
|
|
|
|
|
|
|
} |
923
|
|
|
|
|
|
|
|
924
|
|
|
|
|
|
|
|
925
|
|
|
|
|
|
|
sub like { |
926
|
315
|
|
|
315
|
1
|
4543712
|
my( $self, $thing, $regex, $name ) = @_; |
927
|
315
|
|
|
|
|
5334
|
my $ctx = $self->ctx; |
928
|
|
|
|
|
|
|
|
929
|
315
|
|
|
|
|
2303
|
local $Level = $Level + 1; |
930
|
|
|
|
|
|
|
|
931
|
315
|
|
|
|
|
2617
|
release $ctx, $self->_regex_ok( $thing, $regex, '=~', $name ); |
932
|
|
|
|
|
|
|
} |
933
|
|
|
|
|
|
|
|
934
|
|
|
|
|
|
|
sub unlike { |
935
|
5
|
|
|
5
|
1
|
18
|
my( $self, $thing, $regex, $name ) = @_; |
936
|
5
|
|
|
|
|
12
|
my $ctx = $self->ctx; |
937
|
|
|
|
|
|
|
|
938
|
5
|
|
|
|
|
15
|
local $Level = $Level + 1; |
939
|
|
|
|
|
|
|
|
940
|
5
|
|
|
|
|
19
|
release $ctx, $self->_regex_ok( $thing, $regex, '!~', $name ); |
941
|
|
|
|
|
|
|
} |
942
|
|
|
|
|
|
|
|
943
|
|
|
|
|
|
|
|
944
|
|
|
|
|
|
|
my %numeric_cmps = map { ( $_, 1 ) } ( "<", "<=", ">", ">=", "==", "!=", "<=>" ); |
945
|
|
|
|
|
|
|
|
946
|
|
|
|
|
|
|
# Bad, these are not comparison operators. Should we include more? |
947
|
|
|
|
|
|
|
my %cmp_ok_bl = map { ( $_, 1 ) } ( "=", "+=", ".=", "x=", "^=", "|=", "||=", "&&=", "..."); |
948
|
|
|
|
|
|
|
|
949
|
|
|
|
|
|
|
sub cmp_ok { |
950
|
601
|
|
|
601
|
1
|
1686
|
my( $self, $got, $type, $expect, $name ) = @_; |
951
|
601
|
|
|
|
|
1292
|
my $ctx = $self->ctx; |
952
|
|
|
|
|
|
|
|
953
|
601
|
100
|
|
|
|
2188
|
if ($cmp_ok_bl{$type}) { |
954
|
2
|
|
|
|
|
12
|
$ctx->throw("$type is not a valid comparison operator in cmp_ok()"); |
955
|
|
|
|
|
|
|
} |
956
|
|
|
|
|
|
|
|
957
|
599
|
|
|
|
|
1539
|
my ($test, $succ); |
958
|
599
|
|
|
|
|
0
|
my $error; |
959
|
|
|
|
|
|
|
{ |
960
|
|
|
|
|
|
|
## no critic (BuiltinFunctions::ProhibitStringyEval) |
961
|
|
|
|
|
|
|
|
962
|
599
|
|
|
|
|
937
|
local( $@, $!, $SIG{__DIE__} ); # isolate eval |
|
599
|
|
|
|
|
3235
|
|
963
|
|
|
|
|
|
|
|
964
|
599
|
|
|
|
|
2429
|
my($pack, $file, $line) = $ctx->trace->call(); |
965
|
599
|
|
|
|
|
1767
|
my $warning_bits = $ctx->trace->warning_bits; |
966
|
|
|
|
|
|
|
|
967
|
|
|
|
|
|
|
# This is so that warnings come out at the caller's level |
968
|
599
|
|
|
96
|
|
54153
|
$succ = eval qq[ |
|
96
|
|
|
53
|
|
3911
|
|
|
73
|
|
|
36
|
|
2341
|
|
|
56
|
|
|
26
|
|
1668
|
|
|
26
|
|
|
21
|
|
1144
|
|
|
21
|
|
|
18
|
|
949
|
|
|
18
|
|
|
12
|
|
777
|
|
|
12
|
|
|
12
|
|
535
|
|
|
12
|
|
|
11
|
|
507
|
|
|
11
|
|
|
11
|
|
466
|
|
|
11
|
|
|
11
|
|
515
|
|
|
11
|
|
|
10
|
|
566
|
|
|
10
|
|
|
8
|
|
496
|
|
|
8
|
|
|
8
|
|
396
|
|
|
8
|
|
|
8
|
|
388
|
|
|
8
|
|
|
8
|
|
573
|
|
|
8
|
|
|
7
|
|
371
|
|
|
7
|
|
|
6
|
|
256
|
|
|
6
|
|
|
6
|
|
252
|
|
|
6
|
|
|
6
|
|
228
|
|
|
6
|
|
|
6
|
|
246
|
|
|
6
|
|
|
6
|
|
232
|
|
|
6
|
|
|
6
|
|
213
|
|
|
6
|
|
|
6
|
|
214
|
|
|
6
|
|
|
6
|
|
240
|
|
|
6
|
|
|
6
|
|
548
|
|
|
6
|
|
|
6
|
|
234
|
|
|
6
|
|
|
5
|
|
236
|
|
|
5
|
|
|
5
|
|
192
|
|
|
5
|
|
|
5
|
|
180
|
|
|
5
|
|
|
5
|
|
173
|
|
|
5
|
|
|
5
|
|
181
|
|
|
5
|
|
|
5
|
|
178
|
|
|
5
|
|
|
5
|
|
183
|
|
|
5
|
|
|
5
|
|
248
|
|
|
5
|
|
|
5
|
|
184
|
|
|
5
|
|
|
5
|
|
185
|
|
|
5
|
|
|
5
|
|
252
|
|
|
5
|
|
|
5
|
|
166
|
|
|
5
|
|
|
5
|
|
202
|
|
|
5
|
|
|
5
|
|
227
|
|
|
5
|
|
|
5
|
|
185
|
|
|
5
|
|
|
5
|
|
196
|
|
|
5
|
|
|
5
|
|
189
|
|
|
5
|
|
|
5
|
|
185
|
|
|
5
|
|
|
5
|
|
220
|
|
|
5
|
|
|
|
|
174
|
|
969
|
|
|
|
|
|
|
BEGIN {\${^WARNING_BITS} = \$warning_bits}; |
970
|
|
|
|
|
|
|
#line $line "(eval in cmp_ok) $file" |
971
|
|
|
|
|
|
|
\$test = (\$got $type \$expect); |
972
|
|
|
|
|
|
|
1; |
973
|
|
|
|
|
|
|
]; |
974
|
599
|
|
|
|
|
10107
|
$error = $@; |
975
|
|
|
|
|
|
|
} |
976
|
599
|
|
|
|
|
1474
|
local $Level = $Level + 1; |
977
|
599
|
|
|
|
|
1891
|
my $ok = $self->ok( $test, $name ); |
978
|
|
|
|
|
|
|
|
979
|
|
|
|
|
|
|
# Treat overloaded objects as numbers if we're asked to do a |
980
|
|
|
|
|
|
|
# numeric comparison. |
981
|
|
|
|
|
|
|
my $unoverload |
982
|
599
|
100
|
|
|
|
2130
|
= $numeric_cmps{$type} |
983
|
|
|
|
|
|
|
? '_unoverload_num' |
984
|
|
|
|
|
|
|
: '_unoverload_str'; |
985
|
|
|
|
|
|
|
|
986
|
599
|
100
|
|
|
|
1370
|
$self->diag(<<"END") unless $succ; |
987
|
|
|
|
|
|
|
An error occurred while using $type: |
988
|
|
|
|
|
|
|
------------------------------------ |
989
|
|
|
|
|
|
|
$error |
990
|
|
|
|
|
|
|
------------------------------------ |
991
|
|
|
|
|
|
|
END |
992
|
|
|
|
|
|
|
|
993
|
599
|
100
|
|
|
|
1237
|
unless($ok) { |
994
|
28
|
|
|
|
|
166
|
$self->$unoverload( \$got, \$expect ); |
995
|
|
|
|
|
|
|
|
996
|
28
|
100
|
|
|
|
240
|
if( $type =~ /^(eq|==)$/ ) { |
|
|
100
|
|
|
|
|
|
997
|
19
|
|
|
|
|
77
|
$self->_is_diag( $got, $type, $expect ); |
998
|
|
|
|
|
|
|
} |
999
|
|
|
|
|
|
|
elsif( $type =~ /^(ne|!=)$/ ) { |
1000
|
162
|
|
|
164
|
|
1417
|
no warnings; |
|
162
|
|
|
|
|
363
|
|
|
162
|
|
|
|
|
11510
|
|
1001
|
6
|
|
66
|
|
|
74
|
my $eq = ($got eq $expect || $got == $expect) |
1002
|
|
|
|
|
|
|
&& ( |
1003
|
|
|
|
|
|
|
(defined($got) xor defined($expect)) |
1004
|
|
|
|
|
|
|
|| (length($got) != length($expect)) |
1005
|
|
|
|
|
|
|
); |
1006
|
162
|
|
|
164
|
|
1183
|
use warnings; |
|
162
|
|
|
|
|
358
|
|
|
162
|
|
|
|
|
59674
|
|
1007
|
|
|
|
|
|
|
|
1008
|
6
|
100
|
|
|
|
19
|
if ($eq) { |
1009
|
2
|
|
|
|
|
10
|
$self->_cmp_diag( $got, $type, $expect ); |
1010
|
|
|
|
|
|
|
} |
1011
|
|
|
|
|
|
|
else { |
1012
|
4
|
|
|
|
|
15
|
$self->_isnt_diag( $got, $type ); |
1013
|
|
|
|
|
|
|
} |
1014
|
|
|
|
|
|
|
} |
1015
|
|
|
|
|
|
|
else { |
1016
|
3
|
|
|
|
|
11
|
$self->_cmp_diag( $got, $type, $expect ); |
1017
|
|
|
|
|
|
|
} |
1018
|
|
|
|
|
|
|
} |
1019
|
599
|
|
|
|
|
1963
|
return release $ctx, $ok; |
1020
|
|
|
|
|
|
|
} |
1021
|
|
|
|
|
|
|
|
1022
|
|
|
|
|
|
|
sub _cmp_diag { |
1023
|
5
|
|
|
5
|
|
19
|
my( $self, $got, $type, $expect ) = @_; |
1024
|
|
|
|
|
|
|
|
1025
|
5
|
100
|
|
|
|
21
|
$got = defined $got ? "'$got'" : 'undef'; |
1026
|
5
|
50
|
|
|
|
21
|
$expect = defined $expect ? "'$expect'" : 'undef'; |
1027
|
|
|
|
|
|
|
|
1028
|
5
|
|
|
|
|
15
|
local $Level = $Level + 1; |
1029
|
5
|
|
|
|
|
33
|
return $self->diag(<<"DIAGNOSTIC"); |
1030
|
|
|
|
|
|
|
$got |
1031
|
|
|
|
|
|
|
$type |
1032
|
|
|
|
|
|
|
$expect |
1033
|
|
|
|
|
|
|
DIAGNOSTIC |
1034
|
|
|
|
|
|
|
} |
1035
|
|
|
|
|
|
|
|
1036
|
|
|
|
|
|
|
sub _caller_context { |
1037
|
319
|
|
|
319
|
|
1214
|
my $self = shift; |
1038
|
|
|
|
|
|
|
|
1039
|
319
|
|
|
|
|
3349
|
my( $pack, $file, $line ) = $self->caller(1); |
1040
|
|
|
|
|
|
|
|
1041
|
319
|
|
|
|
|
2104
|
my $code = ''; |
1042
|
319
|
50
|
33
|
|
|
2894
|
$code .= "#line $line $file\n" if defined $file and defined $line; |
1043
|
|
|
|
|
|
|
|
1044
|
319
|
|
|
|
|
1215
|
return $code; |
1045
|
|
|
|
|
|
|
} |
1046
|
|
|
|
|
|
|
|
1047
|
|
|
|
|
|
|
|
1048
|
|
|
|
|
|
|
sub BAIL_OUT { |
1049
|
2
|
|
|
2
|
1
|
6
|
my( $self, $reason ) = @_; |
1050
|
|
|
|
|
|
|
|
1051
|
2
|
|
|
|
|
7
|
my $ctx = $self->ctx; |
1052
|
|
|
|
|
|
|
|
1053
|
2
|
|
|
|
|
9
|
$self->{Bailed_Out} = 1; |
1054
|
|
|
|
|
|
|
|
1055
|
2
|
|
|
|
|
11
|
$ctx->bail($reason); |
1056
|
|
|
|
|
|
|
} |
1057
|
|
|
|
|
|
|
|
1058
|
|
|
|
|
|
|
|
1059
|
|
|
|
|
|
|
{ |
1060
|
162
|
|
|
164
|
|
1390
|
no warnings 'once'; |
|
162
|
|
|
|
|
423
|
|
|
162
|
|
|
|
|
119118
|
|
1061
|
|
|
|
|
|
|
*BAILOUT = \&BAIL_OUT; |
1062
|
|
|
|
|
|
|
} |
1063
|
|
|
|
|
|
|
|
1064
|
|
|
|
|
|
|
sub skip { |
1065
|
31
|
|
|
31
|
1
|
101
|
my( $self, $why, $name ) = @_; |
1066
|
31
|
|
50
|
|
|
80
|
$why ||= ''; |
1067
|
31
|
100
|
|
|
|
79
|
$name = '' unless defined $name; |
1068
|
31
|
|
|
|
|
110
|
$self->_unoverload_str( \$why ); |
1069
|
|
|
|
|
|
|
|
1070
|
31
|
|
|
|
|
164
|
my $ctx = $self->ctx; |
1071
|
|
|
|
|
|
|
|
1072
|
|
|
|
|
|
|
$ctx->hub->meta(__PACKAGE__, {})->{Test_Results}[ $ctx->hub->count ] = { |
1073
|
|
|
|
|
|
|
'ok' => 1, |
1074
|
|
|
|
|
|
|
actual_ok => 1, |
1075
|
|
|
|
|
|
|
name => $name, |
1076
|
|
|
|
|
|
|
type => 'skip', |
1077
|
|
|
|
|
|
|
reason => $why, |
1078
|
31
|
50
|
|
|
|
242
|
} unless $self->{no_log_results}; |
1079
|
|
|
|
|
|
|
|
1080
|
31
|
|
|
|
|
85
|
$name =~ s|#|\\#|g; # # in a name can confuse Test::Harness. |
1081
|
31
|
|
|
|
|
53
|
$name =~ s{\n}{\n# }sg; |
1082
|
31
|
|
|
|
|
67
|
$why =~ s{\n}{\n# }sg; |
1083
|
|
|
|
|
|
|
|
1084
|
31
|
|
|
|
|
96
|
my $tctx = $ctx->snapshot; |
1085
|
31
|
|
|
|
|
132
|
$tctx->skip('', $why); |
1086
|
|
|
|
|
|
|
|
1087
|
31
|
|
|
|
|
140
|
return release $ctx, 1; |
1088
|
|
|
|
|
|
|
} |
1089
|
|
|
|
|
|
|
|
1090
|
|
|
|
|
|
|
|
1091
|
|
|
|
|
|
|
sub todo_skip { |
1092
|
6
|
|
|
6
|
1
|
29
|
my( $self, $why ) = @_; |
1093
|
6
|
|
50
|
|
|
19
|
$why ||= ''; |
1094
|
|
|
|
|
|
|
|
1095
|
6
|
|
|
|
|
19
|
my $ctx = $self->ctx; |
1096
|
|
|
|
|
|
|
|
1097
|
|
|
|
|
|
|
$ctx->hub->meta(__PACKAGE__, {})->{Test_Results}[ $ctx->hub->count ] = { |
1098
|
|
|
|
|
|
|
'ok' => 1, |
1099
|
|
|
|
|
|
|
actual_ok => 0, |
1100
|
|
|
|
|
|
|
name => '', |
1101
|
|
|
|
|
|
|
type => 'todo_skip', |
1102
|
|
|
|
|
|
|
reason => $why, |
1103
|
6
|
50
|
|
|
|
77
|
} unless $self->{no_log_results}; |
1104
|
|
|
|
|
|
|
|
1105
|
6
|
|
|
|
|
36
|
$why =~ s{\n}{\n# }sg; |
1106
|
6
|
|
|
|
|
30
|
my $tctx = $ctx->snapshot; |
1107
|
6
|
|
|
|
|
30
|
$tctx->send_event( 'Skip', todo => $why, todo_diag => 1, reason => $why, pass => 0); |
1108
|
|
|
|
|
|
|
|
1109
|
6
|
|
|
|
|
30
|
return release $ctx, 1; |
1110
|
|
|
|
|
|
|
} |
1111
|
|
|
|
|
|
|
|
1112
|
|
|
|
|
|
|
|
1113
|
|
|
|
|
|
|
sub maybe_regex { |
1114
|
327
|
|
|
327
|
1
|
864
|
my( $self, $regex ) = @_; |
1115
|
327
|
|
|
|
|
694
|
my $usable_regex = undef; |
1116
|
|
|
|
|
|
|
|
1117
|
327
|
100
|
|
|
|
957
|
return $usable_regex unless defined $regex; |
1118
|
|
|
|
|
|
|
|
1119
|
326
|
|
|
|
|
626
|
my( $re, $opts ); |
1120
|
|
|
|
|
|
|
|
1121
|
|
|
|
|
|
|
# Check for qr/foo/ |
1122
|
326
|
100
|
100
|
|
|
861
|
if( _is_qr($regex) ) { |
|
|
100
|
|
|
|
|
|
1123
|
302
|
|
|
|
|
651
|
$usable_regex = $regex; |
1124
|
|
|
|
|
|
|
} |
1125
|
|
|
|
|
|
|
# Check for '/foo/' or 'm,foo,' |
1126
|
|
|
|
|
|
|
elsif(( $re, $opts ) = $regex =~ m{^ /(.*)/ (\w*) $ }sx or |
1127
|
|
|
|
|
|
|
( undef, $re, $opts ) = $regex =~ m,^ m([^\w\s]) (.+) \1 (\w*) $,sx |
1128
|
|
|
|
|
|
|
) |
1129
|
|
|
|
|
|
|
{ |
1130
|
22
|
100
|
|
|
|
81
|
$usable_regex = length $opts ? "(?$opts)$re" : $re; |
1131
|
|
|
|
|
|
|
} |
1132
|
|
|
|
|
|
|
|
1133
|
326
|
|
|
|
|
1240
|
return $usable_regex; |
1134
|
|
|
|
|
|
|
} |
1135
|
|
|
|
|
|
|
|
1136
|
|
|
|
|
|
|
sub _is_qr { |
1137
|
326
|
|
|
326
|
|
706
|
my $regex = shift; |
1138
|
|
|
|
|
|
|
|
1139
|
|
|
|
|
|
|
# is_regexp() checks for regexes in a robust manner, say if they're |
1140
|
|
|
|
|
|
|
# blessed. |
1141
|
326
|
50
|
|
|
|
2375
|
return re::is_regexp($regex) if defined &re::is_regexp; |
1142
|
0
|
|
|
|
|
0
|
return ref $regex eq 'Regexp'; |
1143
|
|
|
|
|
|
|
} |
1144
|
|
|
|
|
|
|
|
1145
|
|
|
|
|
|
|
sub _regex_ok { |
1146
|
320
|
|
|
320
|
|
2999
|
my( $self, $thing, $regex, $cmp, $name ) = @_; |
1147
|
|
|
|
|
|
|
|
1148
|
320
|
|
|
|
|
792
|
my $ok = 0; |
1149
|
320
|
|
|
|
|
1235
|
my $usable_regex = $self->maybe_regex($regex); |
1150
|
320
|
100
|
|
|
|
1303
|
unless( defined $usable_regex ) { |
1151
|
1
|
|
|
|
|
2
|
local $Level = $Level + 1; |
1152
|
1
|
|
|
|
|
3
|
$ok = $self->ok( 0, $name ); |
1153
|
1
|
|
|
|
|
6
|
$self->diag(" '$regex' doesn't look much like a regex to me."); |
1154
|
1
|
|
|
|
|
5
|
return $ok; |
1155
|
|
|
|
|
|
|
} |
1156
|
|
|
|
|
|
|
|
1157
|
|
|
|
|
|
|
{ |
1158
|
319
|
|
|
|
|
596
|
my $test; |
|
319
|
|
|
|
|
642
|
|
1159
|
319
|
|
|
|
|
3053
|
my $context = $self->_caller_context; |
1160
|
|
|
|
|
|
|
|
1161
|
|
|
|
|
|
|
{ |
1162
|
|
|
|
|
|
|
## no critic (BuiltinFunctions::ProhibitStringyEval) |
1163
|
|
|
|
|
|
|
|
1164
|
319
|
|
|
|
|
854
|
local( $@, $!, $SIG{__DIE__} ); # isolate eval |
|
319
|
|
|
|
|
5767
|
|
1165
|
|
|
|
|
|
|
|
1166
|
|
|
|
|
|
|
# No point in issuing an uninit warning, they'll see it in the diagnostics |
1167
|
162
|
|
|
164
|
|
1353
|
no warnings 'uninitialized'; |
|
162
|
|
|
|
|
368
|
|
|
162
|
|
|
|
|
90806
|
|
1168
|
|
|
|
|
|
|
|
1169
|
319
|
|
|
|
|
28337
|
$test = eval $context . q{$test = $thing =~ /$usable_regex/ ? 1 : 0}; |
1170
|
|
|
|
|
|
|
} |
1171
|
|
|
|
|
|
|
|
1172
|
319
|
100
|
|
|
|
11818
|
$test = !$test if $cmp eq '!~'; |
1173
|
|
|
|
|
|
|
|
1174
|
319
|
|
|
|
|
953
|
local $Level = $Level + 1; |
1175
|
319
|
|
|
|
|
2418
|
$ok = $self->ok( $test, $name ); |
1176
|
|
|
|
|
|
|
} |
1177
|
|
|
|
|
|
|
|
1178
|
319
|
100
|
|
|
|
1130
|
unless($ok) { |
1179
|
5
|
50
|
|
|
|
18
|
$thing = defined $thing ? "'$thing'" : 'undef'; |
1180
|
5
|
100
|
|
|
|
17
|
my $match = $cmp eq '=~' ? "doesn't match" : "matches"; |
1181
|
|
|
|
|
|
|
|
1182
|
5
|
|
|
|
|
12
|
local $Level = $Level + 1; |
1183
|
5
|
|
|
|
|
32
|
$self->diag( sprintf <<'DIAGNOSTIC', $thing, $match, $regex ); |
1184
|
|
|
|
|
|
|
%s |
1185
|
|
|
|
|
|
|
%13s '%s' |
1186
|
|
|
|
|
|
|
DIAGNOSTIC |
1187
|
|
|
|
|
|
|
|
1188
|
|
|
|
|
|
|
} |
1189
|
|
|
|
|
|
|
|
1190
|
319
|
|
|
|
|
3584
|
return $ok; |
1191
|
|
|
|
|
|
|
} |
1192
|
|
|
|
|
|
|
|
1193
|
|
|
|
|
|
|
|
1194
|
|
|
|
|
|
|
sub is_fh { |
1195
|
1167
|
|
|
1167
|
1
|
2476
|
my $self = shift; |
1196
|
1167
|
|
|
|
|
1658
|
my $maybe_fh = shift; |
1197
|
1167
|
100
|
|
|
|
2514
|
return 0 unless defined $maybe_fh; |
1198
|
|
|
|
|
|
|
|
1199
|
1166
|
100
|
|
|
|
3664
|
return 1 if ref $maybe_fh eq 'GLOB'; # its a glob ref |
1200
|
182
|
100
|
|
|
|
449
|
return 1 if ref \$maybe_fh eq 'GLOB'; # its a glob |
1201
|
|
|
|
|
|
|
|
1202
|
|
|
|
|
|
|
return eval { $maybe_fh->isa("IO::Handle") } || |
1203
|
180
|
|
66
|
|
|
369
|
eval { tied($maybe_fh)->can('TIEHANDLE') }; |
1204
|
|
|
|
|
|
|
} |
1205
|
|
|
|
|
|
|
|
1206
|
|
|
|
|
|
|
|
1207
|
|
|
|
|
|
|
sub level { |
1208
|
20
|
|
|
20
|
1
|
138
|
my( $self, $level ) = @_; |
1209
|
|
|
|
|
|
|
|
1210
|
20
|
100
|
|
|
|
65
|
if( defined $level ) { |
1211
|
18
|
|
|
|
|
43
|
$Level = $level; |
1212
|
|
|
|
|
|
|
} |
1213
|
20
|
|
|
|
|
53
|
return $Level; |
1214
|
|
|
|
|
|
|
} |
1215
|
|
|
|
|
|
|
|
1216
|
|
|
|
|
|
|
|
1217
|
|
|
|
|
|
|
sub use_numbers { |
1218
|
221
|
|
|
221
|
1
|
647
|
my( $self, $use_nums ) = @_; |
1219
|
|
|
|
|
|
|
|
1220
|
221
|
|
|
|
|
768
|
my $ctx = $self->ctx; |
1221
|
221
|
|
|
|
|
1175
|
my $format = $ctx->hub->format; |
1222
|
221
|
50
|
66
|
|
|
3556
|
unless ($format && $format->can('no_numbers') && $format->can('set_no_numbers')) { |
|
|
|
66
|
|
|
|
|
1223
|
3
|
50
|
|
|
|
17
|
warn "The current formatter does not support 'use_numbers'" if $format; |
1224
|
3
|
|
|
|
|
17
|
return release $ctx, 0; |
1225
|
|
|
|
|
|
|
} |
1226
|
|
|
|
|
|
|
|
1227
|
218
|
100
|
|
|
|
1512
|
$format->set_no_numbers(!$use_nums) if defined $use_nums; |
1228
|
|
|
|
|
|
|
|
1229
|
218
|
100
|
|
|
|
988
|
return release $ctx, $format->no_numbers ? 0 : 1; |
1230
|
|
|
|
|
|
|
} |
1231
|
|
|
|
|
|
|
|
1232
|
|
|
|
|
|
|
BEGIN { |
1233
|
162
|
|
|
164
|
|
596
|
for my $method (qw(no_header no_diag)) { |
1234
|
324
|
|
|
|
|
1073
|
my $set = "set_$method"; |
1235
|
|
|
|
|
|
|
my $code = sub { |
1236
|
61
|
|
|
61
|
|
195
|
my( $self, $no ) = @_; |
1237
|
|
|
|
|
|
|
|
1238
|
61
|
|
|
|
|
191
|
my $ctx = $self->ctx; |
1239
|
61
|
|
|
|
|
308
|
my $format = $ctx->hub->format; |
1240
|
61
|
100
|
66
|
|
|
551
|
unless ($format && $format->can($set)) { |
1241
|
1
|
50
|
|
|
|
3
|
warn "The current formatter does not support '$method'" if $format; |
1242
|
1
|
|
|
|
|
5
|
$ctx->release; |
1243
|
|
|
|
|
|
|
return |
1244
|
1
|
|
|
|
|
4
|
} |
1245
|
|
|
|
|
|
|
|
1246
|
60
|
100
|
|
|
|
421
|
$format->$set($no) if defined $no; |
1247
|
|
|
|
|
|
|
|
1248
|
60
|
100
|
|
|
|
262
|
return release $ctx, $format->$method ? 1 : 0; |
1249
|
324
|
|
|
|
|
1815
|
}; |
1250
|
|
|
|
|
|
|
|
1251
|
162
|
|
|
164
|
|
1392
|
no strict 'refs'; ## no critic |
|
162
|
|
|
|
|
417
|
|
|
162
|
|
|
|
|
5355
|
|
1252
|
324
|
|
|
|
|
268664
|
*$method = $code; |
1253
|
|
|
|
|
|
|
} |
1254
|
|
|
|
|
|
|
} |
1255
|
|
|
|
|
|
|
|
1256
|
|
|
|
|
|
|
sub no_ending { |
1257
|
198
|
|
|
198
|
1
|
504
|
my( $self, $no ) = @_; |
1258
|
|
|
|
|
|
|
|
1259
|
198
|
|
|
|
|
509
|
my $ctx = $self->ctx; |
1260
|
|
|
|
|
|
|
|
1261
|
198
|
100
|
|
|
|
1095
|
$ctx->hub->set_no_ending($no) if defined $no; |
1262
|
|
|
|
|
|
|
|
1263
|
198
|
|
|
|
|
543
|
return release $ctx, $ctx->hub->no_ending; |
1264
|
|
|
|
|
|
|
} |
1265
|
|
|
|
|
|
|
|
1266
|
|
|
|
|
|
|
sub diag { |
1267
|
616
|
|
|
616
|
1
|
1155
|
my $self = shift; |
1268
|
616
|
100
|
|
|
|
1466
|
return unless @_; |
1269
|
|
|
|
|
|
|
|
1270
|
608
|
100
|
|
|
|
1399
|
my $text = join '' => map {defined($_) ? $_ : 'undef'} @_; |
|
613
|
|
|
|
|
2478
|
|
1271
|
|
|
|
|
|
|
|
1272
|
608
|
100
|
|
|
|
1793
|
if (Test2::API::test2_in_preload()) { |
1273
|
1
|
|
|
|
|
4
|
chomp($text); |
1274
|
1
|
|
|
|
|
7
|
$text =~ s/^/# /msg; |
1275
|
1
|
|
|
|
|
6
|
print STDERR $text, "\n"; |
1276
|
1
|
|
|
|
|
3
|
return 0; |
1277
|
|
|
|
|
|
|
} |
1278
|
|
|
|
|
|
|
|
1279
|
607
|
|
|
|
|
1462
|
my $ctx = $self->ctx; |
1280
|
607
|
|
|
|
|
2618
|
$ctx->diag($text); |
1281
|
607
|
|
|
|
|
2302
|
$ctx->release; |
1282
|
607
|
|
|
|
|
1886
|
return 0; |
1283
|
|
|
|
|
|
|
} |
1284
|
|
|
|
|
|
|
|
1285
|
|
|
|
|
|
|
|
1286
|
|
|
|
|
|
|
sub note { |
1287
|
13
|
|
|
13
|
1
|
42
|
my $self = shift; |
1288
|
13
|
50
|
|
|
|
37
|
return unless @_; |
1289
|
|
|
|
|
|
|
|
1290
|
13
|
50
|
|
|
|
32
|
my $text = join '' => map {defined($_) ? $_ : 'undef'} @_; |
|
14
|
|
|
|
|
72
|
|
1291
|
|
|
|
|
|
|
|
1292
|
13
|
100
|
|
|
|
45
|
if (Test2::API::test2_in_preload()) { |
1293
|
1
|
|
|
|
|
2
|
chomp($text); |
1294
|
1
|
|
|
|
|
6
|
$text =~ s/^/# /msg; |
1295
|
1
|
|
|
|
|
3
|
print STDOUT $text, "\n"; |
1296
|
1
|
|
|
|
|
6
|
return 0; |
1297
|
|
|
|
|
|
|
} |
1298
|
|
|
|
|
|
|
|
1299
|
12
|
|
|
|
|
33
|
my $ctx = $self->ctx; |
1300
|
12
|
|
|
|
|
60
|
$ctx->note($text); |
1301
|
12
|
|
|
|
|
56
|
$ctx->release; |
1302
|
12
|
|
|
|
|
42
|
return 0; |
1303
|
|
|
|
|
|
|
} |
1304
|
|
|
|
|
|
|
|
1305
|
|
|
|
|
|
|
|
1306
|
|
|
|
|
|
|
sub explain { |
1307
|
5
|
|
|
5
|
1
|
9
|
my $self = shift; |
1308
|
|
|
|
|
|
|
|
1309
|
5
|
|
|
|
|
16
|
local ($@, $!); |
1310
|
5
|
|
|
|
|
1266
|
require Data::Dumper; |
1311
|
|
|
|
|
|
|
|
1312
|
|
|
|
|
|
|
return map { |
1313
|
5
|
|
|
|
|
13647
|
ref $_ |
1314
|
9
|
100
|
|
|
|
95
|
? do { |
1315
|
4
|
|
|
|
|
22
|
my $dumper = Data::Dumper->new( [$_] ); |
1316
|
4
|
|
|
|
|
106
|
$dumper->Indent(1)->Terse(1); |
1317
|
4
|
50
|
|
|
|
96
|
$dumper->Sortkeys(1) if $dumper->can("Sortkeys"); |
1318
|
4
|
|
|
|
|
26
|
$dumper->Dump; |
1319
|
|
|
|
|
|
|
} |
1320
|
|
|
|
|
|
|
: $_ |
1321
|
|
|
|
|
|
|
} @_; |
1322
|
|
|
|
|
|
|
} |
1323
|
|
|
|
|
|
|
|
1324
|
|
|
|
|
|
|
|
1325
|
|
|
|
|
|
|
sub output { |
1326
|
491
|
|
|
491
|
1
|
1769
|
my( $self, $fh ) = @_; |
1327
|
|
|
|
|
|
|
|
1328
|
491
|
|
|
|
|
1210
|
my $ctx = $self->ctx; |
1329
|
491
|
|
|
|
|
1772
|
my $format = $ctx->hub->format; |
1330
|
491
|
|
|
|
|
1694
|
$ctx->release; |
1331
|
491
|
50
|
33
|
|
|
2739
|
return unless $format && $format->isa('Test2::Formatter::TAP'); |
1332
|
|
|
|
|
|
|
|
1333
|
491
|
100
|
|
|
|
1670
|
$format->handles->[Test2::Formatter::TAP::OUT_STD()] = $self->_new_fh($fh) |
1334
|
|
|
|
|
|
|
if defined $fh; |
1335
|
|
|
|
|
|
|
|
1336
|
491
|
|
|
|
|
1136
|
return $format->handles->[Test2::Formatter::TAP::OUT_STD()]; |
1337
|
|
|
|
|
|
|
} |
1338
|
|
|
|
|
|
|
|
1339
|
|
|
|
|
|
|
sub failure_output { |
1340
|
484
|
|
|
484
|
1
|
1181
|
my( $self, $fh ) = @_; |
1341
|
|
|
|
|
|
|
|
1342
|
484
|
|
|
|
|
1061
|
my $ctx = $self->ctx; |
1343
|
484
|
|
|
|
|
1674
|
my $format = $ctx->hub->format; |
1344
|
484
|
|
|
|
|
1419
|
$ctx->release; |
1345
|
484
|
50
|
33
|
|
|
2431
|
return unless $format && $format->isa('Test2::Formatter::TAP'); |
1346
|
|
|
|
|
|
|
|
1347
|
484
|
100
|
|
|
|
1449
|
$format->handles->[Test2::Formatter::TAP::OUT_ERR()] = $self->_new_fh($fh) |
1348
|
|
|
|
|
|
|
if defined $fh; |
1349
|
|
|
|
|
|
|
|
1350
|
484
|
|
|
|
|
1101
|
return $format->handles->[Test2::Formatter::TAP::OUT_ERR()]; |
1351
|
|
|
|
|
|
|
} |
1352
|
|
|
|
|
|
|
|
1353
|
|
|
|
|
|
|
sub todo_output { |
1354
|
482
|
|
|
482
|
1
|
1166
|
my( $self, $fh ) = @_; |
1355
|
|
|
|
|
|
|
|
1356
|
482
|
|
|
|
|
1096
|
my $ctx = $self->ctx; |
1357
|
482
|
|
|
|
|
1541
|
my $format = $ctx->hub->format; |
1358
|
482
|
|
|
|
|
1478
|
$ctx->release; |
1359
|
482
|
50
|
33
|
|
|
2521
|
return unless $format && $format->isa('Test::Builder::Formatter'); |
1360
|
|
|
|
|
|
|
|
1361
|
482
|
100
|
|
|
|
1399
|
$format->handles->[Test::Builder::Formatter::OUT_TODO()] = $self->_new_fh($fh) |
1362
|
|
|
|
|
|
|
if defined $fh; |
1363
|
|
|
|
|
|
|
|
1364
|
482
|
|
|
|
|
1199
|
return $format->handles->[Test::Builder::Formatter::OUT_TODO()]; |
1365
|
|
|
|
|
|
|
} |
1366
|
|
|
|
|
|
|
|
1367
|
|
|
|
|
|
|
sub _new_fh { |
1368
|
1157
|
|
|
1157
|
|
4696
|
my $self = shift; |
1369
|
1157
|
|
|
|
|
1842
|
my($file_or_fh) = shift; |
1370
|
|
|
|
|
|
|
|
1371
|
1157
|
|
|
|
|
1582
|
my $fh; |
1372
|
1157
|
100
|
|
|
|
2515
|
if( $self->is_fh($file_or_fh) ) { |
|
|
100
|
|
|
|
|
|
1373
|
986
|
|
|
|
|
1546
|
$fh = $file_or_fh; |
1374
|
|
|
|
|
|
|
} |
1375
|
|
|
|
|
|
|
elsif( ref $file_or_fh eq 'SCALAR' ) { |
1376
|
|
|
|
|
|
|
# Scalar refs as filehandles was added in 5.8. |
1377
|
170
|
50
|
|
|
|
408
|
if( $] >= 5.008 ) { |
1378
|
170
|
50
|
|
|
|
1840
|
open $fh, ">>", $file_or_fh |
1379
|
|
|
|
|
|
|
or $self->croak("Can't open scalar ref $file_or_fh: $!"); |
1380
|
|
|
|
|
|
|
} |
1381
|
|
|
|
|
|
|
# Emulate scalar ref filehandles with a tie. |
1382
|
|
|
|
|
|
|
else { |
1383
|
0
|
0
|
|
|
|
0
|
$fh = Test::Builder::IO::Scalar->new($file_or_fh) |
1384
|
|
|
|
|
|
|
or $self->croak("Can't tie scalar ref $file_or_fh"); |
1385
|
|
|
|
|
|
|
} |
1386
|
|
|
|
|
|
|
} |
1387
|
|
|
|
|
|
|
else { |
1388
|
1
|
50
|
|
|
|
111
|
open $fh, ">", $file_or_fh |
1389
|
|
|
|
|
|
|
or $self->croak("Can't open test output log $file_or_fh: $!"); |
1390
|
1
|
|
|
|
|
13
|
_autoflush($fh); |
1391
|
|
|
|
|
|
|
} |
1392
|
|
|
|
|
|
|
|
1393
|
1157
|
|
|
|
|
18743
|
return $fh; |
1394
|
|
|
|
|
|
|
} |
1395
|
|
|
|
|
|
|
|
1396
|
|
|
|
|
|
|
sub _autoflush { |
1397
|
1
|
|
|
1
|
|
10
|
my($fh) = shift; |
1398
|
1
|
|
|
|
|
5
|
my $old_fh = select $fh; |
1399
|
1
|
|
|
|
|
3
|
$| = 1; |
1400
|
1
|
|
|
|
|
3
|
select $old_fh; |
1401
|
|
|
|
|
|
|
|
1402
|
1
|
|
|
|
|
3
|
return; |
1403
|
|
|
|
|
|
|
} |
1404
|
|
|
|
|
|
|
|
1405
|
|
|
|
|
|
|
|
1406
|
|
|
|
|
|
|
sub reset_outputs { |
1407
|
221
|
|
|
221
|
1
|
606
|
my $self = shift; |
1408
|
|
|
|
|
|
|
|
1409
|
221
|
|
|
|
|
813
|
my $ctx = $self->ctx; |
1410
|
221
|
|
|
|
|
1144
|
my $format = $ctx->hub->format; |
1411
|
221
|
|
|
|
|
958
|
$ctx->release; |
1412
|
221
|
100
|
66
|
|
|
1689
|
return unless $format && $format->isa('Test2::Formatter::TAP'); |
1413
|
219
|
50
|
|
|
|
912
|
$format->set_handles([@{$self->{Orig_Handles}}]) if $self->{Orig_Handles}; |
|
219
|
|
|
|
|
1710
|
|
1414
|
|
|
|
|
|
|
|
1415
|
219
|
|
|
|
|
774
|
return; |
1416
|
|
|
|
|
|
|
} |
1417
|
|
|
|
|
|
|
|
1418
|
|
|
|
|
|
|
|
1419
|
|
|
|
|
|
|
sub carp { |
1420
|
1
|
|
|
1
|
1
|
22
|
my $self = shift; |
1421
|
1
|
|
|
|
|
4
|
my $ctx = $self->ctx; |
1422
|
1
|
|
|
|
|
8
|
$ctx->alert(join "", @_); |
1423
|
1
|
|
|
|
|
10
|
$ctx->release; |
1424
|
|
|
|
|
|
|
} |
1425
|
|
|
|
|
|
|
|
1426
|
|
|
|
|
|
|
sub croak { |
1427
|
7
|
|
|
7
|
1
|
29
|
my $self = shift; |
1428
|
7
|
|
|
|
|
20
|
my $ctx = $self->ctx; |
1429
|
7
|
|
|
|
|
47
|
$ctx->throw(join "", @_); |
1430
|
0
|
|
|
|
|
0
|
$ctx->release; |
1431
|
|
|
|
|
|
|
} |
1432
|
|
|
|
|
|
|
|
1433
|
|
|
|
|
|
|
|
1434
|
|
|
|
|
|
|
sub current_test { |
1435
|
506
|
|
|
506
|
1
|
1154
|
my( $self, $num ) = @_; |
1436
|
|
|
|
|
|
|
|
1437
|
506
|
|
|
|
|
1433
|
my $ctx = $self->ctx; |
1438
|
506
|
|
|
|
|
1706
|
my $hub = $ctx->hub; |
1439
|
|
|
|
|
|
|
|
1440
|
506
|
100
|
|
|
|
1199
|
if( defined $num ) { |
1441
|
307
|
|
|
|
|
960
|
$hub->set_count($num); |
1442
|
|
|
|
|
|
|
|
1443
|
307
|
50
|
|
|
|
779
|
unless ($self->{no_log_results}) { |
1444
|
|
|
|
|
|
|
# If the test counter is being pushed forward fill in the details. |
1445
|
307
|
|
|
|
|
654
|
my $test_results = $ctx->hub->meta(__PACKAGE__, {})->{Test_Results}; |
1446
|
307
|
100
|
|
|
|
1030
|
if ($num > @$test_results) { |
|
|
100
|
|
|
|
|
|
1447
|
136
|
100
|
|
|
|
401
|
my $start = @$test_results ? @$test_results : 0; |
1448
|
136
|
|
|
|
|
411
|
for ($start .. $num - 1) { |
1449
|
4528
|
|
|
|
|
11628
|
$test_results->[$_] = { |
1450
|
|
|
|
|
|
|
'ok' => 1, |
1451
|
|
|
|
|
|
|
actual_ok => undef, |
1452
|
|
|
|
|
|
|
reason => 'incrementing test number', |
1453
|
|
|
|
|
|
|
type => 'unknown', |
1454
|
|
|
|
|
|
|
name => undef |
1455
|
|
|
|
|
|
|
}; |
1456
|
|
|
|
|
|
|
} |
1457
|
|
|
|
|
|
|
} |
1458
|
|
|
|
|
|
|
# If backward, wipe history. Its their funeral. |
1459
|
|
|
|
|
|
|
elsif ($num < @$test_results) { |
1460
|
147
|
|
|
|
|
261
|
$#{$test_results} = $num - 1; |
|
147
|
|
|
|
|
2208
|
|
1461
|
|
|
|
|
|
|
} |
1462
|
|
|
|
|
|
|
} |
1463
|
|
|
|
|
|
|
} |
1464
|
506
|
|
|
|
|
1556
|
return release $ctx, $hub->count; |
1465
|
|
|
|
|
|
|
} |
1466
|
|
|
|
|
|
|
|
1467
|
|
|
|
|
|
|
|
1468
|
|
|
|
|
|
|
sub is_passing { |
1469
|
411
|
|
|
411
|
1
|
799
|
my $self = shift; |
1470
|
|
|
|
|
|
|
|
1471
|
411
|
|
|
|
|
846
|
my $ctx = $self->ctx; |
1472
|
411
|
|
|
|
|
1307
|
my $hub = $ctx->hub; |
1473
|
|
|
|
|
|
|
|
1474
|
411
|
100
|
|
|
|
953
|
if( @_ ) { |
1475
|
264
|
|
|
|
|
460
|
my ($bool) = @_; |
1476
|
264
|
100
|
|
|
|
932
|
$hub->set_failed(0) if $bool; |
1477
|
264
|
|
|
|
|
709
|
$hub->is_passing($bool); |
1478
|
|
|
|
|
|
|
} |
1479
|
|
|
|
|
|
|
|
1480
|
411
|
|
|
|
|
1035
|
return release $ctx, $hub->is_passing; |
1481
|
|
|
|
|
|
|
} |
1482
|
|
|
|
|
|
|
|
1483
|
|
|
|
|
|
|
|
1484
|
|
|
|
|
|
|
sub summary { |
1485
|
6
|
|
|
6
|
1
|
38
|
my($self) = shift; |
1486
|
|
|
|
|
|
|
|
1487
|
6
|
50
|
|
|
|
24
|
return if $self->{no_log_results}; |
1488
|
|
|
|
|
|
|
|
1489
|
6
|
|
|
|
|
18
|
my $ctx = $self->ctx; |
1490
|
6
|
|
|
|
|
35
|
my $data = $ctx->hub->meta(__PACKAGE__, {})->{Test_Results}; |
1491
|
6
|
|
|
|
|
28
|
$ctx->release; |
1492
|
6
|
50
|
|
|
|
18
|
return map { $_ ? $_->{'ok'} : () } @$data; |
|
14
|
|
|
|
|
46
|
|
1493
|
|
|
|
|
|
|
} |
1494
|
|
|
|
|
|
|
|
1495
|
|
|
|
|
|
|
|
1496
|
|
|
|
|
|
|
sub details { |
1497
|
5
|
|
|
5
|
1
|
21
|
my $self = shift; |
1498
|
|
|
|
|
|
|
|
1499
|
5
|
100
|
|
|
|
24
|
return if $self->{no_log_results}; |
1500
|
|
|
|
|
|
|
|
1501
|
3
|
|
|
|
|
9
|
my $ctx = $self->ctx; |
1502
|
3
|
|
|
|
|
11
|
my $data = $ctx->hub->meta(__PACKAGE__, {})->{Test_Results}; |
1503
|
3
|
|
|
|
|
11
|
$ctx->release; |
1504
|
3
|
|
|
|
|
11
|
return @$data; |
1505
|
|
|
|
|
|
|
} |
1506
|
|
|
|
|
|
|
|
1507
|
|
|
|
|
|
|
|
1508
|
|
|
|
|
|
|
sub find_TODO { |
1509
|
298
|
|
|
298
|
1
|
731
|
my( $self, $pack, $set, $new_value ) = @_; |
1510
|
|
|
|
|
|
|
|
1511
|
298
|
|
|
|
|
693
|
my $ctx = $self->ctx; |
1512
|
|
|
|
|
|
|
|
1513
|
298
|
|
33
|
|
|
1309
|
$pack ||= $ctx->trace->package || $self->exported_to; |
|
|
|
66
|
|
|
|
|
1514
|
298
|
|
|
|
|
1054
|
$ctx->release; |
1515
|
|
|
|
|
|
|
|
1516
|
298
|
50
|
|
|
|
757
|
return unless $pack; |
1517
|
|
|
|
|
|
|
|
1518
|
162
|
|
|
164
|
|
1482
|
no strict 'refs'; ## no critic |
|
162
|
|
|
|
|
445
|
|
|
162
|
|
|
|
|
6431
|
|
1519
|
162
|
|
|
164
|
|
1092
|
no warnings 'once'; |
|
162
|
|
|
|
|
415
|
|
|
162
|
|
|
|
|
27857
|
|
1520
|
298
|
|
|
|
|
480
|
my $old_value = ${ $pack . '::TODO' }; |
|
298
|
|
|
|
|
930
|
|
1521
|
298
|
50
|
|
|
|
669
|
$set and ${ $pack . '::TODO' } = $new_value; |
|
298
|
|
|
|
|
624
|
|
1522
|
298
|
|
|
|
|
990
|
return $old_value; |
1523
|
|
|
|
|
|
|
} |
1524
|
|
|
|
|
|
|
|
1525
|
|
|
|
|
|
|
sub todo { |
1526
|
29
|
|
|
29
|
1
|
99
|
my( $self, $pack ) = @_; |
1527
|
|
|
|
|
|
|
|
1528
|
29
|
|
|
|
|
121
|
local $Level = $Level + 1; |
1529
|
29
|
|
|
|
|
74
|
my $ctx = $self->ctx; |
1530
|
29
|
|
|
|
|
118
|
$ctx->release; |
1531
|
|
|
|
|
|
|
|
1532
|
29
|
|
|
|
|
89
|
my $meta = $ctx->hub->meta(__PACKAGE__, {todo => []})->{todo}; |
1533
|
29
|
100
|
100
|
|
|
152
|
return $meta->[-1]->[1] if $meta && @$meta; |
1534
|
|
|
|
|
|
|
|
1535
|
24
|
|
33
|
|
|
162
|
$pack ||= $ctx->trace->package; |
1536
|
|
|
|
|
|
|
|
1537
|
24
|
50
|
|
|
|
66
|
return unless $pack; |
1538
|
|
|
|
|
|
|
|
1539
|
162
|
|
|
164
|
|
1277
|
no strict 'refs'; ## no critic |
|
162
|
|
|
|
|
380
|
|
|
162
|
|
|
|
|
6148
|
|
1540
|
162
|
|
|
164
|
|
1022
|
no warnings 'once'; |
|
162
|
|
|
|
|
449
|
|
|
162
|
|
|
|
|
25200
|
|
1541
|
24
|
|
|
|
|
38
|
return ${ $pack . '::TODO' }; |
|
24
|
|
|
|
|
130
|
|
1542
|
|
|
|
|
|
|
} |
1543
|
|
|
|
|
|
|
|
1544
|
|
|
|
|
|
|
sub in_todo { |
1545
|
478
|
|
|
478
|
1
|
756
|
my $self = shift; |
1546
|
|
|
|
|
|
|
|
1547
|
478
|
|
|
|
|
924
|
local $Level = $Level + 1; |
1548
|
478
|
|
|
|
|
1016
|
my $ctx = $self->ctx; |
1549
|
478
|
|
|
|
|
2203
|
$ctx->release; |
1550
|
|
|
|
|
|
|
|
1551
|
478
|
|
|
|
|
1547
|
my $meta = $ctx->hub->meta(__PACKAGE__, {todo => []})->{todo}; |
1552
|
478
|
100
|
100
|
|
|
2159
|
return 1 if $meta && @$meta; |
1553
|
|
|
|
|
|
|
|
1554
|
314
|
|
50
|
|
|
817
|
my $pack = $ctx->trace->package || return 0; |
1555
|
|
|
|
|
|
|
|
1556
|
162
|
|
|
163
|
|
1258
|
no strict 'refs'; ## no critic |
|
162
|
|
|
|
|
383
|
|
|
162
|
|
|
|
|
5924
|
|
1557
|
162
|
|
|
163
|
|
1037
|
no warnings 'once'; |
|
162
|
|
|
|
|
378
|
|
|
162
|
|
|
|
|
219036
|
|
1558
|
314
|
|
|
|
|
597
|
my $todo = ${ $pack . '::TODO' }; |
|
314
|
|
|
|
|
954
|
|
1559
|
|
|
|
|
|
|
|
1560
|
314
|
100
|
|
|
|
1198
|
return 0 unless defined $todo; |
1561
|
89
|
100
|
|
|
|
239
|
return 0 if "$todo" eq ''; |
1562
|
87
|
|
|
|
|
309
|
return 1; |
1563
|
|
|
|
|
|
|
} |
1564
|
|
|
|
|
|
|
|
1565
|
|
|
|
|
|
|
sub todo_start { |
1566
|
90
|
|
|
90
|
1
|
199
|
my $self = shift; |
1567
|
90
|
100
|
|
|
|
275
|
my $message = @_ ? shift : ''; |
1568
|
|
|
|
|
|
|
|
1569
|
90
|
|
|
|
|
222
|
my $ctx = $self->ctx; |
1570
|
|
|
|
|
|
|
|
1571
|
90
|
|
|
|
|
322
|
my $hub = $ctx->hub; |
1572
|
|
|
|
|
|
|
my $filter = $hub->pre_filter(sub { |
1573
|
729
|
|
|
729
|
|
1294
|
my ($active_hub, $e) = @_; |
1574
|
|
|
|
|
|
|
|
1575
|
|
|
|
|
|
|
# Turn a diag into a todo diag |
1576
|
729
|
100
|
|
|
|
2633
|
return Test::Builder::TodoDiag->new(%$e) if ref($e) eq 'Test2::Event::Diag'; |
1577
|
|
|
|
|
|
|
|
1578
|
|
|
|
|
|
|
# Set todo on ok's |
1579
|
435
|
100
|
100
|
|
|
1987
|
if ($hub == $active_hub && $e->isa('Test2::Event::Ok')) { |
1580
|
176
|
|
|
|
|
638
|
$e->set_todo($message); |
1581
|
176
|
|
|
|
|
563
|
$e->set_effective_pass(1); |
1582
|
|
|
|
|
|
|
|
1583
|
176
|
50
|
|
|
|
509
|
if (my $result = $e->get_meta(__PACKAGE__)) { |
1584
|
176
|
|
100
|
|
|
774
|
$result->{reason} ||= $message; |
1585
|
176
|
|
100
|
|
|
650
|
$result->{type} ||= 'todo'; |
1586
|
176
|
|
|
|
|
304
|
$result->{ok} = 1; |
1587
|
|
|
|
|
|
|
} |
1588
|
|
|
|
|
|
|
} |
1589
|
|
|
|
|
|
|
|
1590
|
435
|
|
|
|
|
917
|
return $e; |
1591
|
90
|
|
|
|
|
684
|
}, inherit => 1); |
1592
|
|
|
|
|
|
|
|
1593
|
90
|
|
|
|
|
181
|
push @{$ctx->hub->meta(__PACKAGE__, {todo => []})->{todo}} => [$filter, $message]; |
|
90
|
|
|
|
|
210
|
|
1594
|
|
|
|
|
|
|
|
1595
|
90
|
|
|
|
|
380
|
$ctx->release; |
1596
|
|
|
|
|
|
|
|
1597
|
90
|
|
|
|
|
268
|
return; |
1598
|
|
|
|
|
|
|
} |
1599
|
|
|
|
|
|
|
|
1600
|
|
|
|
|
|
|
sub todo_end { |
1601
|
91
|
|
|
91
|
1
|
189
|
my $self = shift; |
1602
|
|
|
|
|
|
|
|
1603
|
91
|
|
|
|
|
237
|
my $ctx = $self->ctx; |
1604
|
|
|
|
|
|
|
|
1605
|
91
|
|
|
|
|
209
|
my $set = pop @{$ctx->hub->meta(__PACKAGE__, {todo => []})->{todo}}; |
|
91
|
|
|
|
|
303
|
|
1606
|
|
|
|
|
|
|
|
1607
|
91
|
100
|
|
|
|
294
|
$ctx->throw('todo_end() called without todo_start()') unless $set; |
1608
|
|
|
|
|
|
|
|
1609
|
90
|
|
|
|
|
211
|
$ctx->hub->pre_unfilter($set->[0]); |
1610
|
|
|
|
|
|
|
|
1611
|
90
|
|
|
|
|
326
|
$ctx->release; |
1612
|
|
|
|
|
|
|
|
1613
|
90
|
|
|
|
|
730
|
return; |
1614
|
|
|
|
|
|
|
} |
1615
|
|
|
|
|
|
|
|
1616
|
|
|
|
|
|
|
|
1617
|
|
|
|
|
|
|
sub caller { ## no critic (Subroutines::ProhibitBuiltinHomonyms) |
1618
|
340
|
|
|
340
|
1
|
1816
|
my( $self ) = @_; |
1619
|
|
|
|
|
|
|
|
1620
|
340
|
|
|
|
|
936
|
my $ctx = $self->ctx; |
1621
|
|
|
|
|
|
|
|
1622
|
340
|
|
|
|
|
5934
|
my $trace = $ctx->trace; |
1623
|
340
|
|
|
|
|
4230
|
$ctx->release; |
1624
|
340
|
50
|
|
|
|
5252
|
return wantarray ? $trace->call : $trace->package; |
1625
|
|
|
|
|
|
|
} |
1626
|
|
|
|
|
|
|
|
1627
|
|
|
|
|
|
|
|
1628
|
|
|
|
|
|
|
sub _try { |
1629
|
546
|
|
|
546
|
|
1288
|
my( $self, $code, %opts ) = @_; |
1630
|
|
|
|
|
|
|
|
1631
|
546
|
|
|
|
|
834
|
my $error; |
1632
|
|
|
|
|
|
|
my $return; |
1633
|
|
|
|
|
|
|
{ |
1634
|
546
|
|
|
|
|
736
|
local $!; # eval can mess up $! |
|
546
|
|
|
|
|
1504
|
|
1635
|
546
|
|
|
|
|
745
|
local $@; # don't set $@ in the test |
1636
|
546
|
|
|
|
|
1440
|
local $SIG{__DIE__}; # don't trip an outside DIE handler. |
1637
|
546
|
|
|
|
|
880
|
$return = eval { $code->() }; |
|
546
|
|
|
|
|
926
|
|
1638
|
546
|
|
|
|
|
2177
|
$error = $@; |
1639
|
|
|
|
|
|
|
} |
1640
|
|
|
|
|
|
|
|
1641
|
546
|
100
|
100
|
|
|
1930
|
die $error if $error and $opts{die_on_fail}; |
1642
|
|
|
|
|
|
|
|
1643
|
545
|
100
|
|
|
|
2951
|
return wantarray ? ( $return, $error ) : $return; |
1644
|
|
|
|
|
|
|
} |
1645
|
|
|
|
|
|
|
|
1646
|
|
|
|
|
|
|
sub _ending { |
1647
|
149
|
|
|
149
|
|
808
|
my $self = shift; |
1648
|
149
|
|
|
|
|
521
|
my ($ctx, $real_exit_code, $new) = @_; |
1649
|
|
|
|
|
|
|
|
1650
|
149
|
100
|
|
|
|
916
|
unless ($ctx) { |
1651
|
9
|
|
|
|
|
32
|
my $octx = $self->ctx; |
1652
|
9
|
|
|
|
|
55
|
$ctx = $octx->snapshot; |
1653
|
9
|
|
|
|
|
31
|
$octx->release; |
1654
|
|
|
|
|
|
|
} |
1655
|
|
|
|
|
|
|
|
1656
|
149
|
50
|
|
|
|
929
|
return if $ctx->hub->no_ending; |
1657
|
149
|
50
|
|
|
|
882
|
return if $ctx->hub->meta(__PACKAGE__, {})->{Ending}++; |
1658
|
|
|
|
|
|
|
|
1659
|
|
|
|
|
|
|
# Don't bother with an ending if this is a forked copy. Only the parent |
1660
|
|
|
|
|
|
|
# should do the ending. |
1661
|
149
|
50
|
|
|
|
1188
|
return unless $self->{Original_Pid} == $$; |
1662
|
|
|
|
|
|
|
|
1663
|
149
|
|
|
|
|
687
|
my $hub = $ctx->hub; |
1664
|
149
|
50
|
|
|
|
768
|
return if $hub->bailed_out; |
1665
|
|
|
|
|
|
|
|
1666
|
149
|
|
|
|
|
788
|
my $plan = $hub->plan; |
1667
|
149
|
|
|
|
|
643
|
my $count = $hub->count; |
1668
|
149
|
|
|
|
|
734
|
my $failed = $hub->failed; |
1669
|
149
|
|
|
|
|
531
|
my $passed = $hub->is_passing; |
1670
|
149
|
100
|
100
|
|
|
939
|
return unless $plan || $count || $failed; |
|
|
|
66
|
|
|
|
|
1671
|
|
|
|
|
|
|
|
1672
|
|
|
|
|
|
|
# Ran tests but never declared a plan or hit done_testing |
1673
|
146
|
100
|
66
|
|
|
626
|
if( !$hub->plan and $hub->count ) { |
1674
|
1
|
|
|
|
|
12
|
$self->diag("Tests were run but no plan was declared and done_testing() was not seen."); |
1675
|
|
|
|
|
|
|
|
1676
|
1
|
50
|
|
|
|
4
|
if($real_exit_code) { |
1677
|
0
|
|
|
|
|
0
|
$self->diag(<<"FAIL"); |
1678
|
|
|
|
|
|
|
Looks like your test exited with $real_exit_code just after $count. |
1679
|
|
|
|
|
|
|
FAIL |
1680
|
0
|
|
0
|
|
|
0
|
$$new ||= $real_exit_code; |
1681
|
0
|
|
|
|
|
0
|
return; |
1682
|
|
|
|
|
|
|
} |
1683
|
|
|
|
|
|
|
|
1684
|
|
|
|
|
|
|
# But if the tests ran, handle exit code. |
1685
|
1
|
50
|
|
|
|
4
|
if($failed > 0) { |
1686
|
0
|
0
|
|
|
|
0
|
my $exit_code = $failed <= 254 ? $failed : 254; |
1687
|
0
|
|
0
|
|
|
0
|
$$new ||= $exit_code; |
1688
|
0
|
|
|
|
|
0
|
return; |
1689
|
|
|
|
|
|
|
} |
1690
|
|
|
|
|
|
|
|
1691
|
1
|
|
50
|
|
|
5
|
$$new ||= 254; |
1692
|
1
|
|
|
|
|
3
|
return; |
1693
|
|
|
|
|
|
|
} |
1694
|
|
|
|
|
|
|
|
1695
|
145
|
100
|
66
|
|
|
815
|
if ($real_exit_code && !$count) { |
1696
|
1
|
|
|
|
|
7
|
$self->diag("Looks like your test exited with $real_exit_code before it could output anything."); |
1697
|
1
|
|
33
|
|
|
3
|
$$new ||= $real_exit_code; |
1698
|
1
|
|
|
|
|
5
|
return; |
1699
|
|
|
|
|
|
|
} |
1700
|
|
|
|
|
|
|
|
1701
|
144
|
100
|
66
|
|
|
1223
|
return if $plan && "$plan" eq 'SKIP'; |
1702
|
|
|
|
|
|
|
|
1703
|
136
|
100
|
|
|
|
594
|
if (!$count) { |
1704
|
1
|
|
|
|
|
4
|
$self->diag('No tests run!'); |
1705
|
1
|
|
50
|
|
|
6
|
$$new ||= 255; |
1706
|
1
|
|
|
|
|
4
|
return; |
1707
|
|
|
|
|
|
|
} |
1708
|
|
|
|
|
|
|
|
1709
|
135
|
50
|
|
|
|
612
|
if ($real_exit_code) { |
1710
|
0
|
|
|
|
|
0
|
$self->diag(<<"FAIL"); |
1711
|
|
|
|
|
|
|
Looks like your test exited with $real_exit_code just after $count. |
1712
|
|
|
|
|
|
|
FAIL |
1713
|
0
|
|
0
|
|
|
0
|
$$new ||= $real_exit_code; |
1714
|
0
|
|
|
|
|
0
|
return; |
1715
|
|
|
|
|
|
|
} |
1716
|
|
|
|
|
|
|
|
1717
|
135
|
100
|
|
|
|
608
|
if ($plan eq 'NO PLAN') { |
1718
|
3
|
|
|
|
|
14
|
$ctx->plan( $count ); |
1719
|
3
|
|
|
|
|
16
|
$plan = $hub->plan; |
1720
|
|
|
|
|
|
|
} |
1721
|
|
|
|
|
|
|
|
1722
|
|
|
|
|
|
|
# Figure out if we passed or failed and print helpful messages. |
1723
|
135
|
|
|
|
|
423
|
my $num_extra = $count - $plan; |
1724
|
|
|
|
|
|
|
|
1725
|
135
|
100
|
|
|
|
986
|
if ($num_extra != 0) { |
1726
|
4
|
100
|
|
|
|
12
|
my $s = $plan == 1 ? '' : 's'; |
1727
|
4
|
|
|
|
|
27
|
$self->diag(<<"FAIL"); |
1728
|
|
|
|
|
|
|
Looks like you planned $plan test$s but ran $count. |
1729
|
|
|
|
|
|
|
FAIL |
1730
|
|
|
|
|
|
|
} |
1731
|
|
|
|
|
|
|
|
1732
|
135
|
100
|
|
|
|
540
|
if ($failed) { |
1733
|
7
|
100
|
|
|
|
31
|
my $s = $failed == 1 ? '' : 's'; |
1734
|
|
|
|
|
|
|
|
1735
|
7
|
100
|
|
|
|
23
|
my $qualifier = $num_extra == 0 ? '' : ' run'; |
1736
|
|
|
|
|
|
|
|
1737
|
7
|
|
|
|
|
63
|
$self->diag(<<"FAIL"); |
1738
|
|
|
|
|
|
|
Looks like you failed $failed test$s of $count$qualifier. |
1739
|
|
|
|
|
|
|
FAIL |
1740
|
|
|
|
|
|
|
} |
1741
|
|
|
|
|
|
|
|
1742
|
135
|
50
|
100
|
|
|
918
|
if (!$passed && !$failed && $count && !$num_extra) { |
|
|
|
66
|
|
|
|
|
|
|
|
66
|
|
|
|
|
1743
|
0
|
|
|
|
|
0
|
$ctx->diag(<<"FAIL"); |
1744
|
|
|
|
|
|
|
All assertions passed, but errors were encountered. |
1745
|
|
|
|
|
|
|
FAIL |
1746
|
|
|
|
|
|
|
} |
1747
|
|
|
|
|
|
|
|
1748
|
135
|
|
|
|
|
367
|
my $exit_code = 0; |
1749
|
135
|
100
|
|
|
|
982
|
if ($failed) { |
|
|
100
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
1750
|
7
|
50
|
|
|
|
55
|
$exit_code = $failed <= 254 ? $failed : 254; |
1751
|
|
|
|
|
|
|
} |
1752
|
|
|
|
|
|
|
elsif ($num_extra != 0) { |
1753
|
1
|
|
|
|
|
1
|
$exit_code = 255; |
1754
|
|
|
|
|
|
|
} |
1755
|
|
|
|
|
|
|
elsif (!$passed) { |
1756
|
0
|
|
|
|
|
0
|
$exit_code = 255; |
1757
|
|
|
|
|
|
|
} |
1758
|
|
|
|
|
|
|
|
1759
|
135
|
|
66
|
|
|
1225
|
$$new ||= $exit_code; |
1760
|
135
|
|
|
|
|
684
|
return; |
1761
|
|
|
|
|
|
|
} |
1762
|
|
|
|
|
|
|
|
1763
|
|
|
|
|
|
|
# Some things used this even though it was private... I am looking at you |
1764
|
|
|
|
|
|
|
# Test::Builder::Prefix... |
1765
|
|
|
|
|
|
|
sub _print_comment { |
1766
|
0
|
|
|
0
|
|
0
|
my( $self, $fh, @msgs ) = @_; |
1767
|
|
|
|
|
|
|
|
1768
|
0
|
0
|
|
|
|
0
|
return if $self->no_diag; |
1769
|
0
|
0
|
|
|
|
0
|
return unless @msgs; |
1770
|
|
|
|
|
|
|
|
1771
|
|
|
|
|
|
|
# Prevent printing headers when compiling (i.e. -c) |
1772
|
0
|
0
|
|
|
|
0
|
return if $^C; |
1773
|
|
|
|
|
|
|
|
1774
|
|
|
|
|
|
|
# Smash args together like print does. |
1775
|
|
|
|
|
|
|
# Convert undef to 'undef' so its readable. |
1776
|
0
|
0
|
|
|
|
0
|
my $msg = join '', map { defined($_) ? $_ : 'undef' } @msgs; |
|
0
|
|
|
|
|
0
|
|
1777
|
|
|
|
|
|
|
|
1778
|
|
|
|
|
|
|
# Escape the beginning, _print will take care of the rest. |
1779
|
0
|
|
|
|
|
0
|
$msg =~ s/^/# /; |
1780
|
|
|
|
|
|
|
|
1781
|
0
|
|
|
|
|
0
|
local( $\, $", $, ) = ( undef, ' ', '' ); |
1782
|
0
|
|
|
|
|
0
|
print $fh $msg; |
1783
|
|
|
|
|
|
|
|
1784
|
0
|
|
|
|
|
0
|
return 0; |
1785
|
|
|
|
|
|
|
} |
1786
|
|
|
|
|
|
|
|
1787
|
|
|
|
|
|
|
# This is used by Test::SharedFork to turn on IPC after the fact. Not |
1788
|
|
|
|
|
|
|
# documenting because I do not want it used. The method name is borrowed from |
1789
|
|
|
|
|
|
|
# Test::Builder 2 |
1790
|
|
|
|
|
|
|
# Once Test2 stuff goes stable this method will be removed and Test::SharedFork |
1791
|
|
|
|
|
|
|
# will be made smarter. |
1792
|
|
|
|
|
|
|
sub coordinate_forks { |
1793
|
0
|
|
|
0
|
0
|
0
|
my $self = shift; |
1794
|
|
|
|
|
|
|
|
1795
|
|
|
|
|
|
|
{ |
1796
|
0
|
|
|
|
|
0
|
local ($@, $!); |
|
0
|
|
|
|
|
0
|
|
1797
|
0
|
|
|
|
|
0
|
require Test2::IPC; |
1798
|
|
|
|
|
|
|
} |
1799
|
0
|
|
|
|
|
0
|
Test2::IPC->import; |
1800
|
0
|
|
|
|
|
0
|
Test2::API::test2_ipc_enable_polling(); |
1801
|
0
|
|
|
|
|
0
|
Test2::API::test2_load(); |
1802
|
0
|
|
|
|
|
0
|
my $ipc = Test2::IPC::apply_ipc($self->{Stack}); |
1803
|
0
|
|
|
|
|
0
|
$ipc->set_no_fatal(1); |
1804
|
0
|
|
|
|
|
0
|
Test2::API::test2_no_wait(1); |
1805
|
|
|
|
|
|
|
} |
1806
|
|
|
|
|
|
|
|
1807
|
2
|
|
|
2
|
1
|
13
|
sub no_log_results { $_[0]->{no_log_results} = 1 } |
1808
|
|
|
|
|
|
|
|
1809
|
|
|
|
|
|
|
1; |
1810
|
|
|
|
|
|
|
|
1811
|
|
|
|
|
|
|
__END__ |