line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Test2::Tools::Basic; |
2
|
172
|
|
|
172
|
|
470062
|
use strict; |
|
172
|
|
|
|
|
422
|
|
|
172
|
|
|
|
|
4867
|
|
3
|
172
|
|
|
172
|
|
811
|
use warnings; |
|
172
|
|
|
|
|
350
|
|
|
172
|
|
|
|
|
6890
|
|
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
our $VERSION = '0.000153'; |
6
|
|
|
|
|
|
|
|
7
|
172
|
|
|
172
|
|
974
|
use Carp qw/croak/; |
|
172
|
|
|
|
|
518
|
|
|
172
|
|
|
|
|
8267
|
|
8
|
172
|
|
|
172
|
|
2179
|
use Test2::API qw/context/; |
|
172
|
|
|
|
|
142815
|
|
|
172
|
|
|
|
|
12860
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
our @EXPORT = qw{ |
11
|
|
|
|
|
|
|
ok pass fail diag note todo skip |
12
|
|
|
|
|
|
|
plan skip_all done_testing bail_out |
13
|
|
|
|
|
|
|
}; |
14
|
172
|
|
|
172
|
|
1169
|
use base 'Exporter'; |
|
172
|
|
|
|
|
365
|
|
|
172
|
|
|
|
|
87940
|
|
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
sub ok($;$@) { |
17
|
1698
|
|
|
1698
|
1
|
3343191
|
my ($bool, $name, @diag) = @_; |
18
|
1698
|
|
|
|
|
5782
|
my $ctx = context(); |
19
|
1698
|
|
|
|
|
406515
|
$ctx->ok($bool, $name, \@diag); |
20
|
1698
|
|
|
|
|
196438
|
$ctx->release; |
21
|
1696
|
100
|
|
|
|
50088
|
return $bool ? 1 : 0; |
22
|
|
|
|
|
|
|
} |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
sub pass { |
25
|
10
|
|
|
10
|
1
|
1039
|
my ($name) = @_; |
26
|
10
|
|
|
|
|
46
|
my $ctx = context(); |
27
|
10
|
|
|
|
|
1263
|
$ctx->ok(1, $name); |
28
|
10
|
|
|
|
|
4105
|
$ctx->release; |
29
|
10
|
|
|
|
|
356
|
return 1; |
30
|
|
|
|
|
|
|
} |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
sub fail { |
33
|
2
|
|
|
2
|
1
|
26
|
my ($name, @diag) = @_; |
34
|
2
|
|
|
|
|
5
|
my $ctx = context(); |
35
|
2
|
|
|
|
|
147
|
$ctx->ok(0, $name, \@diag); |
36
|
2
|
|
|
|
|
868
|
$ctx->release; |
37
|
2
|
|
|
|
|
43
|
return 0; |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
sub diag { |
41
|
12
|
|
|
12
|
1
|
25112
|
my $ctx = context(); |
42
|
12
|
|
|
|
|
6470
|
$ctx->diag( join '', grep { defined $_ } @_ ); |
|
14
|
|
|
|
|
81
|
|
43
|
12
|
|
|
|
|
3027
|
$ctx->release; |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
sub note { |
47
|
662
|
|
|
662
|
1
|
6209
|
my $ctx = context(); |
48
|
662
|
|
|
|
|
174222
|
$ctx->note( join '', grep { defined $_ } @_ ); |
|
664
|
|
|
|
|
4630
|
|
49
|
662
|
|
|
|
|
46343
|
$ctx->release; |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
sub todo { |
53
|
53
|
|
|
53
|
1
|
1541
|
my $reason = shift; |
54
|
53
|
|
|
|
|
126
|
my $code = shift; |
55
|
|
|
|
|
|
|
|
56
|
53
|
100
|
|
|
|
3336
|
require Test2::Todo unless $INC{'Test2/Todo.pm'}; |
57
|
53
|
|
|
|
|
423
|
my $todo = Test2::Todo->new(reason => $reason); |
58
|
|
|
|
|
|
|
|
59
|
53
|
100
|
|
|
|
1516
|
return $code->() if $code; |
60
|
|
|
|
|
|
|
|
61
|
49
|
50
|
|
|
|
138
|
croak "Cannot use todo() in a void context without a codeblock" |
62
|
|
|
|
|
|
|
unless defined wantarray; |
63
|
|
|
|
|
|
|
|
64
|
49
|
|
|
|
|
171
|
return $todo; |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
sub skip { |
68
|
2
|
|
|
2
|
1
|
51
|
my ($why, $num) = @_; |
69
|
2
|
|
50
|
|
|
9
|
$num ||= 1; |
70
|
2
|
|
|
|
|
9
|
my $ctx = context(); |
71
|
2
|
|
|
|
|
161
|
$ctx->skip("skipped test", $why) for 1 .. $num; |
72
|
2
|
|
|
|
|
1737
|
$ctx->release; |
73
|
172
|
|
|
172
|
|
1343
|
no warnings 'exiting'; |
|
172
|
|
|
|
|
524
|
|
|
172
|
|
|
|
|
52934
|
|
74
|
2
|
|
|
|
|
51
|
last SKIP; |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
sub plan { |
78
|
9
|
|
|
9
|
1
|
3075
|
my $plan = shift; |
79
|
9
|
|
|
|
|
31
|
my $ctx = context(); |
80
|
|
|
|
|
|
|
|
81
|
9
|
100
|
66
|
|
|
913
|
if ($plan && $plan =~ m/[^0-9]/) { |
82
|
2
|
100
|
|
|
|
10
|
if ($plan eq 'tests') { |
|
|
50
|
|
|
|
|
|
83
|
1
|
|
|
|
|
3
|
$plan = shift; |
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
elsif ($plan eq 'skip_all') { |
86
|
1
|
|
|
|
|
4
|
skip_all(@_); |
87
|
0
|
|
|
|
|
0
|
$ctx->release; |
88
|
0
|
|
|
|
|
0
|
return; |
89
|
|
|
|
|
|
|
} |
90
|
|
|
|
|
|
|
} |
91
|
|
|
|
|
|
|
|
92
|
8
|
|
|
|
|
44
|
$ctx->plan($plan); |
93
|
8
|
|
|
|
|
2335
|
$ctx->release; |
94
|
|
|
|
|
|
|
} |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
sub skip_all { |
97
|
29
|
|
|
29
|
1
|
2650
|
my ($reason) = @_; |
98
|
29
|
|
|
|
|
370
|
my $ctx = context(); |
99
|
29
|
|
|
|
|
7359
|
$ctx->plan(0, SKIP => $reason); |
100
|
2
|
50
|
|
|
|
975
|
$ctx->release if $ctx; |
101
|
|
|
|
|
|
|
} |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
sub done_testing { |
104
|
140
|
|
|
140
|
1
|
2081
|
my $ctx = context(); |
105
|
140
|
|
|
|
|
20476
|
$ctx->hub->finalize($ctx->trace, 1); |
106
|
114
|
|
|
|
|
61604
|
$ctx->release; |
107
|
|
|
|
|
|
|
} |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
sub bail_out { |
110
|
3
|
|
|
3
|
1
|
692
|
my ($reason) = @_; |
111
|
3
|
|
|
|
|
7
|
my $ctx = context(); |
112
|
3
|
|
|
|
|
195
|
$ctx->bail($reason); |
113
|
0
|
0
|
|
|
|
|
$ctx->release if $ctx; |
114
|
|
|
|
|
|
|
} |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
1; |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
__END__ |