More SQLTester docs. Add --verbosity command to help zoom in on script areas while debugging. Spice up test-start/end output with some emoji.

FossilOrigin-Name: 8dd08021496f504c23945ecc2bbe1e4a13109fdd03457ca6269b4cb1cc4cd04c
This commit is contained in:
stephan 2023-08-10 10:34:50 +00:00
parent 63fb588d30
commit ec8298fbd1
4 changed files with 89 additions and 45 deletions

View File

@ -232,13 +232,23 @@ public class SQLTester {
openDb(0, initialDbName, true);
}
static final String[] startEmoji = {
"🚴", "🏄", "🏇", "🤸", "", "🏊", "", "🧗", "🏋"
};
static final int nStartEmoji = startEmoji.length;
static int iStartEmoji = 0;
private static String nextStartEmoji(){
return startEmoji[iStartEmoji++ % nStartEmoji];
}
public void runTests() throws Exception {
for(String f : listInFiles){
reset();
setupInitialDb();
++nTestFile;
final TestScript ts = new TestScript(f);
outln("----->>>>> running [",f,"]");
outln(nextStartEmoji(), " starting [",f,"]");
try{
ts.run(this);
}catch(SQLTesterException e){
@ -246,7 +256,7 @@ public class SQLTester {
++nAbortedScript;
if( e.isFatal() ) throw e;
}finally{
outln("<<<<<----- ",nTest," test(s) in ",ts.getFilename());
outln("🏁 ",nTest," test(s) in ",ts.getFilename());
}
}
Util.unlink(initialDbName);
@ -561,6 +571,7 @@ public class SQLTester {
if(a.startsWith("-")){
final String flag = a.replaceFirst("-+","");
if( flag.equals("verbose") ){
// Use --verbose up to 3 times
t.setVerbosity(t.getVerbosity() + 1);
}else{
throw new IllegalArgumentException("Unhandled flag: "+flag);
@ -678,7 +689,9 @@ abstract class Command {
Must process one command-unit of work and either return
(on success) or throw (on error).
The first two arguments specify the context of the test.
The first two arguments specify the context of the test. The TestScript
provides the content of the test and the SQLTester providers the sandbox
in which that script is being evaluated.
argv is a list with the command name followed by any arguments to
that command. The argcCheck() method from this class provides
@ -854,7 +867,7 @@ class ResultCommand extends Command {
final String sArgs = argv.length>1 ? Util.argvToString(argv) : "";
if( !result.equals(sArgs) ){
t.outln(argv[0]," FAILED comparison. Result buffer:\n",
result,"\nargs:\n",sArgs);
result,"\nExpected result:\n",sArgs);
ts.toss(argv[0]+" comparison failed.");
}
}
@ -934,7 +947,15 @@ class TestCaseCommand extends Command {
}
}
class CommandDispatcher2 {
//! --verbosity command
class VerbosityCommand extends Command {
public void process(SQLTester t, TestScript ts, String[] argv) throws Exception{
argcCheck(ts,argv,1);
ts.setVerbosity( Integer.parseInt(argv[1]) );
}
}
class CommandDispatcher {
private static java.util.Map<String,Command> commandMap =
new java.util.HashMap<>();
@ -947,22 +968,23 @@ class CommandDispatcher2 {
Command rv = commandMap.get(name);
if( null!=rv ) return rv;
switch(name){
case "close": rv = new CloseDbCommand(); break;
case "column-names":rv = new ColumnNamesCommand(); break;
case "db": rv = new DbCommand(); break;
case "glob": rv = new GlobCommand(); break;
case "json": rv = new JsonCommand(); break;
case "json-block": rv = new JsonBlockCommand(); break;
case "new": rv = new NewDbCommand(); break;
case "notglob": rv = new NotGlobCommand(); break;
case "null": rv = new NullCommand(); break;
case "oom": rv = new NoopCommand(); break;
case "open": rv = new OpenDbCommand(); break;
case "print": rv = new PrintCommand(); break;
case "result": rv = new ResultCommand(); break;
case "run": rv = new RunCommand(); break;
case "tableresult": rv = new TableResultCommand(); break;
case "testcase": rv = new TestCaseCommand(); break;
case "close": rv = new CloseDbCommand(); break;
case "column-names": rv = new ColumnNamesCommand(); break;
case "db": rv = new DbCommand(); break;
case "glob": rv = new GlobCommand(); break;
case "json": rv = new JsonCommand(); break;
case "json-block": rv = new JsonBlockCommand(); break;
case "new": rv = new NewDbCommand(); break;
case "notglob": rv = new NotGlobCommand(); break;
case "null": rv = new NullCommand(); break;
case "oom": rv = new NoopCommand(); break;
case "open": rv = new OpenDbCommand(); break;
case "print": rv = new PrintCommand(); break;
case "result": rv = new ResultCommand(); break;
case "run": rv = new RunCommand(); break;
case "tableresult": rv = new TableResultCommand(); break;
case "testcase": rv = new TestCaseCommand(); break;
case "verbosity": rv = new VerbosityCommand(); break;
default: rv = null; break;
}
if( null!=rv ) commandMap.put(name, rv);
@ -990,24 +1012,38 @@ class CommandDispatcher2 {
evaluation are delegated elsewhere.
*/
class TestScript {
//! input file
private String filename = null;
//! Name pulled from the SCRIPT_MODULE_NAME directive of the file
private String moduleName = null;
//! Content buffer state.
private final Cursor cur = new Cursor();
//! Utility for console output.
private final Outer outer = new Outer();
//! File content and parse state.
private static final class Cursor {
private final StringBuilder sb = new StringBuilder();
byte[] src = null;
//! Current position in this.src.
int pos = 0;
int putbackPos = 0;
int putbackLineNo = 0;
//! Current line number. Starts at 0 for internal reasons and will
// line up with 1-based reality once parsing starts.
int lineNo = 0 /* yes, zero */;
//! Putback value for this.pos.
int putbackPos = 0;
//! Putback line number
int putbackLineNo = 0;
//! Peeked-to pos, used by peekLine() and consumePeeked().
int peekedPos = 0;
//! Peeked-to line number.
int peekedLineNo = 0;
boolean inComment = false;
void reset(){
sb.setLength(0); pos = 0; lineNo = 0/*yes, zero*/; inComment = false;
//! Restore parsing state to the start of the stream.
void rewind(){
sb.setLength(0);
pos = lineNo = putbackPos = putbackLineNo = peekedPos = peekedLineNo = 0
/* kinda missing memset() about now. */;
}
}
@ -1033,6 +1069,10 @@ class TestScript {
return moduleName;
}
/**
Verbosity level 0 produces no debug/verbose output. Level 1 produces
some and level 2 produces more.
*/
public void setVerbosity(int level){
outer.setVerbosity(level);
}
@ -1041,6 +1081,8 @@ class TestScript {
return "["+(moduleName==null ? filename : moduleName)+"] line "+
cur.lineNo;
}
//! Output vals only if level<=current verbosity level.
private TestScript verboseN(int level, Object... vals){
final int verbosity = outer.getVerbosity();
if(verbosity>=level){
@ -1053,17 +1095,12 @@ class TestScript {
private TestScript verbose1(Object... vals){return verboseN(1,vals);}
private TestScript verbose2(Object... vals){return verboseN(2,vals);}
public TestScript warn(Object... vals){
outer.out("WARNING ", getOutputPrefix(),": ").outln(vals);
return this;
}
private TestScript verbose3(Object... vals){return verboseN(3,vals);}
private void reset(){
cur.reset();
cur.rewind();
}
/**
Returns the next line from the buffer, minus the trailing EOL.
@ -1257,7 +1294,7 @@ class TestScript {
final Matcher m = patternCommand.matcher(line);
boolean rc = m.find();
if( rc && checkForImpl ){
rc = null!=CommandDispatcher2.getCommandByName(m.group(2));
rc = null!=CommandDispatcher.getCommandByName(m.group(2));
}
return rc;
}
@ -1300,9 +1337,9 @@ class TestScript {
verbose1("running command: ",argv[0], " ", Util.argvToString(argv));
if(outer.getVerbosity()>1){
final String input = t.getInputText();
if( !input.isEmpty() ) verbose2("Input buffer = ",input);
if( !input.isEmpty() ) verbose3("Input buffer = ",input);
}
CommandDispatcher2.dispatch(t, this, argv);
CommandDispatcher.dispatch(t, this, argv);
}
void toss(Object... msg) throws TestScriptFailed {
@ -1320,7 +1357,7 @@ class TestScript {
String line, directive;
String[] argv;
while( null != (line = getLine()) ){
//verbose(line);
verbose3("input line: ",line);
checkForDirective(tester, line);
argv = getCommandArgv(line);
if( null!=argv ){

View File

@ -260,3 +260,10 @@ is always an exact strcmp() not a GLOB.
The --print command emits both its arguments and its body (if any) to
stdout, indenting each line of output.
### The --column-names command
The --column-names command requires 0 or 1 as an argument, to disable
resp. enable it, and modifies SQL execution to include column names
in output. When this option is on, each column value emitted gets
prefixed by its column name, with a single space between them.

View File

@ -1,5 +1,5 @@
C Give\sDbException\sthe\soption\sof\sclosing\sthe\sdb\sto\ssimplify\serror\shandling\sin\sone\scase.
D 2023-08-10T05:25:13.132
C More\sSQLTester\sdocs.\sAdd\s--verbosity\scommand\sto\shelp\szoom\sin\son\sscript\sareas\swhile\sdebugging.\sSpice\sup\stest-start/end\soutput\swith\ssome\semoji.
D 2023-08-10T10:34:50.418
F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1
F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea
F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724
@ -266,8 +266,8 @@ F ext/jni/src/org/sqlite/jni/sqlite3.java 62b1b81935ccf3393472d17cb883dc5ff39c38
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 4a0504164c632b817f8fc14f93c455da6b7bcf05fcb0bab2cf28e7fda086d009
F ext/jni/src/org/sqlite/jni/tester/test-script-interpreter.md ab7169b08566a082ef55c9ef8a553827f99958ed3e076f31eef757563fae51ba
F ext/jni/src/org/sqlite/jni/tester/SQLTester.java bdc96c5c8a94e49a9e4af6774da1f7373062c9a9f854e0236feaf338552f3018
F ext/jni/src/org/sqlite/jni/tester/test-script-interpreter.md f9f25126127045d051e918fe59004a1485311c50a13edbf18c79a6ff9160030e
F ext/jni/src/tests/000-000-sanity.test 35817746f1909cc9af5d3e890ee94a43c47ce47127da9cca7d39b0e132d36c84
F ext/jni/src/tests/000-001-ignored.test e17e874c6ab3c437f1293d88093cf06286083b65bf162317f91bbfd92f961b70
F ext/lsm1/Makefile a553b728bba6c11201b795188c5708915cc4290f02b7df6ba7e8c4c943fd5cd9
@ -2089,8 +2089,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 48d16c9d2fe5f54b09004b4f09759c4e2ad247ae84130feb557951e32f48976a
R 76947bac9cc560f2389ffc3d550b2e03
P 908c9a44505422a3a15bef3a174d8b931863bc9c74485311a0e62cfec30087bd
R 723877b1e83c903a6eebac5debe5b713
U stephan
Z 6304bd9479984f92f8657a18da8e93ff
Z 9ac434387da17df208fe2a5e4745ca4c
# Remove this line to create a well-formed Fossil manifest.

View File

@ -1 +1 @@
908c9a44505422a3a15bef3a174d8b931863bc9c74485311a0e62cfec30087bd
8dd08021496f504c23945ecc2bbe1e4a13109fdd03457ca6269b4cb1cc4cd04c