line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
2
|
|
|
2
|
|
82549
|
use strict; |
|
2
|
|
|
|
|
6
|
|
|
2
|
|
|
|
|
69
|
|
2
|
2
|
|
|
2
|
|
11
|
use warnings; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
88
|
|
3
|
|
|
|
|
|
|
package Test::Easy; |
4
|
2
|
|
|
2
|
|
11
|
use base qw(Exporter); |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
284
|
|
5
|
|
|
|
|
|
|
|
6
|
2
|
|
|
2
|
|
55
|
use 5.006002; |
|
2
|
|
|
|
|
6
|
|
|
2
|
|
|
|
|
194
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
# used as helper modules within this module |
9
|
|
|
|
|
|
|
require Test::More; |
10
|
2
|
|
|
2
|
|
14
|
use Carp qw(confess); |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
170
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
# this module re-exports functions from these modules |
13
|
2
|
|
|
2
|
|
1107
|
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.09; |
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 $rs; |
96
|
|
|
|
|
|
|
$rs = resub $target, sub { |
97
|
|
|
|
|
|
|
$pre->(@_) if $pre; |
98
|
|
|
|
|
|
|
$rs->{orig_code}->(@_); |
99
|
|
|
|
|
|
|
}, @args; |
100
|
|
|
|
|
|
|
} |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
1; |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
__END__ |