blib/lib/Test2/Tools/SkipUntil.pm

filter: Statementstmt 98.4% 64 / 65 Branchbran 83.3% 20 / 24 Conditioncond 85.7% 18 / 21 MC/DCmcdc 75.0% 9 / 12 Subroutinesub 100% 14 / 14 Podpod 28.5% 2 / 7 totaltotal 88.8% 127 / 143 CC 21 SCAR 13.4
CC
21
Cov
93%
parse_datetime
6.0
check_skip_count
5.0
check_why
5.0
CRAP 3.8
↑ Summary
1 package Test2::Tools::SkipUntil;
2 4 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 4 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 4 ▶use Carp 'croak';
Subroutine BEGIN: called CC=1 SCAR=0.0
5 4 ▶use Test2::API 'context';
Subroutine BEGIN: called CC=1 SCAR=0.0
6 4 ▶use Time::Piece;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 4 our $VERSION = '0.05';
9 4 our @EXPORT = qw(skip_until skip_all_until);
10 4 ▶use base 'Exporter';
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 7 ▶sub skip_until($;$$) {
Subroutine skip_until: called CC=4 SCAR=13.9
Pod documented
13 7 my ($why, $count, $datetime) = @_;
14  
15 7 check_why($why);
16  
17 # count is optional
18 6 ▶ if (@_ == 3) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_ == 3) { } 4 2 6
19 4 check_skip_count($count);
20 }
21 else {
22 2 $datetime = $count;
23 2 $count = 1;
24 }
25  
26 5 my $timepiece = parse_datetime($datetime);
27 3 $timepiece = apply_offset($timepiece);
28  
29 3 ▶ if (should_skip($timepiece)) {
Branch: 1 branch
BranchTrueFalseTotal
if (should_skip($timepiece)) 2 1 3
30 # copied from Test2::Tools::Basic::skip
31 2 my $ctx = context();
32 2 $ctx->skip('skipped test', "$why until $timepiece") for (1..$count);
33 2 $ctx->release;
34 4 ▶ no warnings 'exiting';
Subroutine BEGIN: called CC=1 SCAR=0.0
35 2 last SKIP;
36 }
37 }
38  
39 1 ▶sub skip_all_until($$) {
Subroutine skip_all_until: called CC=3 SCAR=12.0
Pod documented
40 1 my ($why, $datetime) = @_;
41  
42 1 check_why($why);
43  
44 1 my $timepiece = parse_datetime($datetime);
45 1 $timepiece = apply_offset($timepiece);
46  
47 1 ▶ if (should_skip($timepiece)) {
Branch: 1 branch
BranchTrueFalseTotal
if (should_skip($timepiece)) 1 0 1
48 # copied from Test2::Tools::Basic::skip_all
49 1 my $ctx = context();
50 1 $ctx->plan(0, SKIP => "$why until $timepiece");
51 0 ▶ $ctx->release if $ctx;
Branch: 1 branch
BranchTrueFalseTotal
if $ctx 0 0 0
52 }
53 }
54  
55 12 ▶sub check_why {
Subroutine check_why: called CC=5 SCAR=16.1
Pod undocumented
56 12 my $why = shift;
57 12 ▶ unless(defined $why && ref $why eq '' && length $why) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $why and ref $why eq "" and length $why) 5 7 12
Condition100%6/6
defined $why and ref $why eq "" and length $why
!ll&&!rl&&r
417
defined $why and ref $why eq ""
!ll&&!rl&&r
318
MC/DC100%3/3
defined $why and ref $why eq "" and length $why
defined $why ref $why eq "" length $why
Truth table100%4/4
A and B and C
A= defined $whyB= ref $why eq ""C= length $why
ABCresult
0XX0
10X0
1100
1111
58 5 ▶ croak sprintf 'requires "why" defined scalar argument (got %s)',
Branch: 1 branch
BranchTrueFalseTotal
defined $why ? : 2 3 5
59 defined $why ? $why : 'undef';
60 }
61 7 return 1;
62 }
63  
64 6 ▶sub should_skip {
Subroutine should_skip: called CC=3 SCAR=12.0
Pod undocumented
65 6 my $timepiece = shift;
66  
67 6 ▶ croak 'Requires a Time::Piece argument'
Branch: 1 branch
BranchTrueFalseTotal
unless $timepiece and ref $timepiece eq "Time::Piece" 0 6 6
Condition33%1/3
$timepiece and ref $timepiece eq "Time::Piece"
!ll&&!rl&&r
006
MC/DC0%0/2
$timepiece and ref $timepiece eq "Time::Piece"
$timepiece ref $timepiece eq "Time::Piece"
Truth table33%1/3
A and B
A= $timepieceB= ref $timepiece eq "Time::Piece"
ABresult
0X0
100
111
68 unless $timepiece && ref $timepiece eq 'Time::Piece';
69  
70 6 my $timepiece_now = localtime;
71 6 return $timepiece_now < $timepiece;
72 }
73  
74 13 ▶sub check_skip_count {
Subroutine check_skip_count: called CC=5 SCAR=16.1
Pod undocumented
75 13 my $count = shift;
76 13 ▶ unless (defined $count &&
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $count and $count =~ qr/^\d+$/ and $count > 0) 7 6 13
Condition83%5/6
defined $count and $count =~ qr/^\d+$/ and $count > 0
!ll&&!rl&&r
706
defined $count and $count =~ qr/^\d+$/
!ll&&!rl&&r
346
MC/DC66%2/3
defined $count and $count =~ qr/^\d+$/ and $count > 0
defined $count $count =~ qr/^\d+$/ $count > 0
Truth table75%3/4
A and B and C
A= defined $countB= $count =~ qr/^\d+$/C= $count > 0
ABCresult
0XX0
10X0
1100
1111
77 $count =~ qr/^\d+$/ &&
78 $count > 0)
79 {
80 7 ▶ croak sprintf('skip test count must be a positive integer! (got %s)',
Branch: 1 branch
BranchTrueFalseTotal
defined $count ? : 4 3 7
81 defined $count ? $count : 'undef');
82 }
83 6 return 1;
84 }
85  
86 14 ▶sub parse_datetime {
Subroutine parse_datetime: called CC=6 SCAR=17.9
Pod undocumented
87 14 my $datetime = shift;
88  
89 14 ▶ if ($datetime && $datetime =~ qr/^\d\d\d\d-\d\d-\d\dT\d\d:\d\d:\d\d$/) {
Branch: 2 branches
BranchTrueFalseTotal
if ($datetime and $datetime =~ qr/^\d\d\d\d-\d\d-\d\dT\d\d:\d\d:\d\d$/) { } 1 13 14
elsif ($datetime and $datetime =~ qr/^\d\d\d\d-\d\d-\d\d$/) { } 5 8 13
Condition100%3/3
$datetime and $datetime =~ qr/^\d\d\d\d-\d\d-\d\dT\d\d:\d\d:\d\d$/
!ll&&!rl&&r
581
MC/DC100%2/2
$datetime and $datetime =~ qr/^\d\d\d\d-\d\d-\d\dT\d\d:\d\d:\d\d$/
$datetime $datetime =~ qr/^\d\d\d\d-\d\d-\d\dT\d\d:\d\d:\d\d$/
Truth table100%3/3
A and B
A= $datetimeB= $datetime =~ qr/^\d\d\d\d-\d\d-\d\dT\d\d:\d\d:\d\d$/
ABresult
0X0
100
111
90 1 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$/) {
Condition100%3/3
$datetime and $datetime =~ qr/^\d\d\d\d-\d\d-\d\d$/
!ll&&!rl&&r
535
MC/DC100%2/2
$datetime and $datetime =~ qr/^\d\d\d\d-\d\d-\d\d$/
$datetime $datetime =~ qr/^\d\d\d\d-\d\d-\d\d$/
Truth table100%3/3
A and B
A= $datetimeB= $datetime =~ qr/^\d\d\d\d-\d\d-\d\d$/
ABresult
0X0
100
111
93 5 return Time::Piece->strptime($datetime, '%Y-%m-%d');
94 }
95 else {
96 8 ▶ croak sprintf q#Datetime must be in format YYYY-MM-DD(THH:MM:SS)? (got %s)#,
Branch: 1 branch
BranchTrueFalseTotal
defined $datetime ? : 4 4 8
97 defined $datetime ? $datetime : 'undef';
98 }
99 }
100  
101 5 ▶sub apply_offset {
Subroutine apply_offset: called CC=1 SCAR=0.0
Pod undocumented
102 5 my $timepiece = shift;
103 5 my $offset_secs = localtime()->tzoffset;
104 5 return $timepiece + $offset_secs;
105 }
106  
107 4 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<localtime>. 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<SKIP> block, registering C<$count> skipped tests until
137 C<localtime> is greater than or equal to C<$datetime>. Just like with
138 L<skip|https://metacpan.org/pod/Test2::Tools::Basic#skip($why)>, 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<localtime> is greater than or equal to C<$datetime>. Behaves like
159 L<skip_all|https://metacpan.org/pod/Test2::Tools::Basic#skip_all($reason)>.
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<GitHub|https://github.com/dnmfarrell/Test2-Tools-SkipUntil>.
166  
167 =head1 AUTHORS
168  
169 David Farrell <dfarrell@cpan.org>
170  
171 =head1 COPYRIGHT
172  
173 Copyright 2018 David Farrell <dfarrell@cpan.org>
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<licenses|http://dev.perl.org/licenses/>.
180  
181 =cut
↑ Summary