SQLTester can now split a test script into a series of individual commands.

FossilOrigin-Name: d3d1accc8b4ba0cd396ee3a58d9710a54b8e1d1b171d67595d4ef1fc7faea8cb
This commit is contained in:
stephan 2023-08-07 22:32:22 +00:00
parent 70679d135d
commit fdeaee5f57
4 changed files with 53 additions and 32 deletions

View File

@ -21,12 +21,15 @@ public class TestScript {
return java.nio.file.Files.readAllBytes(java.nio.file.Paths.get(filename)); return java.nio.file.Files.readAllBytes(java.nio.file.Paths.get(filename));
} }
private void setContent(String c){
content = c;
}
/** /**
Initializes the script with the content of the given file. Initializes the script with the content of the given file.
*/ */
public TestScript(String filename) throws IOException{ public TestScript(String filename) throws IOException{
this.content = new String(readFile(filename), setContent(new String(readFile(filename),
java.nio.charset.StandardCharsets.UTF_8); java.nio.charset.StandardCharsets.UTF_8));
} }
/** /**
@ -34,16 +37,16 @@ public class TestScript {
at construction-time. at construction-time.
*/ */
public TestScript(StringBuffer content){ public TestScript(StringBuffer content){
this.content = content.toString(); setContent(content.toString());
} }
public void setVerbose(boolean b){ public void setVerbose(boolean b){
this.outer.setVerbose(b); outer.setVerbose(b);
} }
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
private <T> TestScript verbose(T... vals){ private <T> TestScript verbose(T... vals){
this.outer.verbose(vals); outer.verbose(vals);
return this; return this;
} }
@ -53,43 +56,53 @@ public class TestScript {
C-style comments from expected script output, which might or might not C-style comments from expected script output, which might or might not
be a real problem. be a real problem.
*/ */
private String chunkContent(){ private List<String> chunkContent(String input){
final String sCComment = final String sCComment =
"[/][*]([*](?![/])|[^*])*[*][/]" "[/][*]([*](?![/])|[^*])*[*][/]"
//"/\\*[^/*]*(?:(?!/\\*|\\*/)[/*][^/*]*)*\\*/" //"/\\*[^/*]*(?:(?!/\\*|\\*/)[/*][^/*]*)*\\*/"
; ;
final String s3Dash = "^---[^\\n]*\\n"; final String s3Dash = "^---+[^\\n]*\\n";
final String sTclComment = "^#[^\\n]*\\n"; final String sTclComment = "^#[^\\n]*\\n";
final String sEmptyLine = "^\\n"; final String sEmptyLine = "^\\n";
final String sCommand = "^--.*$";
final List<String> lPats = new ArrayList<>(); final List<String> lPats = new ArrayList<>();
lPats.add(sCComment); lPats.add(sCComment);
lPats.add(s3Dash); lPats.add(s3Dash);
lPats.add(sTclComment); lPats.add(sTclComment);
lPats.add(sEmptyLine); lPats.add(sEmptyLine);
//lPats.add(sCommand); //verbose("Content:").verbose(input).verbose("<EOF>");
verbose("Content:").verbose(content).verbose("<EOF>"); String tmp = input;
String tmp = content;
for( String s : lPats ){ for( String s : lPats ){
final Pattern p = Pattern.compile( final Pattern p = Pattern.compile(
s, Pattern.MULTILINE s, Pattern.MULTILINE
); );
final Matcher m = p.matcher(tmp); final Matcher m = p.matcher(tmp);
verbose("Pattern {{{",p.pattern(),"}}} with flags", /*verbose("Pattern {{{",p.pattern(),"}}} with flags",
""+p.flags(),"matches:" ""+p.flags(),"matches:"
); );*/
int n = 0; int n = 0;
while(m.find()){ //while( m.find() ) verbose("#"+(++n)+"\t",m.group(0).trim());
verbose("#"+(++n)+"\t",m.group(0).trim());
}
tmp = m.replaceAll(""); tmp = m.replaceAll("");
} }
//final Pattern patCComments = new Pattern(); // Chunk the newly-stripped text into individual commands.
//tmp = content.replace(sCComment,""); final String sCommand = "^--";
//tmp = tmp.replace(s3Dash,""); final List<String> rc = new ArrayList<>();
//tmp = tmp.replace(sTclComment,""); final Pattern p = Pattern.compile(
//tmp = tmp.replace(sEmptyLine,""); sCommand, Pattern.MULTILINE
return tmp; );
final Matcher m = p.matcher(tmp);
int ndxPrev = 0, pos = 0;
String chunk;
while( m.find() ){
pos = m.start();
chunk = tmp.substring(ndxPrev, pos).trim();
if( !chunk.isEmpty() ) rc.add( chunk );
ndxPrev = pos + 2;
}
if( ndxPrev != pos + 2 ){
chunk = tmp.substring(ndxPrev, tmp.length()).trim();
if( !chunk.isEmpty() ) rc.add( chunk );
}
return rc;
} }
/** /**
@ -97,7 +110,12 @@ public class TestScript {
in some form or other (possibly mangled from its original). in some form or other (possibly mangled from its original).
*/ */
public void dump(){ public void dump(){
String s = this.chunkContent(); List<String> list = chunkContent(content);
this.verbose("chunked script:").verbose(s).verbose("<EOF>"); verbose("script chunked by command:");
int n = 0;
for(String c : list){
verbose("#"+(++n),c);
}
verbose("<EOF>");
} }
} }

