Nail down test suite to use the CQLParser script from ../../bin
[cql-java-moved-to-github.git] / test / regression / runtests
1 #!/usr/bin/perl -w
2
3 # $Id: runtests,v 1.7 2002-11-21 09:57: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
17 while (<sections/*>) {
18     my $sdir = $_;
19     s@sections/@@;
20     next if /^CVS$/ || /^10$/;
21     print "testing section $_ - ", read_file("$sdir/name"), "\n";
22
23     while (<$sdir/*.cql>) {
24         my $qfile = $_;
25         s@sections/([0-9]+/.*)\.cql@$1@;
26         my $query = read_file($qfile);
27         my $afile = $qfile;
28         $afile =~ s/\.cql$/.xcql/;
29         print "  query $_ - $query  ";
30         my $correct = read_file("$norman < $afile |");
31         my $tested = read_file("$compiler < $qfile | $norman |")
32             or print "\n    *** test compiler exited non-zero\n";
33         if ($tested eq $correct) {
34             print "OK\n";
35         } else {
36             print "\n    *** different XCQL output\n";
37             print "=== correct ===\n$correct";
38             print "=== tested ===\n$tested";
39         }
40     }
41 }
42
43 sub read_file {
44     my($name) = @_;
45
46     $name = "<$name" if $name !~ /\|$/;
47     my $fh = new IO::File("$name")
48         or die "can't read '$name': $!";
49     my $contents = join('', <$fh>);
50     $fh->close();
51     return $contents;
52 }