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