ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/COMP/SCRAM/src/BuildSystem/test/test_Build.pm
Revision: 1.9
Committed: Fri Sep 29 14:05:39 2000 UTC (24 years, 7 months ago) by williamc
Content type: text/plain
Branch: MAIN
CVS Tags: v102p1, V1_0_1, V1_0_0, V1_pre0, SCRAM_V1, SCRAMV1_IMPORT, V0_19_7, V0_19_6, V0_19_6p1, V0_19_5, SFATEST, V0_19_4, V0_19_4_pre3, V0_19_4_pre2, V0_19_4_pre1, V0_19_3, V0_19_2, V0_19_1, V0_19_0, V0_18_5, V0_18_4, V0_18_2, V0_18_1
Branch point for: V1_pre1, SCRAM_V1_BRANCH, V0_19_4_B, V0_16branch
Changes since 1.8: +5 -3 lines
Log Message:
Still one bug left - but its been there a long time

File Contents

# User Rev Content
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 williamc 1.9 use BuildSystem::test::twigmaker;
9 williamc 1.1 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 williamc 1.2 require BuildSystem::test::TestBuildArea;
19     $self->{tba}=BuildSystem::test::TestBuildArea->new($self->temparea(),
20     $self->datadir());
21     $self->{testarea}=$self->{tba}->releasearea();
22 williamc 1.1
23     # -- make a dummy developer area
24 williamc 1.2 ($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 williamc 1.7 AddDir::adddir($self->{testdevarea}->location()."/".$self->{tba}->twigdir());
31 williamc 1.2 print "Initialisation Complete\n";
32 williamc 1.1
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 williamc 1.3 $self->_basicbuildoperations($self->{testarea}->location());
43 williamc 1.1
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 williamc 1.7 # -- 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 williamc 1.9 if ( ! $self->_twigupdated($twig1) ) {
64     $self->testfail("Failed to update twig1");
65     }
66 williamc 1.7
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 williamc 1.1
85     $self->newtest("Change local configuration");
86     $self->testfail("not implemented");
87    
88 williamc 1.7 $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 williamc 1.1 }
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 williamc 1.7 $self->{twigs}={};
104     $self->{twigfiles}={};
105 williamc 1.3 my $twigdir=$topdir."/".$self->{tba}->twigdir();
106 williamc 1.1 $self->newtest("build from invalid directory");
107     $report=$self->testinterface("build",$self->{configurationareadir});
108 williamc 1.7 $self->testswitch(!$report->status(),
109     "Build Returned Fail as expected", "Build Returned OK");
110 williamc 1.1
111     # -- default build from twig in src tree
112 williamc 1.2 $self->newtest("echo internal variables");
113     my $twig="src/sub/twig";
114 williamc 1.7 my $sub="src/sub";
115 williamc 1.2 $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 williamc 1.1 $self->newtest("default build from twig - configuration setup");
123     $report=$self->testinterface("build",$twig);
124     $self->_buildOKtest($report);
125 williamc 1.7 my $twig1=$topdir."/twigs/firsttwigdir.twig1";
126     my $twig2=$topdir."/twigs/firsttwigdir.twig2";
127 williamc 1.3 my $t1sr1=$twigdir."/a.twig1src";
128     my $t1sr2=$twigdir."/b.twig1src";
129     my $t1sr3=$twigdir."/c.twig1src";
130 williamc 1.7 sleep(1);
131 williamc 1.2 if ( ! $self->_twigupdated($twig1) ) {
132     $self->testfail("Failed to update twig1");
133 williamc 1.1 }
134     else {
135 williamc 1.3 $self->testpass("twig was updated");
136 williamc 1.4 $self->_testcontents($twig1,$t1sr1,$t1sr2,$t1sr3);
137     $self->_analysetwigdates($twig1,[($t1sr1,"update")],
138 williamc 1.8 [($t1sr2,"update")], [($t1sr3,"update")]);
139 williamc 1.2 }
140 williamc 1.4 my $t2sr1=$twigdir."/a.twig2src";
141 williamc 1.2 if ( ! $self->_twigupdated($twig2) ) {
142     $self->testfail("Failed to update twig2");
143 williamc 1.1 }
144     else {
145 williamc 1.4 $self->testpass("twig was updated");
146 williamc 1.2 $self->_testcontents($twig2,$t2sr1);
147 williamc 1.3 $self->_analysetwigdates($twig2,[$t2sr1,"update"]);
148 williamc 1.1 }
149 williamc 1.4
150     # -- rerun - no build should take place
151 williamc 1.8 sleep(1);
152     #if ( $self->{xxx}==1 ) { exit; } else { $self->{xxx}=1;}
153 williamc 1.4 $self->newtest("default build from twig - rerun");
154 williamc 1.8 $report=$self->testinterface("build",$twig);
155 williamc 1.4 $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 williamc 1.8 [($t1sr2,"no update")], [($t1sr3,"no update")]);
161 williamc 1.4
162     # -- date change on src files
163     $self->newtest("date change on src files");
164 williamc 1.5 my ($atime,$mtime)=(stat($t1sr1))[8,9];
165     $mtime--;
166     utime($atime,$mtime, $t1sr1);
167    
168 williamc 1.4 $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 williamc 1.7 if ( $self->_twigupdated($twig2) ) {
177     $self->testfail("Failed - update to twig2 has happened");
178     }
179 williamc 1.1
180     # -- remove some source files
181     $self->newtest("partial src file removal");
182 williamc 1.7 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 williamc 1.1
196 williamc 1.7 # -- 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 williamc 1.9 $report=$self->testinterface("build",$twig,"-d");
202 williamc 1.7 $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 williamc 1.1
210     # -- build from sub - recursive
211 williamc 1.7 $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 williamc 1.2
222 williamc 1.7 # -- directory associated with no class
223 williamc 1.2 $self->newtest("default build from unassigned class below twig");
224 williamc 1.7 ($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 williamc 1.1 }
234    
235     sub _buildOKtest {
236     my $self=shift;
237     my $report=shift;
238    
239     my @errors=$report->error();
240 williamc 1.2 $self->testswitch($report->status(),"Build Returned OK",
241 williamc 1.1 "Build Returned Fail (@errors)");
242     }
243    
244     sub _twigupdated {
245     my $self=shift;
246     my $name=shift;
247    
248 williamc 1.7 sleep(1); # let the build finnish!
249 williamc 1.2 my $twigfile=$name;
250 williamc 1.1 my $updated=0;
251 williamc 1.2 if ( ! -f $twigfile ) {
252 williamc 1.1 $self->testfail("$twigfile not created - test failed");
253     }
254     else {
255     # -- get twig datestamp
256 williamc 1.6 my $twigdatestamp=(stat($twigfile))[9];
257 williamc 1.1 if ( defined $self->{twigs}{$name} ) {
258     if ($self->{twigs}{$name} ne $twigdatestamp ) {
259     $updated=1;
260     }
261 williamc 1.7 print "Dates :- ".$self->{twigs}{$name}." ".$twigdatestamp."\n";
262 williamc 1.1 }
263     else {
264     # twig must be new
265     $updated=1;
266     }
267     $self->{twigs}{$name}=$twigdatestamp;
268     }
269 williamc 1.2 return $updated;
270 williamc 1.1 }
271    
272     #
273     # expects an array of array pairs
274     # ((file,"update"),(file,"no-update")
275 williamc 1.2 sub _analysetwigdates {
276 williamc 1.1 my $self=shift;
277 williamc 1.4 my $twigfile=shift;
278 williamc 1.1
279     my $twig=BuildSystem::test::twigmaker->new($twigfile);
280    
281     # -- check input dates
282     foreach $file ( @_ ) {
283     # -- do we want it updated
284 williamc 1.4 if ( $$file[1]=~/^update/i ) {
285     if ( ( defined $self->{twigfiles}{$$file[0]} ) &&
286     ( $twig->filedate($$file[0]) eq $self->{twigfiles}{$$file[0]} )) {
287 williamc 1.7 $self->testfail($$file[0]." not updated ".
288     "(".$twig->filedate($$file[0]).
289     " ".$self->{twigfiles}{$$file[0]}.") - test failed");
290 williamc 1.4 }
291     else {
292     $self->testpass("updated version of $$file[0] as expected");
293 williamc 1.1 }
294 williamc 1.4 $self->{twigfiles}{$$file[0]}=$twig->filedate($file[0]);
295 williamc 1.1 }
296     else {
297 williamc 1.4 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 williamc 1.1 }
303 williamc 1.4 else {
304     $self->testpass("Same version of $$file[0] as before as expected");
305     }
306 williamc 1.1 }
307 williamc 1.4 $self->{twigfiles}{$$file[0]}=$twig->filedate($$file[0]);
308 williamc 1.1 }
309     }
310    
311 williamc 1.2 sub _testcontents {
312     my $self=shift;
313     my $twig=shift;
314    
315 williamc 1.4 my @expect=@_;
316 williamc 1.2 my $twigobject=BuildSystem::test::twigmaker->new($twig);
317     print "Checking contents of $twig\n";
318     my @objs=$twigobject->contents();
319 williamc 1.4 $self->cmparray(\@objs,@expect);
320 williamc 1.2 }
321 williamc 1.1 # === dummy routines