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.3 by williamc, Fri Jul 2 16:36:12 1999 UTC vs.
Revision 1.6 by williamc, Fri Dec 17 10:10:36 1999 UTC

# Line 3 | Line 3
3   #
4   # Interface
5   # ---------
6 < # new($module,testdatadir,project) : module example - Utilities/urlhandler
6 > # new($module,testdatadir) : module example - Utilities/urlhandler
7   # dotest(@args) : Start testing - arguments dependent on inheriting class
8   #
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;
25   require 5.004;
# Line 29 | Line 32 | sub new {
32          my $fullmodule=shift;
33          chomp $fullmodule;
34          my $datadir=shift;
32        my $project=shift;
35  
36          # The usual Object blessing
37          $self={};
# Line 39 | Line 41 | sub new {
41          my $testmodule;
42          my $module;
43          my $dir="";
44 <        if ( $fullmodule=~/\// ) {
45 <          ($dir=$fullmodule)=~s/(.*\/)(.*)/$1/;
46 <        }
44 > #       if ( $fullmodule=~/\// ) {
45 > #         ($dir=$fullmodule)=~s/(.*\/)(.*)/$1/;
46 > #       }
47 >        if ( $fullmodule=~/::/ ) {
48 >          ($dir=$fullmodule)=~s/(.*::)(.*)/$1/;
49 >        }
50          else { $dir="" }
51 <        ($testmodule=$fullmodule)=~s/(.*\/)(.*)/$1test\/test_$2/;
52 <        ($testmodule=$fullmodule)=~s/${dir}(.*)/${dir}test\/test_$1/;
51 >        ($testmodule=$fullmodule)=~s/(.*\/)(.*)/$1test::test_$2/;
52 >        ($testmodule=$fullmodule)=~s/${dir}(.*)/${dir}test::test_$1/;
53          ($module=$testmodule)=~s/.*\///g;
54  
50        # Data Initialisation
51        $self->{project}=$project;
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  
62          # Now setup a new testobject of the appropriate type
63 <        require $testmodule."\.pm";
63 >        eval "require $testmodule";
64 >        die $@ if $@;
65          $self->{testobj}=$module->_new($self, $fullmodule);
66  
67          return $self;
# Line 107 | Line 111 | sub verify {
111          open ( FILE1, "<$file1" ) or die "Cannot Read Test Output $file1 $!\n";
112          open ( FILE2, "<$file2" ) or die "Cannot Read Benchmark file ".
113                                                          "$file2 $!\n";
114 <        while ( $f1=<FILE1> ) {
115 <         $f2=<FILE2>;
116 <         if ( $f2 ne $f1 ) {
117 <           print "T:\n$f1\nB:$f2\n";
114 >        while ( $f1=<FILE2> ) {
115 >         $f2=<FILE1>;
116 >         if ( (!defined $f2 ) || ( ! defined $f1) || ($f2 ne $f1 )) {
117 >           #print "T:\n$f1\nB:$f2\n";
118             $same=0;
119           }
120          }
# Line 126 | Line 130 | sub verifydir {
130          my $name=shift;
131  
132          if ( -d "$name" ) {
133 <           $self->testpass("");
133 >           $self->testpass("Directory $name exists - test passed");
134          }
135          else {
136             $self->testfail("Directory $name does not exist");
137          }
138   }
139  
140 + sub verifyexists {
141 +        my $self=shift;
142 +        my $name=shift;
143 +
144 +        if ( -e "$name" ) {
145 +           $self->testpass("$name exists - test passed");
146 +        }
147 +        else {
148 +           $self->testfail("$name does not exist");
149 +        }
150 + }
151 +
152   sub testfail {
153          my $self=shift;
154          my $string=shift;
# Line 199 | Line 215 | sub _new {
215  
216          # Data Initialisation
217          $self->{testclass}=$class;
218 <        $self->{classname}=$module;
218 >        ($self->{classname}=$module)=~s/::/\//g;
219          ($self->{class}=$module)=~s/.*\///g;
220          $self->{classfile}=$ENV{SCRAM_HOME}."/src/".$self->{classname}."\.pm";
221          $self->init(@_);
# Line 215 | Line 231 | sub testinterface {
231          my $self=shift;
232          my $subname=shift;
233          my $myreturn;
234 +        my $expected;
235  
236          $self->_checkdoc($subname);
237          $self->{inttest}{$subname}++;
# Line 225 | Line 242 | sub testinterface {
242          if ( exists $self->{expect} ) {
243           @mylist=eval { $self->{object}->$subname(@_); };
244            die "Test Failed $@\n" if $@;
245 <         for $myreturn ( @mylist ) {
246 <          if ( \$myreturn=~/HASH/ ) {
247 <             print "Hash Refreturned\n";
245 >         if ( defined @mylist ) {
246 >         # size check
247 >         if ( $#mylist < $#{$self->{expect}} ) {
248 >                $self->testfail("not enough returned values");
249 >         }
250 >         foreach $myreturn ( @mylist ) {
251 >          if ( ! defined $myreturn ) {
252 >                print "Undefined Value Passed Back\n";
253 >          }
254 >          elsif ( $myreturn=~/HASH/ ) {
255 >             print "Hash Ref returned\n";
256            }
257 <          elsif ( \$myreturn=~/CODE/ ) {
257 >          elsif ( $myreturn=~/CODE/ ) {
258               print "Code Ref returned\n";
259            }
260 <          elsif ( \$myreturn=~/ARRAY/ ) {
260 >          elsif ( $myreturn=~/ARRAY/ ) {
261              print "Array Ref returned\n";
262            }
263            else {
264 <            my $expected=$self->{expect}[$num++];
264 >            $expected=$self->{expect}[$num++];
265              if ( $myreturn eq $expected ) { #simple return case
266               $self->testpass("OK - returned as expected ($expected)");
267              }
# Line 245 | Line 270 | sub testinterface {
270                                                  $myreturn);
271              }
272            }
273 <        }
273 >        } # end foreach block
274 >        }
275            return @mylist;
276          }
277          else {
# Line 258 | Line 284 | sub testinterface {
284   #
285   sub expect {
286          my $self=shift;
261        my $string=shift;
287  
288 <        push @{$self->{expect}}, $string;
288 >        push @{$self->{expect}}, @_;
289   }
290  
291   sub clearexpect {
# Line 358 | Line 383 | sub analyseInterface {
383          }
384          close SRCIN;
385   }
386 +
387 + sub cleantemp {
388 +        my $self=shift;
389 +        use File::Path;
390 +        rmtree($self->temparea());
391 + }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines