line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
#!/usr/bin/perl |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
package Goo::Thing::tpm::Tester; |
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
############################################################################### |
6
|
|
|
|
|
|
|
# Turbo10.com |
7
|
|
|
|
|
|
|
# |
8
|
|
|
|
|
|
|
# Copyright Nigel Hamilton 2005 |
9
|
|
|
|
|
|
|
# All Rights Reserved |
10
|
|
|
|
|
|
|
# |
11
|
|
|
|
|
|
|
# Author: Nigel Hamilton |
12
|
|
|
|
|
|
|
# Filename: Goo::Thing::tpm::Tester.pm |
13
|
|
|
|
|
|
|
# Description: Test things. |
14
|
|
|
|
|
|
|
# |
15
|
|
|
|
|
|
|
# Date Change |
16
|
|
|
|
|
|
|
# ----------------------------------------------------------------------------- |
17
|
|
|
|
|
|
|
# 08/02/2005 Auto generated file |
18
|
|
|
|
|
|
|
# 08/02/2005 Needed an automate test generator and suite |
19
|
|
|
|
|
|
|
# Encounter evil namespace clash when called "Test.pm" - decided |
20
|
|
|
|
|
|
|
# to rename it "Tester.pm" |
21
|
|
|
|
|
|
|
# 09/02/2005 Added prototype to test to stop slurpy array side effects |
22
|
|
|
|
|
|
|
# |
23
|
|
|
|
|
|
|
############################################################################### |
24
|
|
|
|
|
|
|
|
25
|
1
|
|
|
1
|
|
5930
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
30
|
|
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
#use Maths; |
28
|
1
|
|
|
1
|
|
5
|
use Goo::Object; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
17
|
|
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
# use Logger; |
31
|
1
|
|
|
1
|
|
4
|
use Goo::Prompter; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
21
|
|
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
# Test isa Object |
34
|
1
|
|
|
1
|
|
4
|
use base qw(Goo::Object); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
691
|
|
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
############################################################################### |
38
|
|
|
|
|
|
|
# |
39
|
|
|
|
|
|
|
# new - construct a goo object |
40
|
|
|
|
|
|
|
# |
41
|
|
|
|
|
|
|
############################################################################### |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
sub new { |
44
|
|
|
|
|
|
|
|
45
|
0
|
|
|
0
|
|
|
my ($class, $filename) = @_; |
46
|
|
|
|
|
|
|
|
47
|
0
|
|
|
|
|
|
my $this = $class->SUPER::new(); |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
# strip any suffix off the filename |
50
|
0
|
|
|
|
|
|
$filename =~ s/\.pm$//; |
51
|
|
|
|
|
|
|
|
52
|
0
|
|
|
|
|
|
$this->{name} = $filename; |
53
|
|
|
|
|
|
|
|
54
|
0
|
|
|
|
|
|
return $this; |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
############################################################################### |
60
|
|
|
|
|
|
|
# |
61
|
|
|
|
|
|
|
# do - executing the test - overridden by subclasses |
62
|
|
|
|
|
|
|
# |
63
|
|
|
|
|
|
|
############################################################################### |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
sub do { |
66
|
|
|
|
|
|
|
|
67
|
0
|
|
|
0
|
|
|
my ($this, $expression) = @_; |
68
|
|
|
|
|
|
|
|
69
|
0
|
|
|
|
|
|
Goo::Prompter::say("No tests to run"); |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
############################################################################### |
75
|
|
|
|
|
|
|
# |
76
|
|
|
|
|
|
|
# show - the result of a test |
77
|
|
|
|
|
|
|
# |
78
|
|
|
|
|
|
|
############################################################################### |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
sub show { |
81
|
|
|
|
|
|
|
|
82
|
0
|
|
|
0
|
|
|
my ($this, $test_expression, $description) = @_; |
83
|
|
|
|
|
|
|
|
84
|
0
|
|
|
|
|
|
Goo::Prompter::say("Test output is: <$test_expression>"); |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
} |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
############################################################################### |
90
|
|
|
|
|
|
|
# |
91
|
|
|
|
|
|
|
# ok - is the expression defined? |
92
|
|
|
|
|
|
|
# |
93
|
|
|
|
|
|
|
############################################################################### |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
sub ok { |
96
|
|
|
|
|
|
|
|
97
|
0
|
|
|
0
|
|
|
my ($this, $test_expression, $description) = @_; |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
# print $test_expression."\n"; |
100
|
|
|
|
|
|
|
|
101
|
0
|
0
|
|
|
|
|
if ($test_expression) { |
102
|
0
|
|
|
|
|
|
Goo::Prompter::say("ok - $description"); |
103
|
0
|
|
|
|
|
|
$this->{passcount}++; |
104
|
|
|
|
|
|
|
} else { |
105
|
0
|
|
|
|
|
|
Goo::Prompter::yell("[" . caller() . "] not ok - $description"); |
106
|
0
|
|
|
|
|
|
$this->{failcount}++; |
107
|
|
|
|
|
|
|
} |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
} |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
############################################################################### |
113
|
|
|
|
|
|
|
# |
114
|
|
|
|
|
|
|
# not_ok - the reverse of ok |
115
|
|
|
|
|
|
|
# |
116
|
|
|
|
|
|
|
############################################################################### |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
sub not_ok { |
119
|
|
|
|
|
|
|
|
120
|
0
|
|
|
0
|
|
|
my ($this, $test_expression, $description) = @_; |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
# print $test_expression."\n"; |
123
|
0
|
|
|
|
|
|
$this->ok(!$test_expression, $description); |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
} |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
############################################################################### |
129
|
|
|
|
|
|
|
# |
130
|
|
|
|
|
|
|
# is_array - is the expression defined? |
131
|
|
|
|
|
|
|
# |
132
|
|
|
|
|
|
|
############################################################################### |
133
|
|
|
|
|
|
|
|
134
|
0
|
|
|
0
|
|
|
sub is_array { |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
#my ($this, $thing, $description) = @_; |
137
|
|
|
|
|
|
|
# |
138
|
|
|
|
|
|
|
#return ref( |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
} |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
############################################################################### |
144
|
|
|
|
|
|
|
# |
145
|
|
|
|
|
|
|
# show_results - show the results of a test |
146
|
|
|
|
|
|
|
# |
147
|
|
|
|
|
|
|
############################################################################### |
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
sub show_results { |
150
|
|
|
|
|
|
|
|
151
|
0
|
|
|
0
|
|
|
my ($this) = @_; |
152
|
|
|
|
|
|
|
|
153
|
0
|
|
|
|
|
|
Goo::Prompter::say($this->get_results()); |
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
} |
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
############################################################################### |
159
|
|
|
|
|
|
|
# |
160
|
|
|
|
|
|
|
# get_results - show the results of the tests |
161
|
|
|
|
|
|
|
# |
162
|
|
|
|
|
|
|
############################################################################### |
163
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
sub get_results { |
165
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
my ($this) = @_; |
167
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
my $passed = $this->{passcount} || 0; |
169
|
|
|
|
|
|
|
my $failed = $this->{failcount} || 0; |
170
|
|
|
|
|
|
|
my $total = $passed + $failed; |
171
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
if ($total == 0) { |
173
|
|
|
|
|
|
|
return "No tests run."; |
174
|
|
|
|
|
|
|
} |
175
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
#my $percentage = Maths::get_percentage($passed, $total); |
177
|
|
|
|
|
|
|
#my $result = ($percentage == 100) ? "passed" : "failed"; |
178
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
return "$this->{name} $result: $passed passed, $failed failed."; |
180
|
|
|
|
|
|
|
} |
181
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
############################################################################### |
184
|
|
|
|
|
|
|
# |
185
|
|
|
|
|
|
|
# isa - check if a thing is a thing |
186
|
|
|
|
|
|
|
# |
187
|
|
|
|
|
|
|
############################################################################### |
188
|
|
|
|
|
|
|
|
189
|
|
|
|
|
|
|
#sub isa { |
190
|
|
|
|
|
|
|
# |
191
|
|
|
|
|
|
|
# my ($this, $object, $type) = @_; |
192
|
|
|
|
|
|
|
# |
193
|
|
|
|
|
|
|
# return $object->isa($type); |
194
|
|
|
|
|
|
|
# |
195
|
|
|
|
|
|
|
#} |
196
|
|
|
|
|
|
|
|
197
|
|
|
|
|
|
|
|
198
|
|
|
|
|
|
|
1; |
199
|
|
|
|
|
|
|
|
200
|
|
|
|
|
|
|
|
201
|
|
|
|
|
|
|
|
202
|
|
|
|
|
|
|
__END__ |
203
|
|
|
|
|
|
|
|
204
|
|
|
|
|
|
|
=head1 NAME |
205
|
|
|
|
|
|
|
|
206
|
|
|
|
|
|
|
Tester - Test things. |
207
|
|
|
|
|
|
|
|
208
|
|
|
|
|
|
|
=head1 SYNOPSIS |
209
|
|
|
|
|
|
|
|
210
|
|
|
|
|
|
|
use Tester; |
211
|
|
|
|
|
|
|
|
212
|
|
|
|
|
|
|
=head1 DESCRIPTION |
213
|
|
|
|
|
|
|
|
214
|
|
|
|
|
|
|
|
215
|
|
|
|
|
|
|
|
216
|
|
|
|
|
|
|
=head1 METHODS |
217
|
|
|
|
|
|
|
|
218
|
|
|
|
|
|
|
=over |
219
|
|
|
|
|
|
|
|
220
|
|
|
|
|
|
|
=item new |
221
|
|
|
|
|
|
|
|
222
|
|
|
|
|
|
|
construct a goo object |
223
|
|
|
|
|
|
|
|
224
|
|
|
|
|
|
|
=item do |
225
|
|
|
|
|
|
|
|
226
|
|
|
|
|
|
|
executing the test - overridden by subclasses |
227
|
|
|
|
|
|
|
|
228
|
|
|
|
|
|
|
=item show |
229
|
|
|
|
|
|
|
|
230
|
|
|
|
|
|
|
the result of a test |
231
|
|
|
|
|
|
|
|
232
|
|
|
|
|
|
|
=item ok |
233
|
|
|
|
|
|
|
|
234
|
|
|
|
|
|
|
is the expression defined? |
235
|
|
|
|
|
|
|
|
236
|
|
|
|
|
|
|
=item not_ok |
237
|
|
|
|
|
|
|
|
238
|
|
|
|
|
|
|
the reverse of ok |
239
|
|
|
|
|
|
|
|
240
|
|
|
|
|
|
|
=item is_array |
241
|
|
|
|
|
|
|
|
242
|
|
|
|
|
|
|
is the expression defined? |
243
|
|
|
|
|
|
|
|
244
|
|
|
|
|
|
|
=item show_results |
245
|
|
|
|
|
|
|
|
246
|
|
|
|
|
|
|
show the results of a test |
247
|
|
|
|
|
|
|
|
248
|
|
|
|
|
|
|
=item get_results |
249
|
|
|
|
|
|
|
|
250
|
|
|
|
|
|
|
show the results of the tests |
251
|
|
|
|
|
|
|
|
252
|
|
|
|
|
|
|
=item isa |
253
|
|
|
|
|
|
|
|
254
|
|
|
|
|
|
|
check if a thing is a thing |
255
|
|
|
|
|
|
|
|
256
|
|
|
|
|
|
|
|
257
|
|
|
|
|
|
|
=back |
258
|
|
|
|
|
|
|
|
259
|
|
|
|
|
|
|
=head1 AUTHOR |
260
|
|
|
|
|
|
|
|
261
|
|
|
|
|
|
|
Nigel Hamilton <nigel@turbo10.com> |
262
|
|
|
|
|
|
|
|
263
|
|
|
|
|
|
|
=head1 SEE ALSO |
264
|
|
|
|
|
|
|
|