mirror of
https://github.com/sqlite/sqlite.git
synced 2025-07-29 08:01:23 +03:00
Add missing license header. Minor cleanups in SQLTester.
FossilOrigin-Name: 5be50fd5887e5378f7d66405bff3a44117a826a17e5f1a18c5129d1109ecdae2
This commit is contained in:
@ -1,30 +1,43 @@
|
||||
/*
|
||||
** 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 a utility class for generating console output.
|
||||
*/
|
||||
package org.sqlite.jni.tester;
|
||||
|
||||
public class Outer {
|
||||
class Outer {
|
||||
public boolean isVerbose = true;
|
||||
|
||||
public static <T> void out(T val){
|
||||
public static void out(Object val){
|
||||
System.out.print(val);
|
||||
}
|
||||
|
||||
public static <T> void outln(T val){
|
||||
public static void outln(Object val){
|
||||
System.out.println(val);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public static <T> void out(T... vals){
|
||||
public static void out(Object... vals){
|
||||
int n = 0;
|
||||
for(T v : vals) out((n++>0 ? " " : "")+v);
|
||||
for(Object v : vals) out((n++>0 ? " " : "")+v);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public static <T> void outln(T... vals){
|
||||
public static void outln(Object... vals){
|
||||
out(vals);
|
||||
out("\n");
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public <T> Outer verbose(T... vals){
|
||||
public Outer verbose(Object... vals){
|
||||
if(isVerbose) outln(vals);
|
||||
return this;
|
||||
}
|
||||
|
@ -29,9 +29,12 @@ 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";
|
||||
private String nullView;
|
||||
private int totalTestCount = 0;
|
||||
private int testCount;
|
||||
|
||||
public SQLTester(){
|
||||
reset();
|
||||
}
|
||||
|
||||
public void setVerbose(boolean b){
|
||||
@ -39,13 +42,13 @@ public class SQLTester {
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public <T> void verbose(T... vals){
|
||||
this.outer.verbose(vals);
|
||||
public void verbose(Object... vals){
|
||||
outer.verbose(vals);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public <T> void outln(T... vals){
|
||||
this.outer.outln(vals);
|
||||
public void outln(Object... vals){
|
||||
outer.outln(vals);
|
||||
}
|
||||
|
||||
//! Adds the given test script to the to-test list.
|
||||
@ -57,16 +60,17 @@ public class SQLTester {
|
||||
public void runTests() throws Exception {
|
||||
// process each input file
|
||||
for(String f : listInFiles){
|
||||
this.reset();
|
||||
reset();
|
||||
final TestScript ts = new TestScript(f);
|
||||
ts.setVerbose(this.outer.getVerbose());
|
||||
verbose("Test",ts.getName(),"...");
|
||||
ts.run(this);
|
||||
verbose("Ran",testCount,"test(s).");
|
||||
}
|
||||
}
|
||||
|
||||
void resetInputBuffer(){
|
||||
this.inputBuffer.delete(0, this.inputBuffer.length());
|
||||
inputBuffer.delete(0, this.inputBuffer.length());
|
||||
}
|
||||
|
||||
String getInputBuffer(){
|
||||
@ -80,11 +84,18 @@ public class SQLTester {
|
||||
}
|
||||
|
||||
void reset(){
|
||||
this.resetInputBuffer();
|
||||
testCount = 0;
|
||||
nullView = "nil";
|
||||
resetInputBuffer();
|
||||
}
|
||||
|
||||
void setNullValue(String v){nullView = v;}
|
||||
|
||||
void incrementTestCounter(){
|
||||
++testCount;
|
||||
++totalTestCount;
|
||||
}
|
||||
|
||||
public static void main(String[] argv) throws Exception{
|
||||
final SQLTester t = new SQLTester();
|
||||
for(String a : argv){
|
||||
@ -108,18 +119,18 @@ class Command {
|
||||
protected SQLTester tester;
|
||||
Command(SQLTester t){tester = t;}
|
||||
|
||||
protected final void badArg(String... msg){
|
||||
protected final void badArg(Object... msg){
|
||||
StringBuilder sb = new StringBuilder();
|
||||
int i = 0;
|
||||
for(String s : msg) sb.append(((0==i++) ? "" : " ")+s);
|
||||
for(Object s : msg) sb.append(((0==i++) ? "" : " ")+s);
|
||||
throw new IllegalArgumentException(sb.toString());
|
||||
}
|
||||
|
||||
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.");
|
||||
if( min==max ) badArg(argv[0],"requires exactly",min,"argument(s)");
|
||||
else badArg(argv[0],"requires",min,"-",max,"arguments.");
|
||||
}
|
||||
}
|
||||
|
||||
@ -148,7 +159,7 @@ class NullCommand extends Command {
|
||||
super(t);
|
||||
argcCheck(argv,1);
|
||||
affirmNoContent(content);
|
||||
tester.setNullValue(argv[1]);
|
||||
t.setNullValue(argv[1]);
|
||||
//t.verbose(argv[0],argv[1]);
|
||||
}
|
||||
}
|
||||
@ -158,6 +169,7 @@ class ResultCommand extends Command {
|
||||
super(t);
|
||||
argcCheck(argv,0);
|
||||
t.verbose(argv[0],"command is TODO");
|
||||
t.incrementTestCounter();
|
||||
}
|
||||
}
|
||||
|
||||
@ -190,7 +202,7 @@ class CommandDispatcher {
|
||||
}
|
||||
final java.lang.reflect.Constructor<Command> ctor =
|
||||
cmdClass.getConstructor(SQLTester.class, String[].class, String.class);
|
||||
tester.verbose("Running",cmdClass.getSimpleName(),"...");
|
||||
//tester.verbose("Running",argv[0],"...");
|
||||
ctor.newInstance(tester, argv, content);
|
||||
}
|
||||
}
|
||||
|
@ -16,8 +16,6 @@ import java.util.List;
|
||||
import java.util.ArrayList;
|
||||
import java.io.*;
|
||||
import java.util.regex.*;
|
||||
//import java.util.List;
|
||||
//import java.util.ArrayList;
|
||||
|
||||
/**
|
||||
This class represents a single test script. It handles (or delegates)
|
||||
@ -25,8 +23,7 @@ import java.util.regex.*;
|
||||
as-yet-non-existent, classes.
|
||||
|
||||
*/
|
||||
public class TestScript {
|
||||
//! Test script content.
|
||||
class TestScript {
|
||||
private String name;
|
||||
private String content;
|
||||
private List<String> chunks = null;
|
||||
@ -44,6 +41,7 @@ public class TestScript {
|
||||
}
|
||||
/**
|
||||
Initializes the script with the content of the given file.
|
||||
Throws if it cannot read the file or if tokenizing it fails.
|
||||
*/
|
||||
public TestScript(String filename) throws Exception{
|
||||
setContent(new String(readFile(filename),
|
||||
@ -91,8 +89,8 @@ public class TestScript {
|
||||
}
|
||||
|
||||
/**
|
||||
A quick-and-dirty approach to chopping a script up into individual
|
||||
commands and their inputs.
|
||||
Chop script up into chunks containing individual commands and
|
||||
their inputs.
|
||||
*/
|
||||
private List<String> chunkContent(){
|
||||
if( ignored ) return null;
|
||||
@ -121,15 +119,11 @@ public class TestScript {
|
||||
tmp = m.replaceAll("");
|
||||
}
|
||||
// Chunk the newly-cleaned text into individual commands and their input...
|
||||
final String sCommand = "^--";
|
||||
final List<String> rc = new ArrayList<>();
|
||||
final Pattern p = Pattern.compile(
|
||||
sCommand, Pattern.MULTILINE
|
||||
);
|
||||
final Pattern p = Pattern.compile("^--", Pattern.MULTILINE);
|
||||
final Matcher m = p.matcher(tmp);
|
||||
int ndxPrev = 0, pos = 0;
|
||||
int ndxPrev = 0, pos = 0, i = 0;
|
||||
String chunk;
|
||||
int i = 0;
|
||||
//verbose("Trimmed content:").verbose(tmp).verbose("<EOF>");
|
||||
while( m.find() ){
|
||||
pos = m.start();
|
||||
@ -147,6 +141,7 @@ public class TestScript {
|
||||
ndxPrev = pos + 2;
|
||||
}
|
||||
if( ndxPrev < tmp.length() ){
|
||||
// This all belongs to the final command
|
||||
chunk = tmp.substring(ndxPrev, tmp.length()).trim();
|
||||
if( !chunk.isEmpty() ){
|
||||
++i;
|
||||
@ -158,8 +153,7 @@ 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).
|
||||
Runs this test script in the context of the given tester object.
|
||||
*/
|
||||
public void run(SQLTester tester) throws Exception {
|
||||
if( null==chunks ){
|
||||
|
@ -10,6 +10,8 @@ junk
|
||||
--testcase first
|
||||
input for the first
|
||||
command;
|
||||
--result
|
||||
hello world
|
||||
--testcase second
|
||||
select 1
|
||||
--result /* ignored */
|
||||
|
Reference in New Issue
Block a user