line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
1
|
|
|
1
|
|
59521
|
use strict; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
131
|
|
2
|
1
|
|
|
1
|
|
7
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
72
|
|
3
|
|
|
|
|
|
|
package Test::Bomb; |
4
|
|
|
|
|
|
|
# ABSTRACT: a test which succeeds until a deadline passes ( a time bomb ) |
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
our $VERSION = 0.007; |
7
|
|
|
|
|
|
|
|
8
|
1
|
|
|
1
|
|
6
|
use Exporter qw/import/; |
|
1
|
|
|
|
|
7
|
|
|
1
|
|
|
|
|
86
|
|
9
|
1
|
|
|
1
|
|
1095
|
use Date::Parse; |
|
1
|
|
|
|
|
11610
|
|
|
1
|
|
|
|
|
169
|
|
10
|
1
|
|
|
1
|
|
11
|
use Test::More; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
10
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
our @EXPORT = qw/ bomb /; |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
my @configFiles = ( |
16
|
|
|
|
|
|
|
$ENV{TESTBOMBCONFIG} || '', |
17
|
|
|
|
|
|
|
'./t/tbc', './t/testbombconfig', |
18
|
|
|
|
|
|
|
'./.tbc', './.testbombconfig', |
19
|
|
|
|
|
|
|
'./tbc', './testbombconfig', |
20
|
|
|
|
|
|
|
($ENV{HOME}||'.').'/.tbc', |
21
|
|
|
|
|
|
|
($ENV{HOME}||'.').'/.testbombconfig', |
22
|
|
|
|
|
|
|
); |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
%Test::Bomb::groups = ( ); |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
sub bomb { |
29
|
11
|
|
|
11
|
1
|
54599
|
local( $Test::Builder::Level ) = 2; |
30
|
11
|
100
|
|
|
|
40
|
ok( 0, 'Don\'t send me out there! I can\'t take the preasure!'), return |
31
|
|
|
|
|
|
|
if releasing(); |
32
|
10
|
100
|
|
|
|
58
|
if( $_[0] eq '-after' ) { |
|
|
100
|
|
|
|
|
|
33
|
3
|
|
|
|
|
11
|
checkDate($_[1]); |
34
|
|
|
|
|
|
|
} elsif( $_[0] eq '-with' ) { |
35
|
6
|
|
|
|
|
15
|
my $name = $_[1]; |
36
|
6
|
100
|
|
|
|
21
|
if( exists $Test::Bomb::groups{$name} ) { |
37
|
2
|
|
|
|
|
93
|
checkDate($Test::Bomb::groups{$name}) |
38
|
|
|
|
|
|
|
} else { |
39
|
4
|
|
|
|
|
13
|
checkDate(readConfig($name)); |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
} else { |
42
|
1
|
|
|
|
|
10
|
ok 0, 'invalid parameter: \''. $_[0] . "'"; |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
return |
45
|
10
|
|
|
|
|
1604
|
} |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
sub readConfig { |
49
|
5
|
|
|
5
|
1
|
3847
|
local( $Test::Builder::Level ) = 3; |
50
|
5
|
|
|
|
|
11
|
my $name = shift; |
51
|
5
|
|
|
|
|
7
|
my $stringDate; |
52
|
5
|
|
100
|
|
|
14
|
my $configFile = ( grep { -f $_ } @configFiles )[0] || ''; |
53
|
5
|
100
|
|
|
|
137
|
open IN, $configFile or ok( 0, 'failed to open config file'), |
54
|
|
|
|
|
|
|
return 'configFail'; |
55
|
5
|
100
|
|
|
|
21
|
($stringDate) = map { $_->[0] eq $name ? $_->[1] : () } |
|
5
|
|
|
|
|
59
|
|
56
|
3
|
|
|
|
|
64
|
map { s/(^\s+|\s+$|['"])//g; chomp; [split /\s*=\s*/,$_] } |
|
5
|
|
|
|
|
14
|
|
|
5
|
|
|
|
|
33
|
|
57
|
|
|
|
|
|
|
( ); |
58
|
3
|
|
|
|
|
37
|
close IN; |
59
|
3
|
100
|
|
|
|
18
|
ok( 0, 'bomb group is not defined: '.$name), return 'configFail' |
60
|
|
|
|
|
|
|
if not defined $stringDate; |
61
|
2
|
|
|
|
|
11
|
return $stringDate; |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
sub checkDate { |
66
|
11
|
|
|
11
|
1
|
5455
|
local( $Test::Builder::Level ) = 3; |
67
|
11
|
|
|
|
|
25
|
my $dateStr = shift; |
68
|
11
|
100
|
|
|
|
142
|
return if $dateStr eq 'configFail' ; |
69
|
9
|
|
|
|
|
50
|
my $time = str2time($dateStr); |
70
|
9
|
100
|
|
|
|
3814
|
ok(0, "invalid date: '$dateStr'"), return unless $time; |
71
|
8
|
|
|
|
|
16
|
my $res = time < $time; |
72
|
8
|
100
|
|
|
|
27
|
my $name = $res ? "bomb after $dateStr" : 'deadline passed' ; |
73
|
8
|
|
|
|
|
45
|
ok $res, $name ; |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
sub releasing { |
78
|
13
|
100
|
|
13
|
1
|
3891
|
return 1 if exists $ENV{DZIL_RELEASING}; |
79
|
|
|
|
|
|
|
} |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
1; # End of Test::Bomb |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
__END__ |