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