mirror of
https://github.com/sqlite/sqlite.git
synced 2025-07-30 19:03:16 +03:00
Rework SQLTester dispatching and add stub impls for several commmands.
FossilOrigin-Name: 9e61af75ac83e74487a6ae681ee3ff891d8cf1f1d23bf895e9e3963ddf6eaf28
This commit is contained in:
@ -29,6 +29,7 @@ public class SQLTester {
|
||||
private final java.util.List<String> listInFiles = new ArrayList<>();
|
||||
private final Outer outer = new Outer();
|
||||
private final StringBuilder inputBuffer = new StringBuilder();
|
||||
private String nullView = "nil";
|
||||
|
||||
public SQLTester(){
|
||||
}
|
||||
@ -68,10 +69,22 @@ public class SQLTester {
|
||||
this.inputBuffer.delete(0, this.inputBuffer.length());
|
||||
}
|
||||
|
||||
String getInputBuffer(){
|
||||
return inputBuffer.toString();
|
||||
}
|
||||
|
||||
String takeInputBuffer(){
|
||||
final String rc = inputBuffer.toString();
|
||||
resetInputBuffer();
|
||||
return rc;
|
||||
}
|
||||
|
||||
void reset(){
|
||||
this.resetInputBuffer();
|
||||
}
|
||||
|
||||
void setNullValue(String v){nullView = v;}
|
||||
|
||||
public static void main(String[] argv) throws Exception{
|
||||
final SQLTester t = new SQLTester();
|
||||
for(String a : argv){
|
||||
@ -91,42 +104,93 @@ public class SQLTester {
|
||||
}
|
||||
}
|
||||
|
||||
abstract class Command {
|
||||
private SQLTester tester;
|
||||
class Command {
|
||||
protected SQLTester tester;
|
||||
Command(SQLTester t){tester = t;}
|
||||
public SQLTester getTester(){return tester;}
|
||||
|
||||
public abstract void process(String[] argv, String content);
|
||||
}
|
||||
protected final void badArg(String... msg){
|
||||
StringBuilder sb = new StringBuilder();
|
||||
int i = 0;
|
||||
for(String s : msg) sb.append(((0==i++) ? "" : " ")+s);
|
||||
throw new IllegalArgumentException(sb.toString());
|
||||
}
|
||||
|
||||
class NullCommand extends Command {
|
||||
public NullCommand(SQLTester t){super(t);}
|
||||
protected final void argcCheck(String[] argv, int min, int max){
|
||||
int argc = argv.length-1;
|
||||
if(argc<min || argc>max){
|
||||
if( min==max ) badArg(argv[0],"requires exactly",""+min,"argument(s)");
|
||||
else badArg(argv[0],"requires",""+min,"-",""+max,"arguments.");
|
||||
}
|
||||
}
|
||||
|
||||
public void process(String[] argv, String content){
|
||||
protected final void argcCheck(String[] argv, int argc){
|
||||
argcCheck(argv, argc, argc);
|
||||
}
|
||||
|
||||
protected void affirmNoContent(String content){
|
||||
if(null != content){
|
||||
badArg(this.getClass().getName(),"does not accept content.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class TestCaseCommand extends Command {
|
||||
public TestCaseCommand(SQLTester t){super(t);}
|
||||
class DbCommand extends Command {
|
||||
public DbCommand(SQLTester t, String[] argv, String content){
|
||||
super(t);
|
||||
argcCheck(argv,1);
|
||||
affirmNoContent(content);
|
||||
//t.verbose(argv[0],argv[1]);
|
||||
}
|
||||
}
|
||||
|
||||
public void process(String[] argv, String content){
|
||||
class NullCommand extends Command {
|
||||
public NullCommand(SQLTester t, String[] argv, String content){
|
||||
super(t);
|
||||
argcCheck(argv,1);
|
||||
affirmNoContent(content);
|
||||
tester.setNullValue(argv[1]);
|
||||
//t.verbose(argv[0],argv[1]);
|
||||
}
|
||||
}
|
||||
|
||||
class ResultCommand extends Command {
|
||||
public ResultCommand(SQLTester t){super(t);}
|
||||
|
||||
public void process(String[] argv, String content){
|
||||
public ResultCommand(SQLTester t, String[] argv, String content){
|
||||
super(t);
|
||||
argcCheck(argv,0);
|
||||
t.verbose(argv[0],"command is TODO");
|
||||
}
|
||||
}
|
||||
|
||||
class CommandFactory {
|
||||
static Command getCommandByName(SQLTester t, String name){
|
||||
class TestCaseCommand extends Command {
|
||||
public TestCaseCommand(SQLTester t, String[] argv, String content){
|
||||
super(t);
|
||||
argcCheck(argv,1);
|
||||
t.verbose(argv[0],argv[1]);
|
||||
}
|
||||
}
|
||||
|
||||
class CommandDispatcher {
|
||||
static Class getCommandByName(String name){
|
||||
switch(name){
|
||||
case "null": return new NullCommand(t);
|
||||
case "result": return new ResultCommand(t);
|
||||
case "testcase": return new TestCaseCommand(t);
|
||||
case "db": return DbCommand.class;
|
||||
case "null": return NullCommand.class;
|
||||
case "result": return ResultCommand.class;
|
||||
case "testcase": return TestCaseCommand.class;
|
||||
default: return null;
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
static void dispatch(SQLTester tester, String[] argv, String content) throws Exception{
|
||||
final Class cmdClass = getCommandByName(argv[0]);
|
||||
if(null == cmdClass){
|
||||
throw new IllegalArgumentException(
|
||||
"No command handler found for '"+argv[0]+"'"
|
||||
);
|
||||
}
|
||||
final java.lang.reflect.Constructor<Command> ctor =
|
||||
cmdClass.getConstructor(SQLTester.class, String[].class, String.class);
|
||||
tester.verbose("Running",cmdClass.getSimpleName(),"...");
|
||||
ctor.newInstance(tester, argv, content);
|
||||
}
|
||||
}
|
||||
|
@ -165,25 +165,15 @@ public class TestScript {
|
||||
if( null==chunks ){
|
||||
verbose("This contains content which forces it to be ignored.");
|
||||
}else{
|
||||
verbose("script commands:");
|
||||
int n = 0;
|
||||
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);
|
||||
final String[] parts = chunk.split("\\n", 2);
|
||||
final String[] argv = parts[0].split("\\s+");
|
||||
CommandDispatcher.dispatch(
|
||||
tester, argv, parts.length>1 ? parts[1] : null
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -4,7 +4,8 @@
|
||||
|
||||
junk
|
||||
|
||||
--null NULL
|
||||
--null zilch
|
||||
--db 1
|
||||
--- also ignored
|
||||
--testcase first
|
||||
input for the first
|
||||
|
Reference in New Issue
Block a user