On 12/8/18, Deon Brewis <[email protected]> wrote:
>
> I'm curious how that test that you added works? i.e. What causes the test
> to fail if the results are wrong?
The particular test case you are referring to is written in in the TCL
language. The TCL tests are the oldest set of tests for SQLite since
SQLite is really a TCL-extension that escaped into the wild.
Everything in TCL is a command followed by zero or more arguments. In
this sense, TCL is very much like Bourne shell. COMMAND ARG1 ARG2
ARG3 .... Where TCL excels is in how it quotes the arguments. Curly
braces {...} are quoting characters that nest. Take, for example,
the "if" command in TCL:
if {$a<0} {
set a [expr {-$a}]
} else {
set a [expr {$a+10}]
}
In this case, the "if" command has four arguments
if EXPR SCRIPT else SCRIPT
When the "if" command runs, it evaluates its first argument EXPR. If
EXPR is true, then the if command runs the SCRIPT given in the second
argument. Otherwise it runs the SCRIPT in the fourth argument. The
magic, you see, is in the use of nested curly braces for quoting.
The test command you refer to is this:
do_execsql_test index6-12.1 {
DROP TABLE IF EXISTS t1;
DROP TABLE IF EXISTS t2;
CREATE TABLE t1(a,b);
INSERT INTO t1 VALUES(1,1);
INSERT INTO t1 VALUES(2,2);
CREATE TABLE t2(x);
INSERT INTO t2 VALUES(1);
INSERT INTO t2 VALUES(2);
SELECT 'one', * FROM t2 WHERE x NOT IN (SELECT a FROM t1);
CREATE INDEX t1a ON t1(a) WHERE b=1;
SELECT 'two', * FROM t2 WHERE x NOT IN (SELECT a FROM t1);
} {}
The name of the command is "do_execsql_test". That command takes
three arguments:
do_execsql_test TESTNAME SQL-SCRIPT EXPECTED-RESULT
This command simply runs the SQL found in its second argument and
accumulates the results. The accumulated result should exactly match
the third argument. If it does not match, then it prints an error
message and increments the error counter.
If you start with the canonical SQL source code, you can generate the
appropriate TCL interpreter by typing
./configure; make testfixture
Or on windows:
nmake /f Makefile.msc testfixture.exe
Then you say "./testfixture test/index6.test" to run that particular test file.
--
D. Richard Hipp
[email protected]
_______________________________________________
sqlite-users mailing list
[email protected]
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users