Move the top-level "test" directory into "test/regression"
[cql-java-moved-to-github.git] / test / regression / runtests
1 #!/usr/bin/perl -w
2
3 use IO::File;
4 use strict;
5
6 if (@ARGV != 2) {
7     print STDERR "Usage: $0 <CQL-compiler> <XML-normaliser>\n";
8     exit(1);
9 }
10 my $compiler = $ARGV[0];
11 my $norman = $ARGV[1];
12
13 while (<sections/*>) {
14     my $sdir = $_;
15     s@sections/@@;
16     print "testing section $_ - ", read_file("$sdir/name"), "\n";
17
18     while (<$sdir/*.cql>) {
19         my $qfile = $_;
20         s@sections/([0-9]+/.*)\.cql@$1@;
21         my $query = read_file($qfile);
22         my $afile = $qfile;
23         $afile =~ s/\.cql$/.xcql/;
24         print "  query $_ - $query\n";
25         my $correct = read_file("$norman < $afile |");
26         my $tested = read_file("$compiler < $qfile | $norman |")
27             or die "can't run test compiler '$compiler | $norman': $!";
28         print "    *** different XCQL output\n"
29             if $tested ne $correct;
30     }
31 }
32
33 sub read_file {
34     my($name) = @_;
35
36     $name = "<$name" if $name !~ /\|$/;
37     my $fh = new IO::File("$name")
38         or die "can't read '$name': $!";
39     my $contents = join('', <$fh>);
40     $fh->close();
41     return $contents;
42 }