mirror of
https://github.com/sqlite/sqlite.git
synced 2025-07-29 08:01:23 +03:00
SQLTester can now read a script and strip it of all noise content.
FossilOrigin-Name: 59bd392817ac69ffdf60ab7a2094b0d616bf593da060b6acf1b4ce9837847fcb
This commit is contained in:
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
|
||||
|
Reference in New Issue
Block a user