line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
3
|
|
|
3
|
|
75620
|
use strict; |
|
3
|
|
|
|
|
7
|
|
|
3
|
|
|
|
|
120
|
|
2
|
3
|
|
|
3
|
|
16
|
use warnings; |
|
3
|
|
|
|
|
5
|
|
|
3
|
|
|
|
|
143
|
|
3
|
|
|
|
|
|
|
package Test::Easy; |
4
|
3
|
|
|
3
|
|
19
|
use base qw(Exporter); |
|
3
|
|
|
|
|
4
|
|
|
3
|
|
|
|
|
351
|
|
5
|
|
|
|
|
|
|
|
6
|
3
|
|
|
3
|
|
86
|
use 5.006002; |
|
3
|
|
|
|
|
9
|
|
|
3
|
|
|
|
|
173
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
# used as helper modules within this module |
9
|
|
|
|
|
|
|
require Test::More; |
10
|
3
|
|
|
3
|
|
17
|
use Carp qw(confess); |
|
3
|
|
|
|
|
5
|
|
|
3
|
|
|
|
|
245
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
# this module re-exports functions from these modules |
13
|
3
|
|
|
3
|
|
1211
|
use Test::Easy::DataDriven; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
use Test::Easy::DeepEqual; |
15
|
|
|
|
|
|
|
use Test::Easy::Time; |
16
|
|
|
|
|
|
|
use Test::Resub; |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
our $VERSION = 1.11; |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
## spend a little time moving things around into @EXPORT, @EXPORT_OK |
21
|
|
|
|
|
|
|
our @EXPORT = qw(nearly_ok around_about wiretap); |
22
|
|
|
|
|
|
|
our @EXPORT_OK = qw(nearly test_sub); |
23
|
|
|
|
|
|
|
foreach my $supplier (qw( |
24
|
|
|
|
|
|
|
Test::Resub |
25
|
|
|
|
|
|
|
Test::Easy::DataDriven |
26
|
|
|
|
|
|
|
Test::Easy::Time |
27
|
|
|
|
|
|
|
Test::Easy::DeepEqual |
28
|
|
|
|
|
|
|
)) { |
29
|
|
|
|
|
|
|
no strict 'refs'; |
30
|
|
|
|
|
|
|
push @EXPORT, @{"$supplier\::EXPORT"}; |
31
|
|
|
|
|
|
|
push @EXPORT_OK, @{"$supplier\::EXPORT_TAGS"}; |
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
# Set up %EXPORT_TAGS based on whatever we've shoved into @EXPORT, @EXPORT_OK |
35
|
|
|
|
|
|
|
our %EXPORT_TAGS = ( |
36
|
|
|
|
|
|
|
helpers => [@EXPORT_OK], |
37
|
|
|
|
|
|
|
all => [@EXPORT, @EXPORT_OK], |
38
|
|
|
|
|
|
|
); |
39
|
|
|
|
|
|
|
foreach my $supplier (qw(Test::Resub Test::Easy::DataDriven)) { |
40
|
|
|
|
|
|
|
no strict 'refs'; |
41
|
|
|
|
|
|
|
%EXPORT_TAGS = _merge(%EXPORT_TAGS, %{"$supplier\::EXPORT_TAGS"}); |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
sub _merge { |
45
|
|
|
|
|
|
|
my %out; |
46
|
|
|
|
|
|
|
while (my ($k, $v) = splice @_, 0, 2) { |
47
|
|
|
|
|
|
|
push @{$out{$k}}, @$v; |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
return %out; |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
# code begins here |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
sub nearly_ok { |
55
|
|
|
|
|
|
|
my ($got, $expected, $epsilon, $message) = @_; |
56
|
|
|
|
|
|
|
local $Test::Builder::Level = $Test::Builder::Level + 1; |
57
|
|
|
|
|
|
|
Test::More::ok( nearly($got, $expected, $epsilon), $message ) |
58
|
|
|
|
|
|
|
or warn "expected $got to be $expected +/- $epsilon; actual difference was " . ($expected - $got) . "\n"; |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
sub nearly { |
62
|
|
|
|
|
|
|
my ($got, $expected, $epsilon) = @_; |
63
|
|
|
|
|
|
|
my $close = abs($expected - $got) <= $epsilon; |
64
|
|
|
|
|
|
|
return !!$close; |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
sub around_about { |
68
|
|
|
|
|
|
|
my ($now, $epsilon) = @_; |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
$epsilon ||= 0; |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
return Test::Easy::equivalence->new( |
73
|
|
|
|
|
|
|
raw => [$now, $epsilon], |
74
|
|
|
|
|
|
|
explain => sub { |
75
|
|
|
|
|
|
|
my ($got, $raw) = @_; |
76
|
|
|
|
|
|
|
return sprintf '%s within %s seconds of %s', $got, reverse @$raw; |
77
|
|
|
|
|
|
|
}, |
78
|
|
|
|
|
|
|
test => sub { |
79
|
|
|
|
|
|
|
my ($got) = @_; |
80
|
|
|
|
|
|
|
return time_nearly($got, $now, $epsilon); |
81
|
|
|
|
|
|
|
}, |
82
|
|
|
|
|
|
|
); |
83
|
|
|
|
|
|
|
} |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
sub test_sub (&) { |
86
|
|
|
|
|
|
|
my $test = shift; |
87
|
|
|
|
|
|
|
return sub { |
88
|
|
|
|
|
|
|
local $Test::Builder::Level = $Test::Builder::Level + 1; |
89
|
|
|
|
|
|
|
goto &$test; |
90
|
|
|
|
|
|
|
}; |
91
|
|
|
|
|
|
|
} |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
sub wiretap { |
94
|
|
|
|
|
|
|
my ($target, $pre, @args) = @_; |
95
|
|
|
|
|
|
|
my $orig = do { no strict 'refs'; *{$target}{CODE} }; |
96
|
|
|
|
|
|
|
return resub $target, sub { |
97
|
|
|
|
|
|
|
$pre->(@_) if $pre; |
98
|
|
|
|
|
|
|
$orig->(@_); |
99
|
|
|
|
|
|
|
}, @args; |
100
|
|
|
|
|
|
|
} |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
1; |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
__END__ |