line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Test::FITesque::Fixture; |
2
|
|
|
|
|
|
|
|
3
|
6
|
|
|
6
|
|
9873
|
use strict; |
|
6
|
|
|
|
|
16
|
|
|
6
|
|
|
|
|
303
|
|
4
|
6
|
|
|
6
|
|
35
|
use warnings; |
|
6
|
|
|
|
|
13
|
|
|
6
|
|
|
|
|
161
|
|
5
|
|
|
|
|
|
|
|
6
|
6
|
|
|
6
|
|
6683
|
use attributes; |
|
6
|
|
|
|
|
15832
|
|
|
6
|
|
|
|
|
46
|
|
7
|
6
|
|
|
6
|
|
488
|
use base qw(Class::Data::Inheritable); |
|
6
|
|
|
|
|
14
|
|
|
6
|
|
|
|
|
9994
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
__PACKAGE__->mk_classdata(__ATTR_MAP => {}); |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
=pod |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
=head1 NAME |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
Test::FITesque::Fixture - Abstract calls for fixtures |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
=head1 SYNOPSIS |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
package Buddha::Fixture; |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
use strict; |
22
|
|
|
|
|
|
|
use warnings; |
23
|
|
|
|
|
|
|
use base qw(Test::FITesque::Fixture); |
24
|
|
|
|
|
|
|
use Test::More qw(); |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
sub click_on_button : Test { |
27
|
|
|
|
|
|
|
my ($self, @args) = @_; |
28
|
|
|
|
|
|
|
... |
29
|
|
|
|
|
|
|
ok(1); |
30
|
|
|
|
|
|
|
} |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
sub open_window : Test : Plan(3) { |
33
|
|
|
|
|
|
|
my ($self, @args) = @_; |
34
|
|
|
|
|
|
|
... |
35
|
|
|
|
|
|
|
ok(1); |
36
|
|
|
|
|
|
|
ok(2); |
37
|
|
|
|
|
|
|
ok(3); |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
=head1 DESCRIPTION |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
This module provides the base class for FITesque fixtures. It provides methods |
43
|
|
|
|
|
|
|
for the 'Test' and 'Plan' attributes along with some utility functions for |
44
|
|
|
|
|
|
|
L. |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
All methods for use as FITesque test methods must be marked with the 'Test' |
47
|
|
|
|
|
|
|
attribute. |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
The 'Plan' attribute states how many L functions the FITesque test |
50
|
|
|
|
|
|
|
method expects to run. If a method does not have the 'Plan' attribute set, it |
51
|
|
|
|
|
|
|
is implied that the test method will execute one L functions. |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
# Execute 10 Test::More functions |
54
|
|
|
|
|
|
|
sub test_method : Test : Plan(10) { |
55
|
|
|
|
|
|
|
... |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
# Just one this time |
59
|
|
|
|
|
|
|
sub test_method : Test { |
60
|
|
|
|
|
|
|
... |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
# not a test method |
64
|
|
|
|
|
|
|
sub normal_method { |
65
|
|
|
|
|
|
|
... |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
There are also 2 methods which may require overriding. The parse_method_string |
69
|
|
|
|
|
|
|
method returns a coderef of the method that relates to the method string |
70
|
|
|
|
|
|
|
used as the first element of a FITesque test row. |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
# get coderef for the 'click_on_buton' method of the fixture class |
73
|
|
|
|
|
|
|
my $coderef = $fixture->parse_method_string('click on button'); |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
The other method, 'parse_arguments' provides a hook in point to allow |
76
|
|
|
|
|
|
|
preprocessing on arguments to FITesque fixture test methods. This might be |
77
|
|
|
|
|
|
|
useful in case you want to design a domain specific langauge into your |
78
|
|
|
|
|
|
|
arguments. By default, this method just returns the arguments as is. |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
=head1 METHODS |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
=head2 new |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
my $fixture = Buddha::Fixture->new(); |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
Simple constructor |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
=cut |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
sub new { |
91
|
23
|
|
|
23
|
1
|
969
|
my ($class, $args) = @_; |
92
|
23
|
|
100
|
|
|
126
|
$args ||= {}; |
93
|
23
|
|
|
|
|
65
|
my $self = bless $args, $class; |
94
|
23
|
|
|
|
|
70
|
return $self; |
95
|
|
|
|
|
|
|
} |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
=head2 method_test_count |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
my $count = $fixture->method_test_count('foo'); |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
This returns the planned test count associated with the passed |
102
|
|
|
|
|
|
|
method name. |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
=cut |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
sub method_test_count { |
107
|
87
|
|
|
87
|
1
|
2781
|
my ($self, $string) = @_; |
108
|
87
|
|
|
|
|
218
|
my $coderef = $self->parse_method_string($string); |
109
|
|
|
|
|
|
|
|
110
|
87
|
100
|
|
|
|
250
|
return undef if !$coderef; |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
# use test methods first |
113
|
86
|
|
|
|
|
188
|
for my $meth (values %{ __PACKAGE__->__ATTR_MAP}){ |
|
86
|
|
|
|
|
278
|
|
114
|
182
|
100
|
|
|
|
1743
|
if($coderef == $meth->{coderef}){ |
115
|
75
|
|
100
|
|
|
553
|
return $meth->{count} || 1; |
116
|
|
|
|
|
|
|
} |
117
|
|
|
|
|
|
|
} |
118
|
|
|
|
|
|
|
|
119
|
11
|
|
|
|
|
77
|
return undef; |
120
|
|
|
|
|
|
|
} |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
=head2 parse_method_string |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
my $coderef = $fixture->parse_method_string('click on button'); |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
This method takes a string of text and attempts to return a coderef |
127
|
|
|
|
|
|
|
of a method within the fixture class. |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
=cut |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
sub parse_method_string { |
132
|
146
|
|
|
146
|
1
|
219
|
my ($self, $method_string) = @_; |
133
|
146
|
|
|
|
|
351
|
(my $method_name = $method_string) =~ s/\s+/_/g; |
134
|
|
|
|
|
|
|
|
135
|
146
|
|
|
|
|
495
|
my $coderef = $self->can($method_name); |
136
|
146
|
|
|
|
|
463
|
return $coderef; |
137
|
|
|
|
|
|
|
} |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
=head2 parse_arguments |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
my @arguments = $fixture->parse_arguments(qw(one two three)); |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
This method provides a way to preprocess arguments for methods before |
144
|
|
|
|
|
|
|
they are run. |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
=cut |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
sub parse_arguments { |
149
|
52
|
|
|
52
|
1
|
78
|
my $self = shift; |
150
|
52
|
|
|
|
|
177
|
return @_; |
151
|
|
|
|
|
|
|
} |
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
sub MODIFY_CODE_ATTRIBUTES { |
154
|
21
|
|
|
21
|
|
38258
|
my ($package, $coderef, @attrs) = @_; |
155
|
|
|
|
|
|
|
|
156
|
21
|
|
|
|
|
90
|
my $attr_info = { package => $package, coderef => $coderef }; |
157
|
21
|
|
|
|
|
41
|
my @not_recognised = (); |
158
|
21
|
|
|
|
|
99
|
while (my $attr = shift @attrs){ |
159
|
31
|
100
|
|
|
|
132
|
next if $attr eq 'Test'; |
160
|
11
|
100
|
|
|
|
87
|
if(my ($count) = $attr =~ /^Plan\((\d+)\)$/){ |
161
|
9
|
100
|
|
|
|
41
|
if($count > 0){ |
162
|
8
|
|
|
|
|
24
|
$attr_info->{count} = $count; |
163
|
8
|
|
|
|
|
62
|
next; |
164
|
|
|
|
|
|
|
} |
165
|
|
|
|
|
|
|
} |
166
|
3
|
|
|
|
|
15
|
push @not_recognised, $attr; |
167
|
|
|
|
|
|
|
} |
168
|
|
|
|
|
|
|
|
169
|
21
|
|
|
|
|
98
|
__PACKAGE__->__ATTR_MAP->{"$coderef"} = $attr_info; |
170
|
|
|
|
|
|
|
|
171
|
21
|
|
|
|
|
305
|
return @not_recognised; |
172
|
|
|
|
|
|
|
} |
173
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
=head1 AUTHORS |
175
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
Scott McWhirter, C<< >> |
177
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
=head1 COPYRIGHT & LICENSE |
179
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
Copyright 2007 Scott McWhirter, all rights reserved. |
181
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
This program is released under the following license: BSD. Please see the |
183
|
|
|
|
|
|
|
LICENSE file included in this distribution for details. |
184
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
=cut |
186
|
|
|
|
|
|
|
|
187
|
|
|
|
|
|
|
1; |