More clean up, update readme
[cql-java-moved-to-github.git] / util / regression / runtests
1 #!/usr/bin/perl -w
2
3
4 use IO::File;
5 use strict;
6
7 $ENV{CLASSPATH} .= ":../../src/main/java";
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$/;
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         $ntests++;
32         my $correct = read_file("$norman < $afile |");
33         my $tested = read_file("$compiler < $qfile | $norman |");
34         if (!$tested) {
35             print "\n    *** test compiler exited non-zero\n";
36         } elsif ($tested eq $correct) {
37             print "OK\n";
38             $ncorrect++;
39         } else {
40             print "\n    *** XCQL output differs from $afile\n";
41             print "=== tested ===\n$tested";
42             print "=== end ===\n";
43         }
44     }
45 }
46
47 print sprintf("%d of %d passed: %d%%\n",
48               $ncorrect, $ntests, (100 * $ncorrect) / $ntests);
49
50 sub read_file {
51     my($name) = @_;
52
53     $name = "<$name" if $name !~ /\|$/;
54     my $fh = new IO::File("$name")
55         or die "can't read '$name': $!";
56     my $contents = join('', <$fh>);
57     $fh->close();
58     return $contents;
59 }