line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Test2::Tools::Defer; |
2
|
155
|
|
|
155
|
|
75116
|
use strict; |
|
155
|
|
|
|
|
338
|
|
|
155
|
|
|
|
|
4108
|
|
3
|
155
|
|
|
155
|
|
694
|
use warnings; |
|
155
|
|
|
|
|
304
|
|
|
155
|
|
|
|
|
5678
|
|
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
our $VERSION = '0.000153'; |
6
|
|
|
|
|
|
|
|
7
|
155
|
|
|
155
|
|
794
|
use Carp qw/croak/; |
|
155
|
|
|
|
|
305
|
|
|
155
|
|
|
|
|
6766
|
|
8
|
|
|
|
|
|
|
|
9
|
155
|
|
|
155
|
|
1772
|
use Test2::Util qw/get_tid/; |
|
155
|
|
|
|
|
21381
|
|
|
155
|
|
|
|
|
7295
|
|
10
|
155
|
|
|
|
|
11066
|
use Test2::API qw{ |
11
|
|
|
|
|
|
|
test2_add_callback_exit |
12
|
|
|
|
|
|
|
test2_pid test2_tid |
13
|
155
|
|
|
155
|
|
2057
|
}; |
|
155
|
|
|
|
|
109840
|
|
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
our @EXPORT = qw/def do_def/; |
16
|
155
|
|
|
155
|
|
1136
|
use base 'Exporter'; |
|
155
|
|
|
|
|
333
|
|
|
155
|
|
|
|
|
87086
|
|
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
my %TODO; |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
sub def { |
21
|
54
|
|
|
54
|
1
|
617
|
my ($func, @args) = @_; |
22
|
|
|
|
|
|
|
|
23
|
54
|
|
|
|
|
332
|
my @caller = caller(0); |
24
|
|
|
|
|
|
|
|
25
|
54
|
|
100
|
|
|
211
|
$TODO{$caller[0]} ||= []; |
26
|
54
|
|
|
|
|
67
|
push @{$TODO{$caller[0]}} => [$func, \@args, \@caller]; |
|
54
|
|
|
|
|
377
|
|
27
|
|
|
|
|
|
|
} |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
sub do_def { |
30
|
11
|
|
|
11
|
1
|
27719
|
my $for = caller; |
31
|
11
|
100
|
|
|
|
234
|
my $tests = delete $TODO{$for} or croak "No tests to run!"; |
32
|
|
|
|
|
|
|
|
33
|
10
|
|
|
|
|
39
|
for my $test (@$tests) { |
34
|
51
|
|
|
|
|
811
|
my ($func, $args, $caller) = @$test; |
35
|
|
|
|
|
|
|
|
36
|
51
|
|
|
|
|
115
|
my ($pkg, $file, $line) = @$caller; |
37
|
|
|
|
|
|
|
|
38
|
51
|
|
|
|
|
194
|
chomp(my $eval = <<" EOT"); |
39
|
|
|
|
|
|
|
package $pkg; |
40
|
|
|
|
|
|
|
# line $line "(eval in Test2::Tools::Defer) $file" |
41
|
|
|
|
|
|
|
\&$func(\@\$args); |
42
|
|
|
|
|
|
|
1; |
43
|
|
|
|
|
|
|
EOT |
44
|
|
|
|
|
|
|
|
45
|
51
|
100
|
|
|
|
3770
|
eval $eval and next; |
46
|
1
|
|
|
|
|
17
|
chomp(my $error = $@); |
47
|
|
|
|
|
|
|
|
48
|
1
|
|
|
|
|
495
|
require Data::Dumper; |
49
|
1
|
|
|
|
|
5126
|
chomp(my $td = Data::Dumper::Dumper($args)); |
50
|
1
|
|
|
|
|
55
|
$td =~ s/^\$VAR1 =/\$args: /; |
51
|
1
|
|
|
|
|
15
|
die <<" EOT"; |
52
|
|
|
|
|
|
|
Exception: $error |
53
|
|
|
|
|
|
|
--eval-- |
54
|
|
|
|
|
|
|
$eval |
55
|
|
|
|
|
|
|
-------- |
56
|
|
|
|
|
|
|
Tool: $func |
57
|
|
|
|
|
|
|
Caller: $caller->[0], $caller->[1], $caller->[2] |
58
|
|
|
|
|
|
|
$td |
59
|
|
|
|
|
|
|
EOT |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
|
62
|
9
|
|
|
|
|
268
|
return; |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
sub _verify { |
66
|
104
|
|
|
104
|
|
3834
|
my ($context, $exit, $new_exit) = @_; |
67
|
|
|
|
|
|
|
|
68
|
104
|
|
|
|
|
295
|
my $not_ok = 0; |
69
|
104
|
|
|
|
|
1477
|
for my $pkg (keys %TODO) { |
70
|
3
|
|
|
|
|
7
|
my $tests = delete $TODO{$pkg}; |
71
|
3
|
|
|
|
|
5
|
my $caller = $tests->[0]->[-1]; |
72
|
3
|
100
|
|
|
|
11
|
print STDOUT "not ok - deferred tests were not run!\n" unless $not_ok++; |
73
|
3
|
|
|
|
|
8
|
print STDERR "# '$pkg' has deferred tests that were never run!\n"; |
74
|
3
|
|
|
|
|
8
|
print STDERR "# $caller->[1] at line $caller->[2]\n"; |
75
|
3
|
|
100
|
|
|
17
|
$$new_exit ||= 255; |
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
test2_add_callback_exit(\&_verify); |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
1; |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
__END__ |