line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Test::RandomCheck; |
2
|
4
|
|
|
4
|
|
24692
|
use strict; |
|
4
|
|
|
|
|
6
|
|
|
4
|
|
|
|
|
101
|
|
3
|
4
|
|
|
4
|
|
15
|
use warnings; |
|
4
|
|
|
|
|
11
|
|
|
4
|
|
|
|
|
95
|
|
4
|
4
|
|
|
4
|
|
2326
|
use Data::Dumper; |
|
4
|
|
|
|
|
29934
|
|
|
4
|
|
|
|
|
259
|
|
5
|
4
|
|
|
4
|
|
25
|
use Exporter qw(import); |
|
4
|
|
|
|
|
5
|
|
|
4
|
|
|
|
|
95
|
|
6
|
4
|
|
|
4
|
|
1601
|
use Test::RandomCheck::Generator; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
use Test::RandomCheck::PRNG; |
8
|
|
|
|
|
|
|
use Test::More (); |
9
|
|
|
|
|
|
|
use 5.008_005; |
10
|
|
|
|
|
|
|
use constant DEBUG => $ENV{RANDOMCHECK_DEBUG}; |
11
|
|
|
|
|
|
|
our $VERSION = '0.02'; |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
our @EXPORT = qw(random_ok); |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
sub _dump_args ($) { |
16
|
|
|
|
|
|
|
my $args = shift; |
17
|
|
|
|
|
|
|
my $str = Data::Dumper->new([$args])->Indent(0)->Terse(1)->Dump; |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
# Use the list style instead of the array-ref style |
20
|
|
|
|
|
|
|
$str =~ s/^\[/(/; |
21
|
|
|
|
|
|
|
$str =~ s/\]$/)/; |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
"\@_ = $str"; |
24
|
|
|
|
|
|
|
} |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
sub random_ok (&$;@) { |
27
|
|
|
|
|
|
|
my $code = shift; |
28
|
|
|
|
|
|
|
my $type = shift; |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
my @types; |
31
|
|
|
|
|
|
|
push @types, shift |
32
|
|
|
|
|
|
|
while eval { $_[0]->isa("Test::RandomCheck::Types") }; |
33
|
|
|
|
|
|
|
$type = concat ($type, @types) if @types; |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
my %params = @_; |
36
|
|
|
|
|
|
|
my $shots = delete $params{shots} // 202; |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
local $Test::Builder::Level = $Test::Builder::Level + 1; |
39
|
|
|
|
|
|
|
my $generator = $type->arbitrary->map(sub { scalar $code->(@_), [@_] }); |
40
|
|
|
|
|
|
|
my $rand = Test::RandomCheck::PRNG->new; |
41
|
|
|
|
|
|
|
for (1 .. $shots) { |
42
|
|
|
|
|
|
|
my $size = ($_ - 1) % 101; |
43
|
|
|
|
|
|
|
my ($is_success, $args) = $generator->pick($rand, $size); |
44
|
|
|
|
|
|
|
unless ($is_success) { |
45
|
|
|
|
|
|
|
Test::More::diag("Faild by following args: " . _dump_args($args)); |
46
|
|
|
|
|
|
|
Test::More::diag( |
47
|
|
|
|
|
|
|
sprintf "Generated by size=%d", $size |
48
|
|
|
|
|
|
|
) if DEBUG; |
49
|
|
|
|
|
|
|
return Test::More::ok 0 ; |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
Test::More::ok 1; |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
1; |
56
|
|
|
|
|
|
|
__END__ |