line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Test::Proto::CodeRef; |
2
|
5
|
|
|
5
|
|
40625
|
use 5.008; |
|
5
|
|
|
|
|
16
|
|
|
5
|
|
|
|
|
195
|
|
3
|
5
|
|
|
5
|
|
27
|
use strict; |
|
5
|
|
|
|
|
12
|
|
|
5
|
|
|
|
|
153
|
|
4
|
5
|
|
|
5
|
|
26
|
use warnings; |
|
5
|
|
|
|
|
9
|
|
|
5
|
|
|
|
|
124
|
|
5
|
5
|
|
|
5
|
|
1250
|
use Moo; |
|
5
|
|
|
|
|
21728
|
|
|
5
|
|
|
|
|
32
|
|
6
|
|
|
|
|
|
|
extends 'Test::Proto::Base'; |
7
|
|
|
|
|
|
|
with( 'Test::Proto::Role::Value', ); |
8
|
5
|
|
|
5
|
|
4321
|
use Test::Proto::Common; |
|
5
|
|
|
|
|
10
|
|
|
5
|
|
|
|
|
2568
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
=head1 NAME |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
Test::Proto::CodeRef - Test a coderef's behaviour |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
=head1 METHODS |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
=head3 call |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
$p->call(['test.txt','>'], [$fh])->ok($subject); |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
Takes two arguments: first, the arguments to pass to the code, second the expected return value. Passes the arguments to the test subject, and tests the return value against the expected value. |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
The arguments and return value should be arrayrefs; the code is evaluated in list context. |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
=cut |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
sub call { |
27
|
3
|
|
|
3
|
1
|
39
|
my ($self) = shift; |
28
|
3
|
|
|
|
|
20
|
$self->call_list_context(@_); |
29
|
|
|
|
|
|
|
} |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
=head3 call_void_context |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
$p->call_void_context(['test.txt','>'])->ok($subject); |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
Takes one argument: the arguments to use with the method, as an arrayref. Calls the method on the test subject, with the arguments. This test will always pass, unless the code dies, or is not code. |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
=cut |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
sub call_void_context { |
40
|
1
|
|
|
1
|
1
|
14
|
my ( $self, $args, $reason ) = @_; |
41
|
1
|
|
|
|
|
9
|
$self->add_test( 'call_void_context', { args => $args, }, $reason ); |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
define_test "call_void_context" => sub { |
45
|
1
|
|
|
1
|
|
4
|
my ( $self, $data, $reason ) = @_; # self is the runner |
46
|
1
|
|
|
|
|
5
|
my $args = $data->{args}; |
47
|
1
|
|
|
|
|
31
|
$self->subject->(@$args); |
48
|
1
|
|
|
|
|
10
|
return $self->pass; #~ void context so we pass unless it dies. |
49
|
|
|
|
|
|
|
}; |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
=head3 call_scalar_context |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
$p->call_scalar_context(['test.txt','>'], $true)->ok($subject); |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
Takes two arguments: first, the arguments to pass to the code, second the expected return value. Passes the arguments to the test subject, and tests the return value against the expected value. |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
The arguments should be an arrayref, and the expected value should be a prototype evaluating the returned scalar, as the method is evaluated in scalar context. |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
=cut |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
sub call_scalar_context { |
62
|
1
|
|
|
1
|
1
|
12
|
my ( $self, $args, $expected, $reason ) = @_; |
63
|
1
|
|
|
|
|
12
|
$self->add_test( |
64
|
|
|
|
|
|
|
'call_scalar_context', |
65
|
|
|
|
|
|
|
{ |
66
|
|
|
|
|
|
|
args => $args, |
67
|
|
|
|
|
|
|
expected => $expected |
68
|
|
|
|
|
|
|
}, |
69
|
|
|
|
|
|
|
$reason |
70
|
|
|
|
|
|
|
); |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
define_test "call_scalar_context" => sub { |
74
|
1
|
|
|
1
|
|
3
|
my ( $self, $data, $reason ) = @_; # self is the runner |
75
|
1
|
|
|
|
|
3
|
my $args = $data->{args}; |
76
|
1
|
|
|
|
|
8
|
my $expected = upgrade( $data->{expected} ); |
77
|
1
|
|
|
|
|
30
|
my $response = $self->subject->(@$args); |
78
|
1
|
|
|
|
|
13
|
return $expected->validate( $response, $self ); |
79
|
|
|
|
|
|
|
}; |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
=head3 call_list_context |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
$p->call_list_context(['test.txt','>'], [$true])->ok($subject); |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
Takes two arguments: first, the arguments to pass to the code, second the expected return value. Passes the arguments to the test subject, and tests the return value against the expected value. |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
The arguments and return value should be arrayrefs; the code is evaluated in list context. |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
=cut |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
sub call_list_context { |
92
|
5
|
|
|
5
|
1
|
31
|
my ( $self, $args, $expected, $reason ) = @_; |
93
|
5
|
|
|
|
|
46
|
$self->add_test( |
94
|
|
|
|
|
|
|
'call_list_context', |
95
|
|
|
|
|
|
|
{ |
96
|
|
|
|
|
|
|
args => $args, |
97
|
|
|
|
|
|
|
expected => $expected |
98
|
|
|
|
|
|
|
}, |
99
|
|
|
|
|
|
|
$reason |
100
|
|
|
|
|
|
|
); |
101
|
|
|
|
|
|
|
} |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
define_test call_list_context => sub { |
104
|
5
|
|
|
5
|
|
11
|
my ( $self, $data, $reason ) = @_; # self is the runner |
105
|
5
|
|
|
|
|
14
|
my $args = $data->{args}; |
106
|
5
|
|
|
|
|
26
|
my $expected = upgrade( $data->{expected} ); |
107
|
5
|
|
|
|
|
136
|
my $response = [ $self->subject->(@$args) ]; |
108
|
5
|
|
|
|
|
68
|
return $expected->validate( $response, $self ); |
109
|
|
|
|
|
|
|
}; |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
=head1 OTHER INFORMATION |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
For author, version, bug reports, support, etc, please see L. |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
=cut |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
1; |