line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Test2::Tools::SkipUntil; |
2
|
4
|
|
|
4
|
|
259719
|
use strict; |
|
4
|
|
|
|
|
18
|
|
|
4
|
|
|
|
|
79
|
|
3
|
4
|
|
|
4
|
|
14
|
use warnings; |
|
4
|
|
|
|
|
5
|
|
|
4
|
|
|
|
|
82
|
|
4
|
4
|
|
|
4
|
|
13
|
use Carp 'croak'; |
|
4
|
|
|
|
|
6
|
|
|
4
|
|
|
|
|
154
|
|
5
|
4
|
|
|
4
|
|
394
|
use Test2::API 'context'; |
|
4
|
|
|
|
|
45493
|
|
|
4
|
|
|
|
|
145
|
|
6
|
4
|
|
|
4
|
|
1105
|
use Time::Piece; |
|
4
|
|
|
|
|
22237
|
|
|
4
|
|
|
|
|
13
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
our $VERSION = '0.05'; |
9
|
|
|
|
|
|
|
our @EXPORT = qw(skip_until skip_all_until); |
10
|
4
|
|
|
4
|
|
284
|
use base 'Exporter'; |
|
4
|
|
|
|
|
7
|
|
|
4
|
|
|
|
|
710
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub skip_until($;$$) { |
13
|
7
|
|
|
7
|
1
|
9500
|
my ($why, $count, $datetime) = @_; |
14
|
|
|
|
|
|
|
|
15
|
7
|
|
|
|
|
17
|
check_why($why); |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
# count is optional |
18
|
6
|
100
|
|
|
|
10
|
if (@_ == 3) { |
19
|
4
|
|
|
|
|
6
|
check_skip_count($count); |
20
|
|
|
|
|
|
|
} |
21
|
|
|
|
|
|
|
else { |
22
|
2
|
|
|
|
|
3
|
$datetime = $count; |
23
|
2
|
|
|
|
|
3
|
$count = 1; |
24
|
|
|
|
|
|
|
} |
25
|
|
|
|
|
|
|
|
26
|
5
|
|
|
|
|
6
|
my $timepiece = parse_datetime($datetime); |
27
|
3
|
|
|
|
|
175
|
$timepiece = apply_offset($timepiece); |
28
|
|
|
|
|
|
|
|
29
|
3
|
100
|
|
|
|
149
|
if (should_skip($timepiece)) { |
30
|
|
|
|
|
|
|
# copied from Test2::Tools::Basic::skip |
31
|
2
|
|
|
|
|
40
|
my $ctx = context(); |
32
|
2
|
|
|
|
|
127
|
$ctx->skip('skipped test', "$why until $timepiece") for (1..$count); |
33
|
2
|
|
|
|
|
1045
|
$ctx->release; |
34
|
4
|
|
|
4
|
|
21
|
no warnings 'exiting'; |
|
4
|
|
|
|
|
5
|
|
|
4
|
|
|
|
|
1479
|
|
35
|
2
|
|
|
|
|
50
|
last SKIP; |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
sub skip_all_until($$) { |
40
|
1
|
|
|
1
|
1
|
58
|
my ($why, $datetime) = @_; |
41
|
|
|
|
|
|
|
|
42
|
1
|
|
|
|
|
17
|
check_why($why); |
43
|
|
|
|
|
|
|
|
44
|
1
|
|
|
|
|
3
|
my $timepiece = parse_datetime($datetime); |
45
|
1
|
|
|
|
|
144
|
$timepiece = apply_offset($timepiece); |
46
|
|
|
|
|
|
|
|
47
|
1
|
50
|
|
|
|
115
|
if (should_skip($timepiece)) { |
48
|
|
|
|
|
|
|
# copied from Test2::Tools::Basic::skip_all |
49
|
1
|
|
|
|
|
40
|
my $ctx = context(); |
50
|
1
|
|
|
|
|
4335
|
$ctx->plan(0, SKIP => "$why until $timepiece"); |
51
|
0
|
0
|
|
|
|
0
|
$ctx->release if $ctx; |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
sub check_why { |
56
|
12
|
|
|
12
|
0
|
1995
|
my $why = shift; |
57
|
12
|
100
|
100
|
|
|
59
|
unless(defined $why && ref $why eq '' && length $why) { |
|
|
|
100
|
|
|
|
|
58
|
5
|
100
|
|
|
|
430
|
croak sprintf 'requires "why" defined scalar argument (got %s)', |
59
|
|
|
|
|
|
|
defined $why ? $why : 'undef'; |
60
|
|
|
|
|
|
|
} |
61
|
7
|
|
|
|
|
11
|
return 1; |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
sub should_skip { |
65
|
6
|
|
|
6
|
0
|
1794
|
my $timepiece = shift; |
66
|
|
|
|
|
|
|
|
67
|
6
|
50
|
33
|
|
|
18
|
croak 'Requires a Time::Piece argument' |
68
|
|
|
|
|
|
|
unless $timepiece && ref $timepiece eq 'Time::Piece'; |
69
|
|
|
|
|
|
|
|
70
|
6
|
|
|
|
|
173
|
my $timepiece_now = localtime; |
71
|
6
|
|
|
|
|
264
|
return $timepiece_now < $timepiece; |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
sub check_skip_count { |
75
|
13
|
|
|
13
|
0
|
3273
|
my $count = shift; |
76
|
13
|
100
|
100
|
|
|
99
|
unless (defined $count && |
|
|
|
66
|
|
|
|
|
77
|
|
|
|
|
|
|
$count =~ qr/^\d+$/ && |
78
|
|
|
|
|
|
|
$count > 0) |
79
|
|
|
|
|
|
|
{ |
80
|
7
|
100
|
|
|
|
465
|
croak sprintf('skip test count must be a positive integer! (got %s)', |
81
|
|
|
|
|
|
|
defined $count ? $count : 'undef'); |
82
|
|
|
|
|
|
|
} |
83
|
6
|
|
|
|
|
18
|
return 1; |
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
sub parse_datetime { |
87
|
14
|
|
|
14
|
0
|
10107
|
my $datetime = shift; |
88
|
|
|
|
|
|
|
|
89
|
14
|
100
|
100
|
|
|
135
|
if ($datetime && $datetime =~ qr/^\d\d\d\d-\d\d-\d\dT\d\d:\d\d:\d\d$/) { |
|
|
100
|
100
|
|
|
|
|
90
|
1
|
|
|
|
|
15
|
return Time::Piece->strptime($datetime, '%Y-%m-%dT%H:%M:%S'); |
91
|
|
|
|
|
|
|
} |
92
|
|
|
|
|
|
|
elsif ($datetime && $datetime =~ qr/^\d\d\d\d-\d\d-\d\d$/) { |
93
|
5
|
|
|
|
|
32
|
return Time::Piece->strptime($datetime, '%Y-%m-%d'); |
94
|
|
|
|
|
|
|
} |
95
|
|
|
|
|
|
|
else { |
96
|
8
|
100
|
|
|
|
683
|
croak sprintf q#Datetime must be in format YYYY-MM-DD(THH:MM:SS)? (got %s)#, |
97
|
|
|
|
|
|
|
defined $datetime ? $datetime : 'undef'; |
98
|
|
|
|
|
|
|
} |
99
|
|
|
|
|
|
|
} |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
sub apply_offset { |
102
|
5
|
|
|
5
|
0
|
2562
|
my $timepiece = shift; |
103
|
5
|
|
|
|
|
13
|
my $offset_secs = localtime()->tzoffset; |
104
|
5
|
|
|
|
|
792
|
return $timepiece + $offset_secs; |
105
|
|
|
|
|
|
|
} |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
1; |
108
|
|
|
|
|
|
|
=head1 NAME |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
Test2::Tools::SkipUntil - skip tests until a date is reached |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
=head1 SYNOPSIS |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
use Test2::Bundle::More |
115
|
|
|
|
|
|
|
use Test2::Tools::SkipUntil; |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
SKIP: { |
118
|
|
|
|
|
|
|
skip_until "known fail see issue #213", '2018-06-01'; |
119
|
|
|
|
|
|
|
... |
120
|
|
|
|
|
|
|
} |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
... |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
done_testing; |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
=head1 DESCRIPTION |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
Exports two functions for skipping tests until a datetime is reached. Dates are |
129
|
|
|
|
|
|
|
evaluated in C. These might be useful when you have known exceptions |
130
|
|
|
|
|
|
|
in your test suite which are temporary. |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
=head1 FUNCTIONS |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
=head2 skip_until ($why, $count, $datetime) |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
Skips all tests in a C block, registering C<$count> skipped tests until |
137
|
|
|
|
|
|
|
C is greater than or equal to C<$datetime>. Just like with |
138
|
|
|
|
|
|
|
L, C<$count> is |
139
|
|
|
|
|
|
|
optional, and defaults to 1. |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
C<$datetime> must be a scalar in one of the following formats: |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
=over 4 |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
=item * |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
YYYY-MM-DDTHH:MM:SS - e.g. "2017-05-01T13:24:58" |
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
=item * |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
YYYY-MM-DD - e.g. "2017-05-01" |
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
=back |
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
=head2 skip_all_until ($why, $datetime) |
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
Skips all tests by setting the test plan to zero, and exiting succesfully |
158
|
|
|
|
|
|
|
unless C is greater than or equal to C<$datetime>. Behaves like |
159
|
|
|
|
|
|
|
L. |
160
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
See L"skip_until ($why, $count, $datetime)"> for the accepted C<$datetime> formats. |
162
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
=head1 SOURCE |
164
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
The source code repository for Test2-Tools-SkipUntil can be found on L. |
166
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
=head1 AUTHORS |
168
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
David Farrell |
170
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
=head1 COPYRIGHT |
172
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
Copyright 2018 David Farrell |
174
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
=head1 LICENSE |
176
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. |
178
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
See L. |
180
|
|
|
|
|
|
|
|
181
|
|
|
|
|
|
|
=cut |