Failure to compile a query counts as a failed test!
[cql-java-moved-to-github.git] / test / regression / runtests
1 #!/usr/bin/perl -w
2
3 # $Id: runtests,v 1.10 2007-06-21 14:54:32 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         $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    *** different XCQL output\n";
41             print "=== correct ===\n$correct";
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 }