Tweaks to test suite. I think it's ready for serious use now.
[cql-java-moved-to-github.git] / test / regression / runtests
1 #!/usr/bin/perl -w
2
3 # $Id: runtests,v 1.5 2002-11-20 17:55:46 mike Exp $
4
5 use IO::File;
6 use strict;
7
8 if (@ARGV != 2) {
9     print STDERR "Usage: $0 <CQL-compiler> <XML-normaliser>\n";
10     exit(1);
11 }
12 my $compiler = $ARGV[0];
13 my $norman = $ARGV[1];
14
15 while (<sections/*>) {
16     my $sdir = $_;
17     s@sections/@@;
18     print "testing section $_ - ", read_file("$sdir/name"), "\n";
19
20     while (<$sdir/*.cql>) {
21         my $qfile = $_;
22         s@sections/([0-9]+/.*)\.cql@$1@;
23         my $query = read_file($qfile);
24         my $afile = $qfile;
25         $afile =~ s/\.cql$/.xcql/;
26         print "  query $_ - $query  ";
27         my $correct = read_file("$norman < $afile |");
28         my $tested = read_file("$compiler < $qfile | $norman |")
29             or print "\n    *** test compiler exited non-zero\n";
30         if ($tested eq $correct) {
31             print "OK\n";
32         } else {
33             print "\n    *** different XCQL output\n";
34             print "=== correct ===\n$correct";
35             print "=== tested ===\n$tested";
36         }
37     }
38 }
39
40 sub read_file {
41     my($name) = @_;
42
43     $name = "<$name" if $name !~ /\|$/;
44     my $fh = new IO::File("$name")
45         or die "can't read '$name': $!";
46     my $contents = join('', <$fh>);
47     $fh->close();
48     return $contents;
49 }