ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/COMP/SCRAM/src/Utilities/TestClass.pm
(Generate patch)

Comparing COMP/SCRAM/src/Utilities/TestClass.pm (file contents):
Revision 1.4 by williamc, Wed Sep 1 09:15:58 1999 UTC vs.
Revision 1.8 by williamc, Wed Jan 26 12:03:37 2000 UTC

# Line 9 | Line 9
9   # newtest() : Initiate a testing sequence
10   # verify(actual_result_file, expected_result_file) : compare two files
11   # verifydir(dir) : Check existence of the directory
12 + # verifyexists(file) : Verify the existence of file
13   # datadir([dir]) : return the current data directory (set it to dir if supplied)
14 < # ------------------- Private Methods ----------------------------------
14 > # testfail(string) : report that current test has failed
15 > # testpass(string) : report that current test has passed
16   # newfilename() : return a new filename that can be opened etc.
17   # temparea() : return a directory for building temporary stuff
18   # newobject(@args) : Set up a new object to be tested
19   # testinterface($name,@args) : perform interface tests for $name with @args
20   # expect(string) : tell the testinterface of any expected return values
21   # clearexpect()  : Reset any expect variables.
22 + #cleantemp()    : delete the temporary area
23  
24 < package TestClass;
24 > package Utilities::TestClass;
25   require 5.004;
26   $bold  = "\033[1m";
27   $normal = "\033[0m";
# Line 52 | Line 55 | sub new {
55          $self->{class}=$module;
56          $self->{"datadir"}=$datadir;
57          $self->{filenumber}=0;
58 <        $self->{temparea}="/tmp/SCRAMtest";
58 >        $self->{temparea}="/tmp/SCRAMtest++";
59          use File::Path;
60          mkpath ($self->{temparea},0, 0777);
61  
# Line 61 | Line 64 | sub new {
64          die $@ if $@;
65          $self->{testobj}=$module->_new($self, $fullmodule);
66  
67 +        # make sure the temparea is cleaned
68 +        use File::Path;
69 +        rmtree($self->temparea());
70 +
71          return $self;
72   }
73  
# Line 108 | Line 115 | sub verify {
115          open ( FILE1, "<$file1" ) or die "Cannot Read Test Output $file1 $!\n";
116          open ( FILE2, "<$file2" ) or die "Cannot Read Benchmark file ".
117                                                          "$file2 $!\n";
118 <        while ( $f1=<FILE1> ) {
119 <         $f2=<FILE2>;
120 <         if ( $f2 ne $f1 ) {
121 <           print "T:\n$f1\nB:$f2\n";
118 >        while ( $f1=<FILE2> ) {
119 >         $f2=<FILE1>;
120 >         if ( (!defined $f2 ) || ( ! defined $f1) || ($f2 ne $f1 )) {
121 >           #print "T:\n$f1\nB:$f2\n";
122             $same=0;
123           }
124          }
# Line 127 | Line 134 | sub verifydir {
134          my $name=shift;
135  
136          if ( -d "$name" ) {
137 <           $self->testpass("");
137 >           $self->testpass("Directory $name exists - test passed");
138          }
139          else {
140             $self->testfail("Directory $name does not exist");
141          }
142   }
143  
144 + sub verifyexists {
145 +        my $self=shift;
146 +        my $name=shift;
147 +
148 +        if ( -e "$name" ) {
149 +           $self->testpass("$name exists - test passed");
150 +        }
151 +        else {
152 +           $self->testfail("$name does not exist");
153 +        }
154 + }
155 +
156   sub testfail {
157          my $self=shift;
158          my $string=shift;
# Line 228 | Line 247 | sub testinterface {
247           @mylist=eval { $self->{object}->$subname(@_); };
248            die "Test Failed $@\n" if $@;
249           if ( defined @mylist ) {
250 +         # size check
251 +         if ( $#mylist < $#{$self->{expect}} ) {
252 +                $self->testfail("not enough returned values");
253 +         }
254           foreach $myreturn ( @mylist ) {
255            if ( ! defined $myreturn ) {
256                  print "Undefined Value Passed Back\n";
257            }
258 <          elsif ( \$myreturn=~/HASH/ ) {
259 <             print "Hash Refreturned\n";
258 >          elsif ( $myreturn=~/HASH/ ) {
259 >             print "Hash Ref ".ref($myreturn)." returned\n";
260            }
261 <          elsif ( \$myreturn=~/CODE/ ) {
261 >          elsif ( $myreturn=~/CODE/ ) {
262               print "Code Ref returned\n";
263            }
264 <          elsif ( \$myreturn=~/ARRAY/ ) {
264 >          elsif ( $myreturn=~/ARRAY/ ) {
265              print "Array Ref returned\n";
266            }
267            else {
# Line 265 | Line 288 | sub testinterface {
288   #
289   sub expect {
290          my $self=shift;
268        my $string=shift;
291  
292 <        push @{$self->{expect}}, $string;
292 >        push @{$self->{expect}}, @_;
293   }
294  
295   sub clearexpect {
# Line 365 | Line 387 | sub analyseInterface {
387          }
388          close SRCIN;
389   }
390 +
391 + sub cleantemp {
392 +        my $self=shift;
393 +        use File::Path;
394 +        rmtree($self->temparea());
395 + }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines