1
0
mirror of https://github.com/sqlite/sqlite.git synced 2025-08-07 02:42:48 +03:00

More fleshing out of JS SQLTester.

FossilOrigin-Name: 8c503dfb9fa15389613a819fcc1792e23d3c05f99a9f450f82eac5125298726f
This commit is contained in:
stephan
2023-08-29 20:44:40 +00:00
parent aa15047796
commit 267c44771f
5 changed files with 84 additions and 27 deletions

View File

@@ -203,8 +203,8 @@ class SQLTester {
//! Console output utility.
#outer = new Outer().outputPrefix( ()=>'SQLTester: ' );
//! List of input script files.
#aFiles = [];
//! List of input scripts.
#aScripts = [];
//! Test input buffer.
#inputBuffer = [];
//! Test result buffer.
@@ -259,7 +259,7 @@ class SQLTester {
this.nullView = "nil";
this.emitColNames = false;
this.#db.iCurrentDb = 0;
this.#db.initSql.push("SELECT 1;");
//this.#db.initSql.push("SELECT 1;");
}
appendInput(line, addNL){
@@ -402,6 +402,54 @@ class SQLTester {
}
}
addTestScript(ts){
if( 2===arguments.length ){
ts = new TestScript(arguments[0], arguments[1]);
}else if(ts instanceof Uint8Array){
ts = new TestScript('<unnamed>', ts);
}else if('string' === typeof arguments[1]){
ts = new TestScript('<unnamed>', Util.utf8Encode(arguments[1]));
}
if( !(ts instanceof TestScript) ){
Util.toss(SQLTesterException, "Invalid argument type for addTestScript()");
}
this.#aScripts.push(ts);
return this;
}
runTests(){
const tStart = (new Date()).getTime();
for(const ts of this.#aScripts){
this.reset();
++this.metrics.nTestFile;
let threw = false;
const timeStart = (new Date()).getTime();
try{
ts.run(this);
}catch(e){
if(e instanceof SQLTesterException){
threw = true;
this.outln("🔥EXCEPTION: ",''+e);
++this.metrics.nAbortedScript;
if( this.#keepGoing ){
this.outln("Continuing anyway becaure of the keep-going option.");
}
else if( e.isFatal() ) throw e;
}else{
throw e;
}
}finally{
const timeEnd = (new Date()).getTime();
this.outln("🏁", (threw ? "❌" : "✅"), " ", this.metrics.nTest,
" test(s) in ", (timeEnd-timeStart),"ms.");
}
}
const tEnd = (new Date()).getTime();
this.outln("Total run-time: ",(tEnd-tStart),"ms");
Util.unlink(this.#db.initialDbName);
return this;
}
#setupInitialDb(){
if( !this.#db.list[0] ){
Util.unlink(this.#db.initialDbName);
@@ -466,7 +514,7 @@ class SQLTester {
const wasm = sqlite3.wasm, capi = sqlite3.capi;
sql = (sql instanceof Uint8Array)
? sql
: new TextEncoder("utf-8").encode(capi.sqlite3_js_sql_to_string(sql));
: Util.utf8Encode(capi.sqlite3_js_sql_to_string(sql));
const self = this;
const sb = (ResultBufferMode.NONE===appendMode) ? null : this.#resultBuffer;
let rc = 0;
@@ -616,6 +664,15 @@ class TestScript {
}else{
content = args[0];
}
if(!(content instanceof Uint8Array)){
if('string' === typeof content){
content = Util.utf8Encode(content);
}else if(content instanceof ArrayBuffer){
content = new Uint8Array(content);
}else{
toss(Error, "Invalid content type for TestScript constructor.");
}
}
this.#filename = filename;
this.#cursor.src = content;
}
@@ -971,28 +1028,24 @@ class TableResultCommand extends Command {
this.argcCheck(ts,argv,0);
t.incrementTestCounter();
let body = ts.fetchCommandBody(t);
log("TRC fetchCommandBody: ",body);
if( null===body ) ts.toss("Missing ",argv[0]," body.");
body = body.trim();
if( !body.endsWith("\n--end") ){
ts.toss(argv[0], " must be terminated with --end\\n");
}else{
body = body.substring(0, body.length-6);
log("TRC fetchCommandBody reshaped:",body);
}
const globs = body.split(/\s*\n\s*/);
if( globs.length < 1 ){
ts.toss(argv[0], " requires 1 or more ",
(this.#jsonMode ? "json snippets" : "globs"),".");
}
log("TRC fetchCommandBody globs:",globs);
const sql = t.takeInputBuffer();
t.execSql(null, true,
this.#jsonMode ? ResultBufferMode.ASIS : ResultBufferMode.ESCAPED,
ResultRowMode.NEWLINE, sql);
const rbuf = t.getResultText().trim();
const res = rbuf.split(/\r?\n/);
log("TRC fetchCommandBody rbuf, res:",rbuf, res);
if( res.length !== globs.length ){
ts.toss(argv[0], " failure: input has ", res.length,
" row(s) but expecting ",globs.length);