mirror of
https://github.com/sqlite/sqlite.git
synced 2025-07-30 19:03:16 +03:00
SQLTester can now read a script and strip it of all noise content.
FossilOrigin-Name: 59bd392817ac69ffdf60ab7a2094b0d616bf593da060b6acf1b4ce9837847fcb
This commit is contained in:
@ -81,6 +81,7 @@ ifeq (1,$(enable.fts5))
|
||||
)
|
||||
endif
|
||||
JAVA_FILES.tester := $(patsubst %,$(dir.src.jni.tester)/%,\
|
||||
Outer.java \
|
||||
SQLTester.java \
|
||||
TestScript.java \
|
||||
)
|
||||
|
40
ext/jni/src/org/sqlite/jni/tester/Outer.java
Normal file
40
ext/jni/src/org/sqlite/jni/tester/Outer.java
Normal file
@ -0,0 +1,40 @@
|
||||
package org.sqlite.jni.tester;
|
||||
|
||||
public class Outer {
|
||||
public boolean isVerbose = true;
|
||||
|
||||
public static <T> void out(T val){
|
||||
System.out.print(val);
|
||||
}
|
||||
|
||||
public static <T> void outln(T val){
|
||||
System.out.println(val);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public static <T> void out(T... vals){
|
||||
int n = 0;
|
||||
for(T v : vals) out((n++>0 ? " " : "")+v);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public static <T> void outln(T... vals){
|
||||
out(vals);
|
||||
out("\n");
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public <T> Outer verbose(T... vals){
|
||||
if(isVerbose) outln(vals);
|
||||
return this;
|
||||
}
|
||||
|
||||
public void setVerbose(boolean b){
|
||||
isVerbose = b;
|
||||
}
|
||||
|
||||
public boolean getVerbose(){
|
||||
return isVerbose;
|
||||
}
|
||||
|
||||
}
|
@ -12,39 +12,19 @@ import static org.sqlite.jni.SQLite3Jni.*;
|
||||
*/
|
||||
public class SQLTester {
|
||||
//! List of input script files.
|
||||
private java.util.List<String> listInFiles = new ArrayList<>();
|
||||
private boolean isVerbose = true;
|
||||
private final java.util.List<String> listInFiles = new ArrayList<>();
|
||||
private final Outer outer = new Outer();
|
||||
|
||||
public SQLTester(){
|
||||
}
|
||||
|
||||
public void setVerbose(boolean b){
|
||||
isVerbose = b;
|
||||
}
|
||||
|
||||
public static <T> void out(T val){
|
||||
System.out.print(val);
|
||||
}
|
||||
|
||||
public static <T> void outln(T val){
|
||||
System.out.println(val);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public static <T> void out(T... vals){
|
||||
int n = 0;
|
||||
for(T v : vals) out((n++>0 ? " " : "")+v);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public static <T> void outln(T... vals){
|
||||
out(vals);
|
||||
out("\n");
|
||||
this.outer.setVerbose(b);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private <T> void verbose(T... vals){
|
||||
if(isVerbose) outln(vals);
|
||||
this.outer.verbose(vals);
|
||||
}
|
||||
|
||||
//! Adds the given test script to the to-test list.
|
||||
@ -58,6 +38,8 @@ public class SQLTester {
|
||||
for(String f : listInFiles){
|
||||
verbose("Running test script",f);
|
||||
final TestScript ts = new TestScript(f);
|
||||
ts.setVerbose(this.outer.getVerbose());
|
||||
ts.dump();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,6 +1,8 @@
|
||||
package org.sqlite.jni.tester;
|
||||
import java.util.List;
|
||||
import java.util.ArrayList;
|
||||
import java.io.*;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.regex.*;
|
||||
//import java.util.List;
|
||||
//import java.util.ArrayList;
|
||||
|
||||
@ -13,6 +15,7 @@ import java.nio.charset.StandardCharsets;
|
||||
public class TestScript {
|
||||
//! Test script content.
|
||||
private String content;
|
||||
private final Outer outer = new Outer();
|
||||
|
||||
private byte[] readFile(String filename) throws IOException {
|
||||
return java.nio.file.Files.readAllBytes(java.nio.file.Paths.get(filename));
|
||||
@ -23,7 +26,7 @@ public class TestScript {
|
||||
*/
|
||||
public TestScript(String filename) throws IOException{
|
||||
this.content = new String(readFile(filename),
|
||||
StandardCharsets.UTF_8);
|
||||
java.nio.charset.StandardCharsets.UTF_8);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -33,4 +36,68 @@ public class TestScript {
|
||||
public TestScript(StringBuffer content){
|
||||
this.content = content.toString();
|
||||
}
|
||||
|
||||
public void setVerbose(boolean b){
|
||||
this.outer.setVerbose(b);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private <T> TestScript verbose(T... vals){
|
||||
this.outer.verbose(vals);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
A quick-and-dirty approach to chopping a script up into individual
|
||||
commands. The primary problem with this is that it will remove any
|
||||
C-style comments from expected script output, which might or might not
|
||||
be a real problem.
|
||||
*/
|
||||
private String chunkContent(){
|
||||
final String sCComment =
|
||||
"[/][*]([*](?![/])|[^*])*[*][/]"
|
||||
//"/\\*[^/*]*(?:(?!/\\*|\\*/)[/*][^/*]*)*\\*/"
|
||||
;
|
||||
final String s3Dash = "^---[^\\n]*\\n";
|
||||
final String sTclComment = "^#[^\\n]*\\n";
|
||||
final String sEmptyLine = "^\\n";
|
||||
final String sCommand = "^--.*$";
|
||||
final List<String> lPats = new ArrayList<>();
|
||||
lPats.add(sCComment);
|
||||
lPats.add(s3Dash);
|
||||
lPats.add(sTclComment);
|
||||
lPats.add(sEmptyLine);
|
||||
//lPats.add(sCommand);
|
||||
verbose("Content:").verbose(content).verbose("<EOF>");
|
||||
String tmp = content;
|
||||
for( String s : lPats ){
|
||||
final Pattern p = Pattern.compile(
|
||||
s, Pattern.MULTILINE
|
||||
);
|
||||
final Matcher m = p.matcher(tmp);
|
||||
verbose("Pattern {{{",p.pattern(),"}}} with flags",
|
||||
""+p.flags(),"matches:"
|
||||
);
|
||||
int n = 0;
|
||||
while(m.find()){
|
||||
verbose("#"+(++n)+"\t",m.group(0).trim());
|
||||
}
|
||||
tmp = m.replaceAll("");
|
||||
}
|
||||
//final Pattern patCComments = new Pattern();
|
||||
//tmp = content.replace(sCComment,"");
|
||||
//tmp = tmp.replace(s3Dash,"");
|
||||
//tmp = tmp.replace(sTclComment,"");
|
||||
//tmp = tmp.replace(sEmptyLine,"");
|
||||
return tmp;
|
||||
}
|
||||
|
||||
/**
|
||||
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(){
|
||||
String s = this.chunkContent();
|
||||
this.verbose("chunked script:").verbose(s).verbose("<EOF>");
|
||||
}
|
||||
}
|
||||
|
@ -2,3 +2,9 @@
|
||||
|
||||
# this line is ignored
|
||||
|
||||
--null NULL
|
||||
--- also ignored
|
||||
--testcase second
|
||||
select 1
|
||||
--result /* ignored */
|
||||
1
|
||||
|
19
manifest
19
manifest
@ -1,5 +1,5 @@
|
||||
C Initial\sskeleton\sfor\sadding\san\sSQL-driven\stest\sscript\sinterpreter\sfor\sthe\sJNI\sbindings.
|
||||
D 2023-08-07T21:04:13.706
|
||||
C SQLTester\scan\snow\sread\sa\sscript\sand\sstrip\sit\sof\sall\snoise\scontent.
|
||||
D 2023-08-07T22:02:43.384
|
||||
F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1
|
||||
F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea
|
||||
F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724
|
||||
@ -230,7 +230,7 @@ F ext/fts5/tool/showfts5.tcl d54da0e067306663e2d5d523965ca487698e722c
|
||||
F ext/icu/README.txt 7ab7ced8ae78e3a645b57e78570ff589d4c672b71370f5aa9e1cd7024f400fc9
|
||||
F ext/icu/icu.c c074519b46baa484bb5396c7e01e051034da8884bad1a1cb7f09bbe6be3f0282
|
||||
F ext/icu/sqliteicu.h fa373836ed5a1ee7478bdf8a1650689294e41d0c89c1daab26e9ae78a32075a8
|
||||
F ext/jni/GNUmakefile e492513ab2fc6da4f01d6745c852d3ef0afa336994e91a513b523ae8ececcde8
|
||||
F ext/jni/GNUmakefile 2b800c74db98b64b63ec1da48dc4a27738f88951f0ca43011288abf80c1b5e80
|
||||
F ext/jni/README.md e965674505e105626127ad45e628e4d19fcd379cdafc4d23c814c1ac2c55681d
|
||||
F ext/jni/src/c/sqlite3-jni.c e6463b3fc8ef000d9a5dd1649fe96a4cfc5aac21a43276424cf28d72548c5921
|
||||
F ext/jni/src/c/sqlite3-jni.h 6c06cdb1e43ce56544dfbe3335a46174dae15d03337d06e55aa7256f85d2ce1b
|
||||
@ -264,10 +264,11 @@ F ext/jni/src/org/sqlite/jni/sqlite3.java ff3729426704626a6019d97bfee512a83f253c
|
||||
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/SQLTester.java d51db80b241ba90dea253b453cd7bb44648fdf0bb84370225f63ac541e727e4a
|
||||
F ext/jni/src/org/sqlite/jni/tester/TestScript.java 67721f78f753c719e465db07abd928fa3c96ebc3917c797b42d21d89aa671a82
|
||||
F ext/jni/src/org/sqlite/jni/tester/Outer.java 8931ff9f152d22a822ff98831a4e924da48016ff1f1f84042390a6f51ad7b48f
|
||||
F ext/jni/src/org/sqlite/jni/tester/SQLTester.java edcab1ea3d7848523416b881061f8095e8f7ae2a626e07947a55a4215898e040
|
||||
F ext/jni/src/org/sqlite/jni/tester/TestScript.java 470e5c08d8badfa3194d06960fe830eb54fd78d2e086bb1f270af499ffea5f25
|
||||
F ext/jni/src/org/sqlite/jni/tester/test-script-interpreter.md ba3cf6584783939c8797a67203e63ec588430fdc0b7719f24873e6731c6d0445
|
||||
F ext/jni/src/tests/000_first.test 9d20eef5d8985ce32dc039004f186a973ca629afee9ab2134f4ec18d1748e426
|
||||
F ext/jni/src/tests/000_first.test 9a6622455cc4be00d332be655e0d2d5cf07a2d2b041f8d1950f66bda4873deed
|
||||
F ext/lsm1/Makefile a553b728bba6c11201b795188c5708915cc4290f02b7df6ba7e8c4c943fd5cd9
|
||||
F ext/lsm1/Makefile.msc f8c878b467232226de288da320e1ac71c131f5ec91e08b21f502303347260013
|
||||
F ext/lsm1/lsm-test/README 87ea529d2abe615e856d4714bfe8bb185e6c2771b8612aa6298588b7b43e6f86
|
||||
@ -2087,8 +2088,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 2d44720d06d9e50cb037e92981d2473a3ad0b7560f2f5923d428f59de6fd6aaa
|
||||
R 85efb1bd754dc306bbc436950f6f48cb
|
||||
P 2aa8f0edecd3fc30eec28987cdbf1003ace154ddc1447b6f8715ecf38d3b06fb
|
||||
R f4841d676ff176af3cb93558f987461f
|
||||
U stephan
|
||||
Z 24f4287e10d577104a22d65944b7f529
|
||||
Z c343b0e8d67b2614399479523c827e4a
|
||||
# Remove this line to create a well-formed Fossil manifest.
|
||||
|
@ -1 +1 @@
|
||||
2aa8f0edecd3fc30eec28987cdbf1003ace154ddc1447b6f8715ecf38d3b06fb
|
||||
59bd392817ac69ffdf60ab7a2094b0d616bf593da060b6acf1b4ce9837847fcb
|
Reference in New Issue
Block a user