line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Test::FITesque::Fixture; |
2
|
|
|
|
|
|
|
|
3
|
6
|
|
|
6
|
|
4780
|
use strict; |
|
6
|
|
|
|
|
6
|
|
|
6
|
|
|
|
|
152
|
|
4
|
6
|
|
|
6
|
|
19
|
use warnings; |
|
6
|
|
|
|
|
5
|
|
|
6
|
|
|
|
|
103
|
|
5
|
|
|
|
|
|
|
|
6
|
6
|
|
|
6
|
|
2625
|
use attributes; |
|
6
|
|
|
|
|
5209
|
|
|
6
|
|
|
|
|
21
|
|
7
|
6
|
|
|
6
|
|
266
|
use base qw(Class::Data::Inheritable); |
|
6
|
|
|
|
|
7
|
|
|
6
|
|
|
|
|
2636
|
|
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
|
373
|
my ($class, $args) = @_; |
92
|
23
|
|
100
|
|
|
78
|
$args ||= {}; |
93
|
23
|
|
|
|
|
33
|
my $self = bless $args, $class; |
94
|
23
|
|
|
|
|
35
|
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
|
78
|
|
|
78
|
1
|
772
|
my ($self, $string) = @_; |
108
|
78
|
|
|
|
|
106
|
my $coderef = $self->parse_method_string($string); |
109
|
|
|
|
|
|
|
|
110
|
78
|
100
|
|
|
|
138
|
return undef if !$coderef; |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
# use test methods first |
113
|
77
|
|
|
|
|
54
|
for my $meth (values %{ __PACKAGE__->__ATTR_MAP}){ |
|
77
|
|
|
|
|
435
|
|
114
|
172
|
100
|
|
|
|
629
|
if($coderef == $meth->{coderef}){ |
115
|
66
|
|
100
|
|
|
271
|
return $meth->{count} || 1; |
116
|
|
|
|
|
|
|
} |
117
|
|
|
|
|
|
|
} |
118
|
|
|
|
|
|
|
|
119
|
11
|
|
|
|
|
40
|
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
|
137
|
|
|
137
|
1
|
115
|
my ($self, $method_string) = @_; |
133
|
137
|
|
|
|
|
187
|
(my $method_name = $method_string) =~ s/\s+/_/g; |
134
|
|
|
|
|
|
|
|
135
|
137
|
|
|
|
|
283
|
my $coderef = $self->can($method_name); |
136
|
137
|
|
|
|
|
230
|
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
|
45
|
my $self = shift; |
150
|
52
|
|
|
|
|
88
|
return @_; |
151
|
|
|
|
|
|
|
} |
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
sub MODIFY_CODE_ATTRIBUTES { |
154
|
21
|
|
|
21
|
|
6352
|
my ($package, $coderef, @attrs) = @_; |
155
|
|
|
|
|
|
|
|
156
|
21
|
|
|
|
|
54
|
my $attr_info = { package => $package, coderef => $coderef }; |
157
|
21
|
|
|
|
|
22
|
my @not_recognised = (); |
158
|
21
|
|
|
|
|
48
|
while (my $attr = shift @attrs){ |
159
|
31
|
100
|
|
|
|
75
|
next if $attr eq 'Test'; |
160
|
11
|
100
|
|
|
|
49
|
if(my ($count) = $attr =~ /^Plan\((\d+)\)$/){ |
161
|
9
|
100
|
|
|
|
21
|
if($count > 0){ |
162
|
8
|
|
|
|
|
14
|
$attr_info->{count} = $count; |
163
|
8
|
|
|
|
|
32
|
next; |
164
|
|
|
|
|
|
|
} |
165
|
|
|
|
|
|
|
} |
166
|
3
|
|
|
|
|
7
|
push @not_recognised, $attr; |
167
|
|
|
|
|
|
|
} |
168
|
|
|
|
|
|
|
|
169
|
21
|
|
|
|
|
55
|
__PACKAGE__->__ATTR_MAP->{"$coderef"} = $attr_info; |
170
|
|
|
|
|
|
|
|
171
|
21
|
|
|
|
|
151
|
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; |