-# $Id: Makefile,v 1.1 2002-11-01 23:45:28 mike Exp $
+# $Id: Makefile,v 1.2 2002-11-02 01:19:23 mike Exp $
+
+tests: sections/01/01.xcql
+ ./runtests CQLParser cat
sections/01/01.xcql: sections
-# ./mkanswers ../../rob/CQLParser.py
./mkanswers ../../srw/cql/cqlparse3
+# OR ./mkanswers ../../rob/CQLParser.py
sections: mktests raw
rm -rf sections
-$Id: README,v 1.1 2002-11-01 23:45:28 mike Exp $
+$Id: README,v 1.2 2002-11-02 01:19:23 mike Exp $
"raw" is the file of test queries as provided by Rob.
"mktests" parses the raw file into sections and individual queries
"01/01.cql", "01/02.cql" etc. are the CQL queries themselves.
"mkanswers" uses a trusted CQL compiler to generate corresponding XCQL.
"01/01.xcql", "01/02.xcql" etc. are the compiled XCQL queries.
-"Makefile" controls the building of all this.
+"runtests" compares the output of a CQL compiler with existing XCQL files.
+
+"Makefile" controls the building of all this. You'll need to edit it
+if you want to use different compilers and suchlike from what's
+written into it, so it may be easier to run the tests by hand -- but
+it's a useful reference for the kinds of commands you might need,
+anyway.
+
+So, for example, if you think Rob Sanderson's parser, CQLParser.py, is
+reliable, and you want to test my parser, cql-java's CQLParser class,
+against its results, do this:
+
+ rm -rf sections
+ ./mktests raw
+ ./mkanswers CQLParser.py
+ ./runtests CQLParser sgmlnorm
+
+(Except that sgmlnorm is useless -- gotta find something better.)
+
+Also: there's a nasty hacl here called "showtest" which, when run like
+``./showtest 07/03'', will show you the ways in which my output
+differs from Adam's. I'll probably delete it soon.
use IO::File;
use strict;
-if (@ARGV == 0) {
+if (@ARGV != 1) {
print STDERR "Usage: $0 <trusted-CQL-compiler>\n";
exit(1);
}
s@sections/@@;
print "answering section $_ - ", read_file("$sdir/name"), "\n";
- while (<$sdir/*>) {
- next if /\/name$/;
+ while (<$sdir/*.cql>) {
my $qfile = $_;
s@sections/([0-9]+/.*)\.cql@$1@;
my $query = read_file($qfile);
my $afile = $qfile;
- $afile =~ s/\.cql$/.cxql/;
+ $afile =~ s/\.cql$/.xcql/;
print " query $_ - $query\n";
my $fh = new IO::File("| $compiler > $afile")
or die "can't run compiler '$compiler': $!";
$fh->close();
return $contents;
}
-
-sub write_file {
- my($name, $contents) = @_;
-
- my $fh = new IO::File(">$name")
- or die "can't create '$name': $!";
- $fh->print($contents);
- $fh->close();
-}
(cat not frog)
"cat" not "fish food"
xml and "prox/word/"
-fred and any
-((fred or all))
a or b and c not d
# I/R/T plus Boolean
bath.author any fish and dc.title all "cat dog"
-(title any/stem "fish dog" or and)
+(title any/stem "fish dog" or "and")
# Prox
cat prox hat
cat prox/word/=/3/ordered hat
cat prox///3 hat
-"fish food" prox/sentence and
-title all "chips frog" prox/word//5 any
+"fish food" prox/sentence "and"
+title all "chips frog" prox/word//5 "any"
(dc.author exact "jones" prox///5 title >= "smith")
((cat prox hat))
index any fish)
(cat any dog or ())
sorry = (mike)
+fred and any
+((fred or all))
--- /dev/null
+#!/usr/bin/perl -w
+
+use IO::File;
+use strict;
+
+if (@ARGV != 2) {
+ print STDERR "Usage: $0 <CQL-compiler> <XML-normaliser>\n";
+ exit(1);
+}
+my $compiler = $ARGV[0];
+my $norman = $ARGV[1];
+
+while (<sections/*>) {
+ my $sdir = $_;
+ s@sections/@@;
+ print "testing section $_ - ", read_file("$sdir/name"), "\n";
+
+ while (<$sdir/*.cql>) {
+ my $qfile = $_;
+ s@sections/([0-9]+/.*)\.cql@$1@;
+ my $query = read_file($qfile);
+ my $afile = $qfile;
+ $afile =~ s/\.cql$/.xcql/;
+ print " query $_ - $query\n";
+ my $correct = read_file("$norman < $afile |");
+ my $tested = read_file("$compiler < $qfile | $norman |")
+ or die "can't run test compiler '$compiler | $norman': $!";
+ print " *** different XCQL output\n"
+ if $tested ne $correct;
+ }
+}
+
+sub read_file {
+ my($name) = @_;
+
+ $name = "<$name" if $name !~ /\|$/;
+ my $fh = new IO::File("$name")
+ or die "can't read '$name': $!";
+ my $contents = join('', <$fh>);
+ $fh->close();
+ return $contents;
+}
--- /dev/null
+#!/bin/sh
+
+if [ $# != 1 ]; then
+ echo "Usage: $0 <test-name>" >&2
+ echo " e.g. $0 01/02" >&2
+ exit 1
+fi
+
+### Warning: nasty hard-coded choices
+( echo "=== Adam ==="
+ ../../srw/cql/cqlparse3 < sections/$1.cql ) > /tmp/adam
+( echo "=== Mike ==="
+ ../bin/CQLParser < sections/$1.cql ) > /tmp/mike
+sdiff -w 80 /tmp/adam /tmp/mike