1
0
mirror of https://github.com/sqlite/sqlite.git synced 2025-07-30 19:03:16 +03:00

Add command dispatcher to SQLTester.

FossilOrigin-Name: e0a06931e91459ea43fed2954568bfafa7ad6b794fcff66e0d3bf0ed181db386
This commit is contained in:
stephan
2023-08-07 23:59:08 +00:00
parent b7f75b7bb2
commit e9ed375876
5 changed files with 131 additions and 18 deletions

View File

@ -1,3 +1,17 @@
/*
** 2023-08-08
**
** The author disclaims copyright to this source code. In place of
** a legal notice, here is a blessing:
**
** May you do good and not evil.
** May you find forgiveness for yourself and forgive others.
** May you share freely, never taking more than you give.
**
*************************************************************************
** This file contains the main application entry pointer for the
** SQLTester framework.
*/
package org.sqlite.jni.tester;
import java.util.List;
import java.util.ArrayList;
@ -14,6 +28,7 @@ public class SQLTester {
//! List of input script files.
private final java.util.List<String> listInFiles = new ArrayList<>();
private final Outer outer = new Outer();
private final StringBuilder inputBuffer = new StringBuilder();
public SQLTester(){
}
@ -23,10 +38,15 @@ public class SQLTester {
}
@SuppressWarnings("unchecked")
private <T> void verbose(T... vals){
public <T> void verbose(T... vals){
this.outer.verbose(vals);
}
@SuppressWarnings("unchecked")
public <T> void outln(T... vals){
this.outer.outln(vals);
}
//! Adds the given test script to the to-test list.
public void addTestScript(String filename){
listInFiles.add(filename);
@ -36,13 +56,22 @@ public class SQLTester {
public void runTests() throws Exception {
// process each input file
for(String f : listInFiles){
this.reset();
final TestScript ts = new TestScript(f);
ts.setVerbose(this.outer.getVerbose());
verbose("Test",ts.getName(),"...");
ts.dump();
ts.run(this);
}
}
void resetInputBuffer(){
this.inputBuffer.delete(0, this.inputBuffer.length());
}
void reset(){
this.resetInputBuffer();
}
public static void main(String[] argv) throws Exception{
final SQLTester t = new SQLTester();
for(String a : argv){
@ -61,3 +90,43 @@ public class SQLTester {
t.runTests();
}
}
abstract class Command {
private SQLTester tester;
Command(SQLTester t){tester = t;}
public SQLTester getTester(){return tester;}
public abstract void process(String[] argv, String content);
}
class NullCommand extends Command {
public NullCommand(SQLTester t){super(t);}
public void process(String[] argv, String content){
}
}
class TestCaseCommand extends Command {
public TestCaseCommand(SQLTester t){super(t);}
public void process(String[] argv, String content){
}
}
class ResultCommand extends Command {
public ResultCommand(SQLTester t){super(t);}
public void process(String[] argv, String content){
}
}
class CommandFactory {
static Command getCommandByName(SQLTester t, String name){
switch(name){
case "null": return new NullCommand(t);
case "result": return new ResultCommand(t);
case "testcase": return new TestCaseCommand(t);
default: return null;
}
}
}

View File

@ -1,3 +1,16 @@
/*
** 2023-08-08
**
** The author disclaims copyright to this source code. In place of
** a legal notice, here is a blessing:
**
** May you do good and not evil.
** May you find forgiveness for yourself and forgive others.
** May you share freely, never taking more than you give.
**
*************************************************************************
** This file contains the TestScript part of the SQLTester framework.
*/
package org.sqlite.jni.tester;
import java.util.List;
import java.util.ArrayList;
@ -116,15 +129,30 @@ public class TestScript {
final Matcher m = p.matcher(tmp);
int ndxPrev = 0, pos = 0;
String chunk;
int i = 0;
//verbose("Trimmed content:").verbose(tmp).verbose("<EOF>");
while( m.find() ){
pos = m.start();
chunk = tmp.substring(ndxPrev, pos).trim();
if( !chunk.isEmpty() ) rc.add( chunk );
if( 0==ndxPrev && pos>ndxPrev ){
/* Initial chunk of non-command state. Skip it. */
ndxPrev = pos + 2;
continue;
}
if( !chunk.isEmpty() ){
++i;
//verbose("CHUNK #"+i,""+ndxPrev,"..",""+pos,chunk);
rc.add( chunk );
}
ndxPrev = pos + 2;
}
if( ndxPrev != pos + 2 ){
if( ndxPrev < tmp.length() ){
chunk = tmp.substring(ndxPrev, tmp.length()).trim();
if( !chunk.isEmpty() ) rc.add( chunk );
if( !chunk.isEmpty() ){
++i;
//verbose("CHUNK #"+(++i),chunk);
rc.add( chunk );
}
}
return rc;
}
@ -133,16 +161,30 @@ public class TestScript {
A debug-only function which dumps the content of the test script
in some form or other (possibly mangled from its original).
*/
public void dump(){
public void run(SQLTester tester) throws Exception {
if( null==chunks ){
verbose("This contains content which forces it to be ignored.");
}else{
verbose("script commands:");
int n = 0;
for(String c : chunks){
verbose("#"+(++n),c);
for(String chunk : chunks){
++n;
//verbose("#"+n,c).verbose("<EOF>");
String[] parts = chunk.split("\\n", 2);
String[] argv = parts[0].split("\\s+");
Command cmd = CommandFactory.getCommandByName(tester, argv[0]);
verbose("Command #"+n,argv[0],":",
(null==cmd ? "null" : cmd.getClass().getName()));
if(null == cmd){
throw new IllegalArgumentException(
"No command handler found for '"+argv[0]+"'"
);
}
if( parts.length > 1 ){
verbose(parts[1]).verbose("<EOF>");
}
cmd.process(argv, parts.length>1 ? parts[1] : null);
}
verbose("<EOF>");
}
}
}

View File

@ -2,6 +2,8 @@
# this line is ignored
junk
--null NULL
--- also ignored
--testcase first

View File

@ -1,5 +1,5 @@
C SQLTester\snow\signores\stests\swhich\scontain\sconstructs\sspecified\sin\sthe\sspec\sdoc.
D 2023-08-07T23:04:17.593
C Add\scommand\sdispatcher\sto\sSQLTester.
D 2023-08-07T23:59:08.259
F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1
F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea
F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724
@ -265,10 +265,10 @@ F ext/jni/src/org/sqlite/jni/sqlite3_context.java d26573fc7b309228cb49786e907859
F ext/jni/src/org/sqlite/jni/sqlite3_stmt.java 78e6d1b95ac600a9475e9db4623f69449322b0c93d1bd4e1616e76ed547ed9fc
F ext/jni/src/org/sqlite/jni/sqlite3_value.java 3d1d4903e267bc0bc81d57d21f5e85978eff389a1a6ed46726dbe75f85e6914a
F ext/jni/src/org/sqlite/jni/tester/Outer.java 8931ff9f152d22a822ff98831a4e924da48016ff1f1f84042390a6f51ad7b48f
F ext/jni/src/org/sqlite/jni/tester/SQLTester.java 1ee4ef9c65c9eedf6bfd68ad807346592ee01faf7fad16c3f18c462ed4c98c38
F ext/jni/src/org/sqlite/jni/tester/TestScript.java 374bdad5cd0597aa9e20e5b8abd077a41d92caae6190ce383c250cb08859e7e4
F ext/jni/src/org/sqlite/jni/tester/SQLTester.java e717d2117f9589f17af599e527c126733b13a2cfded3f47297ae37c02e62e9ab
F ext/jni/src/org/sqlite/jni/tester/TestScript.java fa93b7abe11903412464b6cfbb6a2c44c738d4da291748ec99b28d3964bce846
F ext/jni/src/org/sqlite/jni/tester/test-script-interpreter.md 2627f8ac7c3d3f502404d9a9b8481bad5c2d11df7fdf25fbd0e1dbd2bcaa54c3
F ext/jni/src/tests/000_first.test a06b72b6815246a21f6a4b14126bbc40b9cd1e3b03410431ed50203cfa942e9b
F ext/jni/src/tests/000_first.test dad04b8e386bb5a33d02c9647a20229daccea9889ead58c70a723d5d179facea
F ext/jni/src/tests/010_ignored.test ce2de6742ff1bf98d8976fda0f260ff3d280e8f8c0a99309fb59fcfef2556fcd
F ext/lsm1/Makefile a553b728bba6c11201b795188c5708915cc4290f02b7df6ba7e8c4c943fd5cd9
F ext/lsm1/Makefile.msc f8c878b467232226de288da320e1ac71c131f5ec91e08b21f502303347260013
@ -2089,8 +2089,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93
F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc
F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e
F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0
P d3d1accc8b4ba0cd396ee3a58d9710a54b8e1d1b171d67595d4ef1fc7faea8cb
R d5c9761c7876583110d4d0a8a0b413b4
P ecaeee652aa2cc6893ded9231d7e9b2783465516016740b307b74e4e81598ae3
R 248f12cc342cf395644ad37d3af803a2
U stephan
Z e82e467651a46849ab5637959c044f1b
Z 328e43fc1d1558590d24a0a8fa1662fc
# Remove this line to create a well-formed Fossil manifest.

View File

@ -1 +1 @@
ecaeee652aa2cc6893ded9231d7e9b2783465516016740b307b74e4e81598ae3
e0a06931e91459ea43fed2954568bfafa7ad6b794fcff66e0d3bf0ed181db386