| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Test::EasyMock::Expectation; |
|
2
|
9
|
|
|
9
|
|
41
|
use strict; |
|
|
9
|
|
|
|
|
17
|
|
|
|
9
|
|
|
|
|
270
|
|
|
3
|
9
|
|
|
9
|
|
43
|
use warnings; |
|
|
9
|
|
|
|
|
15
|
|
|
|
9
|
|
|
|
|
397
|
|
|
4
|
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
=head1 NAME |
|
6
|
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
Test::EasyMock::Expectation - A expected behavior object. |
|
8
|
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
=cut |
|
10
|
9
|
|
|
9
|
|
50
|
use Carp qw(croak); |
|
|
9
|
|
|
|
|
14
|
|
|
|
9
|
|
|
|
|
5429
|
|
|
11
|
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
=head1 CONSTRUCTORS |
|
13
|
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
=head2 new(method=>$method, args=>$args}) |
|
15
|
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
Create a instance. |
|
17
|
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
=cut |
|
19
|
|
|
|
|
|
|
sub new { |
|
20
|
52
|
|
|
52
|
1
|
90
|
my ($class, $args) = @_; |
|
21
|
|
|
|
|
|
|
return bless { |
|
22
|
|
|
|
|
|
|
_method => $args->{method}, |
|
23
|
|
|
|
|
|
|
_args => $args->{args}, |
|
24
|
52
|
|
|
1
|
|
532
|
_results => [ { code => sub { return; }, implicit => 1 } ], |
|
|
1
|
|
|
|
|
6
|
|
|
25
|
|
|
|
|
|
|
}, $class; |
|
26
|
|
|
|
|
|
|
} |
|
27
|
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
=head1 PROPERTIES |
|
29
|
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
=head2 method - An expected method name. |
|
31
|
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
=cut |
|
33
|
|
|
|
|
|
|
sub method { |
|
34
|
5
|
|
|
5
|
1
|
8
|
my ($self) = @_; |
|
35
|
5
|
|
|
|
|
15
|
return $self->{_method}; |
|
36
|
|
|
|
|
|
|
} |
|
37
|
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
=head1 METHODS |
|
39
|
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
=head2 push_result($code) |
|
41
|
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
Add a method result behavior. |
|
43
|
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
=cut |
|
45
|
|
|
|
|
|
|
sub push_result { |
|
46
|
28
|
|
|
28
|
1
|
58
|
my ($self, $code) = @_; |
|
47
|
28
|
|
|
|
|
61
|
$self->remove_implicit_result(); |
|
48
|
28
|
|
|
|
|
103
|
push @{$self->{_results}}, { code => $code }; |
|
|
28
|
|
|
|
|
117
|
|
|
49
|
|
|
|
|
|
|
} |
|
50
|
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
=head2 set_stub_result($code) |
|
52
|
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
Set a method result behavior as stub. |
|
54
|
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
=cut |
|
56
|
|
|
|
|
|
|
sub set_stub_result { |
|
57
|
21
|
|
|
21
|
1
|
33
|
my ($self, $code) = @_; |
|
58
|
21
|
|
|
|
|
51
|
$self->remove_implicit_result(); |
|
59
|
21
|
|
|
|
|
126
|
$self->{_stub_result} = { code => $code }; |
|
60
|
|
|
|
|
|
|
} |
|
61
|
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
=head2 remove_implicit_result() |
|
63
|
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
Remove results which flagged with 'implicit'. |
|
65
|
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
=cut |
|
67
|
|
|
|
|
|
|
sub remove_implicit_result { |
|
68
|
49
|
|
|
49
|
1
|
68
|
my ($self) = @_; |
|
69
|
50
|
|
|
|
|
201
|
$self->{_results} = [ |
|
70
|
49
|
|
|
|
|
64
|
grep { !$_->{implicit} } @{$self->{_results}} |
|
|
49
|
|
|
|
|
128
|
|
|
71
|
|
|
|
|
|
|
]; |
|
72
|
|
|
|
|
|
|
} |
|
73
|
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
=head2 retrieve_result() |
|
75
|
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
Retrieve a result value. |
|
77
|
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
=cut |
|
79
|
|
|
|
|
|
|
sub retrieve_result { |
|
80
|
44
|
|
|
44
|
1
|
80
|
my ($self) = @_; |
|
81
|
44
|
|
66
|
|
|
109
|
my $result = shift @{$self->{_results}} || $self->{_stub_result}; |
|
82
|
44
|
50
|
|
|
|
120
|
croak('no result.') unless $result; |
|
83
|
44
|
|
|
|
|
157
|
return $result->{code}->(); |
|
84
|
|
|
|
|
|
|
} |
|
85
|
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
=head2 has_result |
|
87
|
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
It is tested whether it has a result. |
|
89
|
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
=cut |
|
91
|
|
|
|
|
|
|
sub has_result { |
|
92
|
105
|
|
|
105
|
1
|
140
|
my ($self) = @_; |
|
93
|
105
|
|
|
|
|
126
|
return @{$self->{_results}} > 0; |
|
|
105
|
|
|
|
|
493
|
|
|
94
|
|
|
|
|
|
|
} |
|
95
|
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
=head2 has_stub_result |
|
97
|
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
It is tested whether it has a stub result. |
|
99
|
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
=cut |
|
101
|
|
|
|
|
|
|
sub has_stub_result { |
|
102
|
26
|
|
|
26
|
1
|
37
|
my ($self) = @_; |
|
103
|
26
|
|
|
|
|
141
|
return exists $self->{_stub_result}; |
|
104
|
|
|
|
|
|
|
} |
|
105
|
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
=head2 matches($args) |
|
107
|
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
It is tested whether the specified argument matches. |
|
109
|
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
=cut |
|
111
|
|
|
|
|
|
|
sub matches { |
|
112
|
115
|
|
|
115
|
1
|
189
|
my ($self, $args) = @_; |
|
113
|
115
|
|
100
|
|
|
656
|
return $self->{_method} eq $args->{method} |
|
114
|
|
|
|
|
|
|
&& $self->{_args}->matches($args->{args}); |
|
115
|
|
|
|
|
|
|
} |
|
116
|
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
=head2 is_satisfied() |
|
118
|
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
The call to expect tests whether it was called briefly. |
|
120
|
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
=cut |
|
122
|
|
|
|
|
|
|
sub is_satisfied { |
|
123
|
47
|
|
|
47
|
1
|
70
|
my ($self) = @_; |
|
124
|
47
|
|
|
|
|
97
|
return !$self->has_result; |
|
125
|
|
|
|
|
|
|
} |
|
126
|
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
=head2 unsatisfied_message() |
|
128
|
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
The message showing a lacking call is acquired. |
|
130
|
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
=cut |
|
132
|
|
|
|
|
|
|
sub unsatisfied_message { |
|
133
|
2
|
|
|
2
|
1
|
4
|
my ($self) = @_; |
|
134
|
2
|
|
|
|
|
22
|
return sprintf( |
|
135
|
|
|
|
|
|
|
'%d calls of the `%s` method expected exist.', |
|
136
|
2
|
50
|
|
|
|
6
|
scalar(@{$self->{_results}}), |
|
137
|
|
|
|
|
|
|
$self->{_method} |
|
138
|
|
|
|
|
|
|
) if $self->has_result; |
|
139
|
|
|
|
|
|
|
|
|
140
|
0
|
|
|
|
|
|
return; |
|
141
|
|
|
|
|
|
|
} |
|
142
|
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
1; |