1 |
williamc |
1.1 |
#
|
2 |
williamc |
1.2 |
# Build.pm test suite
|
3 |
williamc |
1.1 |
#
|
4 |
|
|
|
5 |
|
|
package BuildSystem::test::test_Build;
|
6 |
|
|
require 5.001;
|
7 |
|
|
use BuildSystem::Build;
|
8 |
|
|
use Configuration::ConfigArea;
|
9 |
|
|
|
10 |
|
|
@ISA=qw(Utilities::TestClass); #methods both from the test class
|
11 |
|
|
|
12 |
|
|
sub init {
|
13 |
|
|
my $self=shift;
|
14 |
|
|
$self->{testfile}=$self->datadir()."/BuildFileDoc";
|
15 |
|
|
|
16 |
|
|
# -- make a release area
|
17 |
williamc |
1.2 |
require BuildSystem::test::TestBuildArea;
|
18 |
|
|
$self->{tba}=BuildSystem::test::TestBuildArea->new($self->temparea(),
|
19 |
|
|
$self->datadir());
|
20 |
|
|
$self->{testarea}=$self->{tba}->releasearea();
|
21 |
williamc |
1.1 |
|
22 |
|
|
# -- make a dummy developer area
|
23 |
williamc |
1.2 |
($self->{testdevarea}, $self->{devconfigarea})=
|
24 |
|
|
$self->{tba}->developerarea($self->temparea());
|
25 |
|
|
|
26 |
|
|
|
27 |
|
|
$self->{twigstore}=$self->{testarea}->location()."/twigs";
|
28 |
|
|
$self->{devtwigstore}=$self->{testdevarea}->location()."/twigs";
|
29 |
williamc |
1.7 |
AddDir::adddir($self->{testdevarea}->location()."/".$self->{tba}->twigdir());
|
30 |
williamc |
1.2 |
print "Initialisation Complete\n";
|
31 |
williamc |
1.1 |
|
32 |
|
|
}
|
33 |
|
|
|
34 |
|
|
sub test {
|
35 |
|
|
my $self=shift;
|
36 |
|
|
$self->newtest("Initiation test - Release Area");
|
37 |
|
|
$self->newobject($self->{testarea});
|
38 |
|
|
$self->testinterface("verbosity",1);
|
39 |
|
|
|
40 |
|
|
# -- perform all basic build operations
|
41 |
williamc |
1.3 |
$self->_basicbuildoperations($self->{testarea}->location());
|
42 |
williamc |
1.1 |
|
43 |
|
|
# -- specific release behaviour tests
|
44 |
|
|
|
45 |
|
|
$self->newtest("Initiation test - Development Area");
|
46 |
|
|
$self->newobject($self->{testdevarea});
|
47 |
|
|
$self->testinterface("verbosity",1);
|
48 |
|
|
|
49 |
williamc |
1.7 |
# -- no changes to release area
|
50 |
|
|
my $twigdir=$self->{testdevarea}->location()."/".
|
51 |
|
|
$self->{tba}->twigdir();
|
52 |
|
|
my $twig="src/sub/twig";
|
53 |
|
|
my $twig1=$self->{devtwigstore}."/firsttwigdir.twig1";
|
54 |
|
|
my $sub="src/sub";
|
55 |
|
|
my $t1sr1=$twigdir."/a.twig1src";
|
56 |
|
|
my $t1sr2=$twigdir."/d.twig1src";
|
57 |
|
|
my $t1sr3=$twigdir."/e.twig1src";
|
58 |
|
|
|
59 |
|
|
$self->newtest("No Source code locally");
|
60 |
|
|
my $report=$self->testinterface("build",$twig);
|
61 |
|
|
$self->_buildOKtest($report);
|
62 |
|
|
|
63 |
|
|
# -- local area overrides
|
64 |
|
|
$self->newtest("Add new src files to satellite area");
|
65 |
|
|
my $newsrc=$self->datadir()."/testsrcs/devsrc/src";
|
66 |
|
|
AddDir::copydir($newsrc,$self->{testdevarea}->location()."/src");
|
67 |
|
|
$report=$self->testinterface("build",$twig,"echo_twig1src");
|
68 |
|
|
$self->_buildOKtest($report);
|
69 |
|
|
my $report=$self->testinterface("build",$twig);
|
70 |
|
|
$self->_buildOKtest($report);
|
71 |
|
|
sleep(1);
|
72 |
|
|
if ( ! $self->_twigupdated($twig1) ) {
|
73 |
|
|
$self->testfail("Failed to update twig1");
|
74 |
|
|
}
|
75 |
|
|
else {
|
76 |
|
|
$self->testpass("twig was updated");
|
77 |
|
|
$self->_testcontents($twig1,$t1sr1,$t1sr2,$t1sr3);
|
78 |
|
|
$self->_analysetwigdates($twig1,[($t1sr1,"update")],
|
79 |
|
|
[($t1sr2,"update")], [($t1sr3,"update")]);
|
80 |
|
|
}
|
81 |
williamc |
1.1 |
|
82 |
|
|
$self->newtest("Change local configuration");
|
83 |
|
|
$self->testfail("not implemented");
|
84 |
|
|
|
85 |
williamc |
1.7 |
$newsrc=$self->datadir()."/testsrcs/src";
|
86 |
|
|
AddDir::copydir($newsrc,$self->{testdevarea}->location()."/src");
|
87 |
|
|
unlink $t1sr2;
|
88 |
|
|
unlink $t1sr3;
|
89 |
|
|
$self->_basicbuildoperations($self->{testdevarea}->location());
|
90 |
williamc |
1.1 |
}
|
91 |
|
|
|
92 |
|
|
# -- support routines
|
93 |
|
|
|
94 |
|
|
sub _basicbuildoperations {
|
95 |
|
|
my $self=shift;
|
96 |
|
|
my $topdir=shift;
|
97 |
|
|
my $report;
|
98 |
|
|
|
99 |
|
|
# -- build from invalid directory
|
100 |
williamc |
1.7 |
$self->{twigs}={};
|
101 |
|
|
$self->{twigfiles}={};
|
102 |
williamc |
1.3 |
my $twigdir=$topdir."/".$self->{tba}->twigdir();
|
103 |
williamc |
1.1 |
$self->newtest("build from invalid directory");
|
104 |
|
|
$report=$self->testinterface("build",$self->{configurationareadir});
|
105 |
williamc |
1.7 |
$self->testswitch(!$report->status(),
|
106 |
|
|
"Build Returned Fail as expected", "Build Returned OK");
|
107 |
williamc |
1.1 |
|
108 |
|
|
# -- default build from twig in src tree
|
109 |
williamc |
1.2 |
$self->newtest("echo internal variables");
|
110 |
|
|
my $twig="src/sub/twig";
|
111 |
williamc |
1.7 |
my $sub="src/sub";
|
112 |
williamc |
1.2 |
$report=$self->testinterface("build",$twig,"echo_Class");
|
113 |
|
|
$self->_buildOKtest($report);
|
114 |
|
|
$report=$self->testinterface("build",$twig,"echo_twigname");
|
115 |
|
|
$self->_buildOKtest($report);
|
116 |
|
|
$report=$self->testinterface("build",$twig,"echo_twig1src");
|
117 |
|
|
$self->_buildOKtest($report);
|
118 |
|
|
|
119 |
williamc |
1.1 |
$self->newtest("default build from twig - configuration setup");
|
120 |
|
|
$report=$self->testinterface("build",$twig);
|
121 |
|
|
$self->_buildOKtest($report);
|
122 |
williamc |
1.7 |
my $twig1=$topdir."/twigs/firsttwigdir.twig1";
|
123 |
|
|
my $twig2=$topdir."/twigs/firsttwigdir.twig2";
|
124 |
williamc |
1.3 |
my $t1sr1=$twigdir."/a.twig1src";
|
125 |
|
|
my $t1sr2=$twigdir."/b.twig1src";
|
126 |
|
|
my $t1sr3=$twigdir."/c.twig1src";
|
127 |
williamc |
1.7 |
sleep(1);
|
128 |
williamc |
1.2 |
if ( ! $self->_twigupdated($twig1) ) {
|
129 |
|
|
$self->testfail("Failed to update twig1");
|
130 |
williamc |
1.1 |
}
|
131 |
|
|
else {
|
132 |
williamc |
1.3 |
$self->testpass("twig was updated");
|
133 |
williamc |
1.4 |
$self->_testcontents($twig1,$t1sr1,$t1sr2,$t1sr3);
|
134 |
|
|
$self->_analysetwigdates($twig1,[($t1sr1,"update")],
|
135 |
|
|
[($t1sr2,"update")], [($t1sr3,"update")]);
|
136 |
williamc |
1.2 |
}
|
137 |
williamc |
1.4 |
my $t2sr1=$twigdir."/a.twig2src";
|
138 |
williamc |
1.2 |
if ( ! $self->_twigupdated($twig2) ) {
|
139 |
|
|
$self->testfail("Failed to update twig2");
|
140 |
williamc |
1.1 |
}
|
141 |
|
|
else {
|
142 |
williamc |
1.4 |
$self->testpass("twig was updated");
|
143 |
williamc |
1.2 |
$self->_testcontents($twig2,$t2sr1);
|
144 |
williamc |
1.3 |
$self->_analysetwigdates($twig2,[$t2sr1,"update"]);
|
145 |
williamc |
1.1 |
}
|
146 |
williamc |
1.4 |
|
147 |
|
|
# -- rerun - no build should take place
|
148 |
|
|
$self->newtest("default build from twig - rerun");
|
149 |
|
|
$report=$self->testinterface("build",$twig,"DEBUG=true");
|
150 |
|
|
$self->_buildOKtest($report);
|
151 |
|
|
if ( $self->_twigupdated($twig1) ) {
|
152 |
|
|
$self->testfail("Failed - update to twig1 has happened");
|
153 |
|
|
}
|
154 |
|
|
$self->_analysetwigdates($twig1,[($t1sr1,"no update")],
|
155 |
|
|
[($t1sr2,"no update")], [($t1sr3,"no update")]);
|
156 |
|
|
|
157 |
|
|
# -- date change on src files
|
158 |
|
|
$self->newtest("date change on src files");
|
159 |
williamc |
1.5 |
my ($atime,$mtime)=(stat($t1sr1))[8,9];
|
160 |
|
|
$mtime--;
|
161 |
|
|
utime($atime,$mtime, $t1sr1);
|
162 |
|
|
|
163 |
williamc |
1.4 |
$report=$self->testinterface("build",$twig);
|
164 |
|
|
$self->_buildOKtest($report);
|
165 |
|
|
if ( ! $self->_twigupdated($twig1) ) {
|
166 |
|
|
$self->testfail("Failed - no update to twig1 has happened");
|
167 |
|
|
}
|
168 |
|
|
$self->_testcontents($twig1,$t1sr1,$t1sr2,$t1sr3);
|
169 |
|
|
$self->_analysetwigdates($twig1,[($t1sr1,"update")],
|
170 |
|
|
[($t1sr2,"no update")], [($t1sr3,"no update")]);
|
171 |
williamc |
1.7 |
if ( $self->_twigupdated($twig2) ) {
|
172 |
|
|
$self->testfail("Failed - update to twig2 has happened");
|
173 |
|
|
}
|
174 |
williamc |
1.1 |
|
175 |
|
|
# -- remove some source files
|
176 |
|
|
$self->newtest("partial src file removal");
|
177 |
williamc |
1.7 |
my $tempfile=$self->temparea()."/".$self->newfilename();
|
178 |
|
|
rename($t1sr3,$tempfile);
|
179 |
|
|
$report=$self->testinterface("build",$twig);
|
180 |
|
|
$self->_buildOKtest($report);
|
181 |
|
|
if ( ! $self->_twigupdated($twig1) ) {
|
182 |
|
|
$self->testfail("Failed - no update to twig1 has happened");
|
183 |
|
|
}
|
184 |
|
|
$self->_testcontents($twig1,$t1sr1,$t1sr2);
|
185 |
|
|
$self->_analysetwigdates($twig1,[($t1sr1,"no update")],
|
186 |
|
|
[($t1sr2,"no update")]);
|
187 |
|
|
if ( $self->_twigupdated($twig2) ) {
|
188 |
|
|
$self->testfail("Failed - update to twig2 has happened");
|
189 |
|
|
}
|
190 |
williamc |
1.1 |
|
191 |
williamc |
1.7 |
# -- add some source files
|
192 |
|
|
$self->newtest("add a new src file");
|
193 |
|
|
rename($tempfile,$t1sr3);
|
194 |
|
|
delete $self->{twigfiles}{$t1sr3};
|
195 |
|
|
$self->{twigs}{$t1sr3}="";
|
196 |
|
|
$report=$self->testinterface("build",$twig);
|
197 |
|
|
$self->_buildOKtest($report);
|
198 |
|
|
if ( ! $self->_twigupdated($twig1) ) {
|
199 |
|
|
$self->testfail("Failed - no update to twig1 has happened");
|
200 |
|
|
}
|
201 |
|
|
$self->_testcontents($twig1,$t1sr1,$t1sr2,$t1sr3);
|
202 |
|
|
$self->_analysetwigdates($twig1,[($t1sr1,"no update")],
|
203 |
|
|
[($t1sr2,"no update")], [($t1sr3,"update")]);
|
204 |
williamc |
1.1 |
|
205 |
|
|
# -- build from sub - recursive
|
206 |
williamc |
1.7 |
$self->newtest("build from sublevel - check recursion mechanism");
|
207 |
|
|
($atime,$mtime)=(stat($t1sr1))[8,9];
|
208 |
|
|
$mtime++;
|
209 |
|
|
utime($atime,$mtime, $t1sr1);
|
210 |
|
|
sleep(1);
|
211 |
|
|
$report=$self->testinterface("build",$sub);
|
212 |
|
|
$self->_buildOKtest($report);
|
213 |
|
|
if ( ! $self->_twigupdated($twig1) ) {
|
214 |
|
|
$self->testfail("Failed - no update to twig1 has happened");
|
215 |
|
|
}
|
216 |
williamc |
1.2 |
|
217 |
williamc |
1.7 |
# -- directory associated with no class
|
218 |
williamc |
1.2 |
$self->newtest("default build from unassigned class below twig");
|
219 |
williamc |
1.7 |
($atime,$mtime)=(stat($t1sr1))[8,9];
|
220 |
|
|
$mtime++;
|
221 |
|
|
utime($atime,$mtime, $t1sr1);
|
222 |
|
|
sleep(1);
|
223 |
|
|
$report=$self->testinterface("build",$twig."/noclass");
|
224 |
|
|
$self->_buildOKtest($report);
|
225 |
|
|
if ( ! $self->_twigupdated($twig1) ) {
|
226 |
|
|
$self->testfail("Failed - no update to twig1 has happened");
|
227 |
|
|
}
|
228 |
williamc |
1.1 |
}
|
229 |
|
|
|
230 |
|
|
sub _buildOKtest {
|
231 |
|
|
my $self=shift;
|
232 |
|
|
my $report=shift;
|
233 |
|
|
|
234 |
|
|
my @errors=$report->error();
|
235 |
williamc |
1.2 |
$self->testswitch($report->status(),"Build Returned OK",
|
236 |
williamc |
1.1 |
"Build Returned Fail (@errors)");
|
237 |
|
|
}
|
238 |
|
|
|
239 |
|
|
sub _twigupdated {
|
240 |
|
|
my $self=shift;
|
241 |
|
|
my $name=shift;
|
242 |
|
|
|
243 |
williamc |
1.7 |
sleep(1); # let the build finnish!
|
244 |
williamc |
1.2 |
my $twigfile=$name;
|
245 |
williamc |
1.1 |
my $updated=0;
|
246 |
williamc |
1.2 |
if ( ! -f $twigfile ) {
|
247 |
williamc |
1.1 |
$self->testfail("$twigfile not created - test failed");
|
248 |
|
|
}
|
249 |
|
|
else {
|
250 |
|
|
# -- get twig datestamp
|
251 |
williamc |
1.6 |
my $twigdatestamp=(stat($twigfile))[9];
|
252 |
williamc |
1.1 |
if ( defined $self->{twigs}{$name} ) {
|
253 |
|
|
if ($self->{twigs}{$name} ne $twigdatestamp ) {
|
254 |
|
|
$updated=1;
|
255 |
|
|
}
|
256 |
williamc |
1.7 |
print "Dates :- ".$self->{twigs}{$name}." ".$twigdatestamp."\n";
|
257 |
williamc |
1.1 |
}
|
258 |
|
|
else {
|
259 |
|
|
# twig must be new
|
260 |
|
|
$updated=1;
|
261 |
|
|
}
|
262 |
|
|
$self->{twigs}{$name}=$twigdatestamp;
|
263 |
|
|
}
|
264 |
williamc |
1.2 |
return $updated;
|
265 |
williamc |
1.1 |
}
|
266 |
|
|
|
267 |
|
|
#
|
268 |
|
|
# expects an array of array pairs
|
269 |
|
|
# ((file,"update"),(file,"no-update")
|
270 |
williamc |
1.2 |
sub _analysetwigdates {
|
271 |
williamc |
1.1 |
my $self=shift;
|
272 |
williamc |
1.4 |
my $twigfile=shift;
|
273 |
williamc |
1.1 |
|
274 |
|
|
my $twig=BuildSystem::test::twigmaker->new($twigfile);
|
275 |
|
|
|
276 |
|
|
# -- check input dates
|
277 |
|
|
foreach $file ( @_ ) {
|
278 |
|
|
# -- do we want it updated
|
279 |
williamc |
1.4 |
if ( $$file[1]=~/^update/i ) {
|
280 |
|
|
if ( ( defined $self->{twigfiles}{$$file[0]} ) &&
|
281 |
|
|
( $twig->filedate($$file[0]) eq $self->{twigfiles}{$$file[0]} )) {
|
282 |
williamc |
1.7 |
$self->testfail($$file[0]." not updated ".
|
283 |
|
|
"(".$twig->filedate($$file[0]).
|
284 |
|
|
" ".$self->{twigfiles}{$$file[0]}.") - test failed");
|
285 |
williamc |
1.4 |
}
|
286 |
|
|
else {
|
287 |
|
|
$self->testpass("updated version of $$file[0] as expected");
|
288 |
williamc |
1.1 |
}
|
289 |
williamc |
1.4 |
$self->{twigfiles}{$$file[0]}=$twig->filedate($file[0]);
|
290 |
williamc |
1.1 |
}
|
291 |
|
|
else {
|
292 |
williamc |
1.4 |
if ( ( ! defined $self->{twigfiles}{$$file[0]} ) ||
|
293 |
|
|
( $twig->filedate($$file[0]) ne $self->{twigfiles}{$$file[0]} )) {
|
294 |
|
|
$self->testfail($$file[0]." updated - test failed ".
|
295 |
|
|
"(was ".$twig->filedate($$file[0])." now "
|
296 |
|
|
.$self->{twigfiles}{$$file[0]}.")" );
|
297 |
williamc |
1.1 |
}
|
298 |
williamc |
1.4 |
else {
|
299 |
|
|
$self->testpass("Same version of $$file[0] as before as expected");
|
300 |
|
|
}
|
301 |
williamc |
1.1 |
}
|
302 |
williamc |
1.4 |
$self->{twigfiles}{$$file[0]}=$twig->filedate($$file[0]);
|
303 |
williamc |
1.1 |
}
|
304 |
|
|
}
|
305 |
|
|
|
306 |
williamc |
1.2 |
sub _testcontents {
|
307 |
|
|
my $self=shift;
|
308 |
|
|
my $twig=shift;
|
309 |
|
|
|
310 |
williamc |
1.4 |
my @expect=@_;
|
311 |
williamc |
1.2 |
use BuildSystem::test::twigmaker;
|
312 |
|
|
my $twigobject=BuildSystem::test::twigmaker->new($twig);
|
313 |
|
|
print "Checking contents of $twig\n";
|
314 |
|
|
my @objs=$twigobject->contents();
|
315 |
williamc |
1.4 |
$self->cmparray(\@objs,@expect);
|
316 |
williamc |
1.2 |
}
|
317 |
williamc |
1.1 |
# === dummy routines
|