mirror of
https://github.com/sqlite/sqlite.git
synced 2025-07-29 08:01:23 +03:00
Add command dispatcher to SQLTester.
FossilOrigin-Name: e0a06931e91459ea43fed2954568bfafa7ad6b794fcff66e0d3bf0ed181db386
This commit is contained in:
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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>");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -2,6 +2,8 @@
|
||||
|
||||
# this line is ignored
|
||||
|
||||
junk
|
||||
|
||||
--null NULL
|
||||
--- also ignored
|
||||
--testcase first
|
||||
|
Reference in New Issue
Block a user