From f93b59f21f11404a6bdbb1f8d4796ca6f0281dba Mon Sep 17 00:00:00 2001 From: mike Date: Sat, 2 Nov 2002 01:19:23 +0000 Subject: [PATCH] First more or less functional version of the test suite (Although it's pretty badly hampered by my lack of a half-decent XML normalisation utility.) --- test/.cvsignore | 1 + test/Makefile | 7 +++++-- test/README | 25 +++++++++++++++++++++++-- test/mkanswers | 16 +++------------- test/raw | 10 +++++----- test/runtests | 42 ++++++++++++++++++++++++++++++++++++++++++ test/showtest | 14 ++++++++++++++ 7 files changed, 93 insertions(+), 22 deletions(-) create mode 100644 test/.cvsignore create mode 100755 test/runtests create mode 100755 test/showtest diff --git a/test/.cvsignore b/test/.cvsignore new file mode 100644 index 0000000..38c8706 --- /dev/null +++ b/test/.cvsignore @@ -0,0 +1 @@ +sections diff --git a/test/Makefile b/test/Makefile index 95a9065..75aade5 100644 --- a/test/Makefile +++ b/test/Makefile @@ -1,8 +1,11 @@ -# $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 diff --git a/test/README b/test/README index fff96be..567e0cb 100644 --- a/test/README +++ b/test/README @@ -1,4 +1,4 @@ -$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 @@ -8,4 +8,25 @@ $Id: README,v 1.1 2002-11-01 23:45:28 mike Exp $ "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. diff --git a/test/mkanswers b/test/mkanswers index 4343b40..3475181 100755 --- a/test/mkanswers +++ b/test/mkanswers @@ -3,7 +3,7 @@ use IO::File; use strict; -if (@ARGV == 0) { +if (@ARGV != 1) { print STDERR "Usage: $0 \n"; exit(1); } @@ -14,13 +14,12 @@ while () { 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': $!"; @@ -38,12 +37,3 @@ sub read_file { $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(); -} diff --git a/test/raw b/test/raw index 847b027..12a16b7 100644 --- a/test/raw +++ b/test/raw @@ -32,22 +32,20 @@ cat not frog (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)) @@ -85,3 +83,5 @@ a prox/wrong b index any fish) (cat any dog or ()) sorry = (mike) +fred and any +((fred or all)) diff --git a/test/runtests b/test/runtests new file mode 100755 index 0000000..977de06 --- /dev/null +++ b/test/runtests @@ -0,0 +1,42 @@ +#!/usr/bin/perl -w + +use IO::File; +use strict; + +if (@ARGV != 2) { + print STDERR "Usage: $0 \n"; + exit(1); +} +my $compiler = $ARGV[0]; +my $norman = $ARGV[1]; + +while () { + 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; +} diff --git a/test/showtest b/test/showtest new file mode 100755 index 0000000..15e57b5 --- /dev/null +++ b/test/showtest @@ -0,0 +1,14 @@ +#!/bin/sh + +if [ $# != 1 ]; then + echo "Usage: $0 " >&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 -- 1.7.10.4