| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
#!/usr/bin/perl |
|
2
|
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
package Goo::TestMaker; |
|
4
|
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
############################################################################### |
|
6
|
|
|
|
|
|
|
# Nigel Hamilton |
|
7
|
|
|
|
|
|
|
# |
|
8
|
|
|
|
|
|
|
# Copyright Nigel Hamilton 2003 |
|
9
|
|
|
|
|
|
|
# All Rights Reserved |
|
10
|
|
|
|
|
|
|
# |
|
11
|
|
|
|
|
|
|
# Author: Nigel Hamilton |
|
12
|
|
|
|
|
|
|
# Filename: Goo::TestMaker.pm |
|
13
|
|
|
|
|
|
|
# Description: Analyse program source and make test stubs add to the |
|
14
|
|
|
|
|
|
|
# testsuite |
|
15
|
|
|
|
|
|
|
# |
|
16
|
|
|
|
|
|
|
# Date Change |
|
17
|
|
|
|
|
|
|
# ----------------------------------------------------------------------------- |
|
18
|
|
|
|
|
|
|
# 14/08/2003 Version 1 |
|
19
|
|
|
|
|
|
|
# 06/02/2005 Returned to make more OO and usable - need to create a test |
|
20
|
|
|
|
|
|
|
# and check it into the test suite in one go! |
|
21
|
|
|
|
|
|
|
# 28/08/2005 Added method: run |
|
22
|
|
|
|
|
|
|
# 15/10/2005 Created test file: TestMakerTest.tpm |
|
23
|
|
|
|
|
|
|
# |
|
24
|
|
|
|
|
|
|
############################################################################### |
|
25
|
|
|
|
|
|
|
|
|
26
|
1
|
|
|
1
|
|
5094
|
use strict; |
|
|
1
|
|
|
|
|
3
|
|
|
|
1
|
|
|
|
|
36
|
|
|
27
|
|
|
|
|
|
|
|
|
28
|
1
|
|
|
1
|
|
6
|
use Cwd; # get the current directory getcwd() |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
72
|
|
|
29
|
1
|
|
|
1
|
|
6
|
use Goo::Date; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
41
|
|
|
30
|
1
|
|
|
1
|
|
6
|
use Goo::Object; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
22
|
|
|
31
|
1
|
|
|
1
|
|
7
|
use Goo::Template; # replace tokens into the code template |
|
|
1
|
|
|
|
|
3
|
|
|
|
1
|
|
|
|
|
35
|
|
|
32
|
1
|
|
|
1
|
|
7
|
use Goo::Prompter; # send out a message! |
|
|
1
|
|
|
|
|
3
|
|
|
|
1
|
|
|
|
|
26
|
|
|
33
|
1
|
|
|
1
|
|
5
|
use Goo::WebDBLite; # store the code templates in the CMS |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
28
|
|
|
34
|
1
|
|
|
1
|
|
7
|
use Goo::FileUtilities; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
25
|
|
|
35
|
1
|
|
|
1
|
|
480
|
use Goo::Thing::pm::ModuleDocumentor; # use the ModuleDocumentor for introspection |
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
use base qw(Object); |
|
38
|
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
############################################################################### |
|
41
|
|
|
|
|
|
|
# |
|
42
|
|
|
|
|
|
|
# format_signature - strip $this, and $class from the signature |
|
43
|
|
|
|
|
|
|
# |
|
44
|
|
|
|
|
|
|
############################################################################### |
|
45
|
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
sub format_signature { |
|
47
|
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
my ($this, $signature) = @_; |
|
49
|
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
# strip $this, or $class from the signature |
|
51
|
|
|
|
|
|
|
$signature =~ s/\$this//; |
|
52
|
|
|
|
|
|
|
$signature =~ s/\$class//; |
|
53
|
|
|
|
|
|
|
$signature =~ s/^\,//; # any leading , left over |
|
54
|
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
return $signature; |
|
56
|
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
} |
|
58
|
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
############################################################################### |
|
61
|
|
|
|
|
|
|
# |
|
62
|
|
|
|
|
|
|
# create_test_for_module - create a test file for a module |
|
63
|
|
|
|
|
|
|
# |
|
64
|
|
|
|
|
|
|
############################################################################### |
|
65
|
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
sub create_test_for_module { |
|
67
|
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
my $this = shift; |
|
69
|
|
|
|
|
|
|
my $full_path = shift; |
|
70
|
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
# match the path and filename |
|
72
|
|
|
|
|
|
|
$full_path =~ m/(.*)\/(.*)$/; |
|
73
|
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
# get the location and filename |
|
75
|
|
|
|
|
|
|
my $location = $1 || getcwd(); |
|
76
|
|
|
|
|
|
|
my $module_filename = $2 || $full_path; |
|
77
|
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
# Prompter::notify("full path === $full_path "); |
|
79
|
|
|
|
|
|
|
# create a test file name for this module |
|
80
|
|
|
|
|
|
|
$module_filename =~ m/(.*)\.(.*)$/; |
|
81
|
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
my $module_name = $1; |
|
83
|
|
|
|
|
|
|
my $test_module_name = $1 . "Test"; |
|
84
|
|
|
|
|
|
|
my $test_module_filename = $1 . "Test.tpm"; |
|
85
|
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
my $test_module_path = $location . "/test"; |
|
87
|
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
unless (-e $test_module_path) { |
|
89
|
|
|
|
|
|
|
mkdir $test_module_path; |
|
90
|
|
|
|
|
|
|
} |
|
91
|
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
$test_module_path .= "/" . $test_module_filename; |
|
93
|
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
# use the module documentor to do introspection |
|
95
|
|
|
|
|
|
|
my $documentor = Goo::Thing::pm::ModuleDocumentor->new($full_path); |
|
96
|
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
# need to check out signatures |
|
98
|
|
|
|
|
|
|
$documentor->calculate_method_signatures(); |
|
99
|
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
my $t = {}; |
|
101
|
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
$t->{name} = $test_module_name; |
|
103
|
|
|
|
|
|
|
$t->{program} = $module_filename; |
|
104
|
|
|
|
|
|
|
$t->{filename} = $test_module_filename; |
|
105
|
|
|
|
|
|
|
$t->{sourcefile} = $test_module_filename; |
|
106
|
|
|
|
|
|
|
$t->{shortmodulename} = lc(join("", $module_name =~ m/[A-Z]/g)); |
|
107
|
|
|
|
|
|
|
$t->{description} = $documentor->get_description(); |
|
108
|
|
|
|
|
|
|
$t->{constructorsignature} = $this->format_signature($documentor->get_method_signature("new")); |
|
109
|
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
# strip the suffix |
|
111
|
|
|
|
|
|
|
$t->{program} = $module_filename; |
|
112
|
|
|
|
|
|
|
$t->{module} = $module_name; |
|
113
|
|
|
|
|
|
|
$t->{date} = Goo::Date::get_current_date_with_slashes(); |
|
114
|
|
|
|
|
|
|
$t->{year} = Goo::Date::get_current_year(); |
|
115
|
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
foreach my $method ($documentor->get_methods()) { |
|
117
|
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
my $description = $documentor->get_method_description($method); |
|
119
|
|
|
|
|
|
|
my $signature = $this->format_signature($documentor->get_method_signature($method)); |
|
120
|
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
if ($method eq "new") { next; } |
|
122
|
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
if ($documentor->get_method_signature($method) =~ /\$this|\$class/) { |
|
124
|
|
|
|
|
|
|
$t->{methods} .= $this->get_oomethod($t, $method, $signature, $description); |
|
125
|
|
|
|
|
|
|
} else { |
|
126
|
|
|
|
|
|
|
$t->{methods} .= $this->get_class_method($t, $method, $signature, $description); |
|
127
|
|
|
|
|
|
|
} |
|
128
|
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
} |
|
130
|
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
my $template = $documentor->has_constructor() ? "testmodule-oo.tpl" : "testmodule.tpl"; |
|
133
|
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
my $test = Goo::Template::replace_tokens_in_string(Goo::WebDBLite::get_template($template), $t); |
|
135
|
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
Goo::FileUtilities::write_file($test_module_path, $test); |
|
137
|
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
#my $pc = PerlCoder->new( { filename => $test_module_path } ); |
|
139
|
|
|
|
|
|
|
#$pc->add_change_log("Test created for "); |
|
140
|
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
Goo::Prompter::yell("Test created: $test_module_path"); |
|
142
|
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
} |
|
144
|
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
############################################################################### |
|
147
|
|
|
|
|
|
|
# |
|
148
|
|
|
|
|
|
|
# get_class_method - return a test for an class/package method |
|
149
|
|
|
|
|
|
|
# |
|
150
|
|
|
|
|
|
|
############################################################################### |
|
151
|
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
sub get_class_method { |
|
153
|
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
my ($this, $tokens, $method, $signature, $description) = @_; |
|
155
|
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
return <<METHOD; |
|
157
|
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
\# $description |
|
159
|
|
|
|
|
|
|
\#\$this->ok($tokens->{module}\:\:$method($signature), "$description"); |
|
160
|
|
|
|
|
|
|
METHOD |
|
161
|
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
} |
|
163
|
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
############################################################################### |
|
166
|
|
|
|
|
|
|
# |
|
167
|
|
|
|
|
|
|
# get_oomethod - return a test for an oo method |
|
168
|
|
|
|
|
|
|
# |
|
169
|
|
|
|
|
|
|
############################################################################### |
|
170
|
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
sub get_oomethod { |
|
172
|
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
my ($this, $tokens, $method, $signature, $description) = @_; |
|
174
|
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
return <<METHOD; |
|
176
|
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
\# $description |
|
178
|
|
|
|
|
|
|
\#\$this->ok(\$$tokens->{shortmodulename}\->$method($signature), "$description"); |
|
179
|
|
|
|
|
|
|
METHOD |
|
180
|
|
|
|
|
|
|
|
|
181
|
|
|
|
|
|
|
} |
|
182
|
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
1; |
|
185
|
|
|
|
|
|
|
|
|
186
|
|
|
|
|
|
|
|
|
187
|
|
|
|
|
|
|
|
|
188
|
|
|
|
|
|
|
__END__ |
|
189
|
|
|
|
|
|
|
|
|
190
|
|
|
|
|
|
|
=head1 NAME |
|
191
|
|
|
|
|
|
|
|
|
192
|
|
|
|
|
|
|
Goo::TestMaker - Analyse program source and make test stubs add to the |
|
193
|
|
|
|
|
|
|
|
|
194
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
195
|
|
|
|
|
|
|
|
|
196
|
|
|
|
|
|
|
use Goo::TestMaker; |
|
197
|
|
|
|
|
|
|
|
|
198
|
|
|
|
|
|
|
=head1 DESCRIPTION |
|
199
|
|
|
|
|
|
|
|
|
200
|
|
|
|
|
|
|
|
|
201
|
|
|
|
|
|
|
|
|
202
|
|
|
|
|
|
|
=head1 METHODS |
|
203
|
|
|
|
|
|
|
|
|
204
|
|
|
|
|
|
|
=over |
|
205
|
|
|
|
|
|
|
|
|
206
|
|
|
|
|
|
|
=item format_signature |
|
207
|
|
|
|
|
|
|
|
|
208
|
|
|
|
|
|
|
strip $this, and $class from the signature |
|
209
|
|
|
|
|
|
|
|
|
210
|
|
|
|
|
|
|
=item create_test_for_module |
|
211
|
|
|
|
|
|
|
|
|
212
|
|
|
|
|
|
|
create a test file for a module |
|
213
|
|
|
|
|
|
|
|
|
214
|
|
|
|
|
|
|
=item get_class_method |
|
215
|
|
|
|
|
|
|
|
|
216
|
|
|
|
|
|
|
return a test for an class/package method |
|
217
|
|
|
|
|
|
|
|
|
218
|
|
|
|
|
|
|
=item get_oomethod |
|
219
|
|
|
|
|
|
|
|
|
220
|
|
|
|
|
|
|
return a test for an oo method |
|
221
|
|
|
|
|
|
|
|
|
222
|
|
|
|
|
|
|
|
|
223
|
|
|
|
|
|
|
=back |
|
224
|
|
|
|
|
|
|
|
|
225
|
|
|
|
|
|
|
=head1 AUTHOR |
|
226
|
|
|
|
|
|
|
|
|
227
|
|
|
|
|
|
|
Nigel Hamilton <nigel@turbo10.com> |
|
228
|
|
|
|
|
|
|
|
|
229
|
|
|
|
|
|
|
=head1 SEE ALSO |
|
230
|
|
|
|
|
|
|
|