+/*
+** 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;
}
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){
}
@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.
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(){
}
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){
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.");
}
}
super(t);
argcCheck(argv,1);
affirmNoContent(content);
- tester.setNullValue(argv[1]);
+ t.setNullValue(argv[1]);
//t.verbose(argv[0],argv[1]);
}
}
super(t);
argcCheck(argv,0);
t.verbose(argv[0],"command is TODO");
+ t.incrementTestCounter();
}
}
}
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);
}
}
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)
as-yet-non-existent, classes.
*/
-public class TestScript {
- //! Test script content.
+class TestScript {
private String name;
private String content;
private List<String> chunks = null;
}
/**
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),
}
/**
- 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;
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();
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;
}
/**
- 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 ){
--testcase first
input for the first
command;
+--result
+hello world
--testcase second
select 1
--result /* ignored */
-C Rework\sSQLTester\sdispatching\sand\sadd\sstub\simpls\sfor\sseveral\scommmands.
-D 2023-08-08T00:37:31.945
+C Add\smissing\slicense\sheader.\sMinor\scleanups\sin\sSQLTester.
+D 2023-08-08T00:59:40.520
F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1
F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea
F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724
F ext/jni/src/org/sqlite/jni/sqlite3_context.java d26573fc7b309228cb49786e9078597d96232257defa955a3425d10897bca810
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 c4cadc7d0a8c86a9369a55527d711558206f8d2cf0ee8e26c1c1167a247e9c16
-F ext/jni/src/org/sqlite/jni/tester/TestScript.java ed3cbc0371d0949293d9cc1925ce79d0d354fbe5282042dfbfe60c6e9d792fcd
+F ext/jni/src/org/sqlite/jni/tester/Outer.java c35a54bd3fd3363ba2abb5533453454d8ffe3f942c9a37a7921c8f6739762e82
+F ext/jni/src/org/sqlite/jni/tester/SQLTester.java d89dc9921b41aea67ee3c69e763671467042b33b62085aa7a44444856c4eca3f
+F ext/jni/src/org/sqlite/jni/tester/TestScript.java 6a631e2ecce24734bd93631ce00446ed109aaeb1ea6666f7a8aff74d96221a6a
F ext/jni/src/org/sqlite/jni/tester/test-script-interpreter.md 2627f8ac7c3d3f502404d9a9b8481bad5c2d11df7fdf25fbd0e1dbd2bcaa54c3
-F ext/jni/src/tests/000_first.test 29cc4ab0fa97a296ba0e2a7d821f7869503eec52e0fdb9de6a536dd02dd01946
+F ext/jni/src/tests/000_first.test 0a066e5e30189545ca4f3586d45db6c08195a50bd2f00907b4d6a3727ff58c02
F ext/jni/src/tests/010_ignored.test ce2de6742ff1bf98d8976fda0f260ff3d280e8f8c0a99309fb59fcfef2556fcd
F ext/lsm1/Makefile a553b728bba6c11201b795188c5708915cc4290f02b7df6ba7e8c4c943fd5cd9
F ext/lsm1/Makefile.msc f8c878b467232226de288da320e1ac71c131f5ec91e08b21f502303347260013
F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc
F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e
F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0
-P e0a06931e91459ea43fed2954568bfafa7ad6b794fcff66e0d3bf0ed181db386
-R 6790dfdd79e39541015901c80293f883
+P 9e61af75ac83e74487a6ae681ee3ff891d8cf1f1d23bf895e9e3963ddf6eaf28
+R 75e2a8b50272267a155f3645b409db9d
U stephan
-Z 7dd3c312d5e23f2927529b8054c01871
+Z fbbe7908dd24ba8c5b8dfecd37f39fe7
# Remove this line to create a well-formed Fossil manifest.
-9e61af75ac83e74487a6ae681ee3ff891d8cf1f1d23bf895e9e3963ddf6eaf28
\ No newline at end of file
+5be50fd5887e5378f7d66405bff3a44117a826a17e5f1a18c5129d1109ecdae2
\ No newline at end of file