View File

@ -4,6 +4,9 @@
--null NULL --null NULL
--- also ignored --- also ignored
--testcase first
input for the first
command;
--testcase second --testcase second
select 1 select 1
--result /* ignored */ --result /* ignored */

View File

@ -1,5 +1,5 @@
C SQLTester\scan\snow\sread\sa\sscript\sand\sstrip\sit\sof\sall\snoise\scontent. C SQLTester\scan\snow\ssplit\sa\stest\sscript\sinto\sa\sseries\sof\sindividual\scommands.
D 2023-08-07T22:02:43.384 D 2023-08-07T22:32:22.258
F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1
F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea
F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724
@ -266,9 +266,9 @@ F ext/jni/src/org/sqlite/jni/sqlite3_stmt.java 78e6d1b95ac600a9475e9db4623f69449
F ext/jni/src/org/sqlite/jni/sqlite3_value.java 3d1d4903e267bc0bc81d57d21f5e85978eff389a1a6ed46726dbe75f85e6914a 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/Outer.java 8931ff9f152d22a822ff98831a4e924da48016ff1f1f84042390a6f51ad7b48f
F ext/jni/src/org/sqlite/jni/tester/SQLTester.java edcab1ea3d7848523416b881061f8095e8f7ae2a626e07947a55a4215898e040 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/TestScript.java 00007d167ce5b40506a624bad1fb8571a0b975285849a7bd8fd7c0ebcfb3f785
F ext/jni/src/org/sqlite/jni/tester/test-script-interpreter.md ba3cf6584783939c8797a67203e63ec588430fdc0b7719f24873e6731c6d0445 F ext/jni/src/org/sqlite/jni/tester/test-script-interpreter.md ba3cf6584783939c8797a67203e63ec588430fdc0b7719f24873e6731c6d0445
F ext/jni/src/tests/000_first.test 9a6622455cc4be00d332be655e0d2d5cf07a2d2b041f8d1950f66bda4873deed F ext/jni/src/tests/000_first.test a06b72b6815246a21f6a4b14126bbc40b9cd1e3b03410431ed50203cfa942e9b
F ext/lsm1/Makefile a553b728bba6c11201b795188c5708915cc4290f02b7df6ba7e8c4c943fd5cd9 F ext/lsm1/Makefile a553b728bba6c11201b795188c5708915cc4290f02b7df6ba7e8c4c943fd5cd9
F ext/lsm1/Makefile.msc f8c878b467232226de288da320e1ac71c131f5ec91e08b21f502303347260013 F ext/lsm1/Makefile.msc f8c878b467232226de288da320e1ac71c131f5ec91e08b21f502303347260013
F ext/lsm1/lsm-test/README 87ea529d2abe615e856d4714bfe8bb185e6c2771b8612aa6298588b7b43e6f86 F ext/lsm1/lsm-test/README 87ea529d2abe615e856d4714bfe8bb185e6c2771b8612aa6298588b7b43e6f86
@ -2088,8 +2088,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93
F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc
F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e
F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0
P 2aa8f0edecd3fc30eec28987cdbf1003ace154ddc1447b6f8715ecf38d3b06fb P 59bd392817ac69ffdf60ab7a2094b0d616bf593da060b6acf1b4ce9837847fcb
R f4841d676ff176af3cb93558f987461f R 63407ef8cfa2823943afd16b1a637995
U stephan U stephan
Z c343b0e8d67b2614399479523c827e4a Z 2b2535b40ad95e4630d07d7436d967c8
# Remove this line to create a well-formed Fossil manifest. # Remove this line to create a well-formed Fossil manifest.

View File

@ -1 +1 @@
59bd392817ac69ffdf60ab7a2094b0d616bf593da060b6acf1b4ce9837847fcb d3d1accc8b4ba0cd396ee3a58d9710a54b8e1d1b171d67595d4ef1fc7faea8cb