43 Generate The TestSuite Source File

 43.1 Read Test Cases
 43.2 Write TestSuite
 43.3 test/TestSuite.as

This Perl script is intended to generate the file test/TestSuite.as. Look at this file in Section 43.3 in order to get an impression how it will look like.

This Perl script takes two arguments. The file given as the first argument should have a format as the file test/tcasfiles.list (see Section 41.4). The second argument is the name of the project.

The script tools/generateTestSuite.pl.nw relies on the fact that TCLIBRARYNAME is set to testcases as can be seen from the code chunk that read the signature files. Only the entries from the file given as the first parameter are used that start with testcases.

The script tools/generateTestSuite.pl.nw proceeds as follows.

It first reads the lines from the file test/asfiles.list that is given as the first parameter. From that file only the lines that start with testcasee are considered. The remaining line contains a filename and a prefix. For each such line it reads via the function readTestCases the corresponding .signatures.as file from the test directory. Note that each .signatures.as file should describe exactly one test domain. The signatures together with the information about the domain name (which is also in the .signatures.as file) is then transformed into the structure of a test/TestSuite.as file.

It is important to note that ALLPROSE allows reuse of parametrized test code. For example, one can write a test package that is parametrized

<<*>>=  
--File plus.as.nw  
#assert DontNeedLibraryTestCases  
#include "testcases"  
TestPlus(R: ArithmeticType): TestCaseType with {  
#include "plus.signatures.as"  
} == add {  
        import from R, TestCaseTools;  
        testPlus(): () == assertEquals(R, 1, 1+0);  
}  
@

and use it in two other files, namely

<<*>>=  
--File plus1.as.nw  
#include "testcases"  
TestPlusMachineInteger: TestCaseType with {  
#include "plus.signatures.as"  
#include "plus1.signatures.as"  
} == TestPlus MachineInteger add;  
        import from MachineInteger, TestCaseTools;  
        testPlus1(): () == assertEquals(MachineInteger, 2, 1+1);  
}  
@

and

<<*>>=  
--File plus2.as.nw  
#include "testcases"  
TestPlusInteger: TestCaseType with {  
#include "plus.signatures.as"  
#include "plus2.signatures.as"  
} == TestPlus Integer add {  
        import from Integer, TestCaseTools;  
        testPlus2(): () == assertEquals(Integer, 2, 1+1);  
}  
@

The script tools/generateTestSuite.pl.nw takes care of correctly generating appropriate entries in the test/TestSuite.as file.

559* 21+   554
#------------------------------------------------------------------
#---
#--- ALLPROSE
#--- Copyright (C) Ralf Hemmecke (ralf@hemmecke.de)
#--- http://www.hemmecke.de/aldor
#---
#------------------------------------------------------------------

%DATA=();

if (scalar(@ARGV) < 2) {
    print STDERR "Usage: $0  FILES.list PROJECTNAME\n";
    die "";
}

$TCASFILES=$ARGV[0];
$PROJECTNAME=$ARGV[1];

read signatures of testcases 561
write TestSuite to stdout 563

Uses FILES 351a and PROJECTNAME 124.