Final report of success count and percentage.
[cql-java-moved-to-github.git] / test / regression / runtests
1 #!/usr/bin/perl -w
2
3 # $Id: runtests,v 1.8 2007-06-07 16:17:28 mike Exp $
4
5 use IO::File;
6 use strict;
7
8 $ENV{CLASSPATH} .= ":../../lib/cql-java.jar";
9
10 if (@ARGV != 2) {
11     print STDERR "Usage: $0 <CQL-compiler> <XML-normaliser>\n";
12     exit(1);
13 }
14 my $compiler = $ARGV[0];
15 my $norman = $ARGV[1];          # name of XML normaliser program
16 my($ntests, $ncorrect) = (0, 0);
17
18 while (<sections/*>) {
19     my $sdir = $_;
20     s@sections/@@;
21     next if /^CVS$/ || /^10$/;
22     print "testing section $_ - ", read_file("$sdir/name"), "\n";
23
24     while (<$sdir/*.cql>) {
25         my $qfile = $_;
26         s@sections/([0-9]+/.*)\.cql@$1@;
27         my $query = read_file($qfile);
28         my $afile = $qfile;
29         $afile =~ s/\.cql$/.xcql/;
30         print "  query $_ - $query  ";
31         my $correct = read_file("$norman < $afile |");
32         my $tested = read_file("$compiler < $qfile | $norman |")
33             or print "\n    *** test compiler exited non-zero\n";
34         $ntests++;
35         if ($tested eq $correct) {
36             print "OK\n";
37             $ncorrect++;
38         } else {
39             print "\n    *** different XCQL output\n";
40             print "=== correct ===\n$correct";
41             print "=== tested ===\n$tested";
42         }
43     }
44 }
45
46 print sprintf("%d of %d passed: %d%%\n",
47               $ncorrect, $ntests, (100 * $ncorrect) / $ntests);
48
49 sub read_file {
50     my($name) = @_;
51
52     $name = "<$name" if $name !~ /\|$/;
53     my $fh = new IO::File("$name")
54         or die "can't read '$name': $!";
55     my $contents = join('', <$fh>);
56     $fh->close();
57     return $contents;
58 }