aboutsummaryrefslogtreecommitdiff
path: root/ext/wasm/SQLTester/SQLTester.run.mjs
diff options
context:
space:
mode:
Diffstat (limited to 'ext/wasm/SQLTester/SQLTester.run.mjs')
-rw-r--r--ext/wasm/SQLTester/SQLTester.run.mjs73
1 files changed, 48 insertions, 25 deletions
diff --git a/ext/wasm/SQLTester/SQLTester.run.mjs b/ext/wasm/SQLTester/SQLTester.run.mjs
index e6730253b..4a0890459 100644
--- a/ext/wasm/SQLTester/SQLTester.run.mjs
+++ b/ext/wasm/SQLTester/SQLTester.run.mjs
@@ -12,7 +12,7 @@
** This file contains a test application for SQLTester.js.
*/
import {default as ns} from './SQLTester.mjs';
-import {default as tests} from './test-list.mjs';
+import {default as allTests} from './test-list.mjs';
globalThis.sqlite3 = ns.sqlite3;
const log = function f(...args){
@@ -33,8 +33,6 @@ const affirm = function(expr, msg){
}
}
-log("SQLTester is ready.");
-
let ts = new ns.TestScript('/foo.test',`
/*
** This is a comment. There are many like it but this one is mine.
@@ -56,10 +54,10 @@ let ts = new ns.TestScript('/foo.test',`
--oom
--db 0
--new my.db
---null zilchy
+--null zilch
--testcase 1.0
SELECT 1, null;
---result 1 zilchy
+--result 1 zilch
--glob *zil*
--notglob *ZIL*
SELECT 1, 2;
@@ -94,29 +92,54 @@ SELECT json_array(1,2,3)
--print Until next time
`);
-const sqt = new ns.SQLTester();
-try{
- if( 0 ){
- affirm( !sqt.getCurrentDb(), 'sqt.getCurrentDb()' );
- sqt.openDb('/foo.db', true);
- affirm( !!sqt.getCurrentDb(),'sqt.getCurrentDb()' );
- sqt.verbosity(0);
- if(false){
+const sqt = new ns.SQLTester()
+ .setLogger(console.log.bind(console))
+ .verbosity(1)
+ .addTestScript(ts);
+
+const runTests = function(){
+ try{
+ if( 0 ){
+ affirm( !sqt.getCurrentDb(), 'sqt.getCurrentDb()' );
+ sqt.openDb('/foo.db', true);
+ affirm( !!sqt.getCurrentDb(),'sqt.getCurrentDb()' );
affirm( 'zilch' !== sqt.nullValue() );
ts.run(sqt);
affirm( 'zilch' === sqt.nullValue() );
+ sqt.addTestScript(ts);
+ sqt.runTests();
+ }else{
+ for(const t of allTests){
+ sqt.addTestScript( new ns.TestScript(t) );
+ }
+ allTests.length = 0;
+ sqt.runTests();
}
- sqt.addTestScript(ts);
- sqt.runTests();
- }else{
- for(const t of tests){
- sqt.addTestScript( new ns.TestScript(t) );
- }
- tests.length = 0;
- sqt.verbosity(0);
- sqt.runTests();
+ }finally{
+ //log( "Metrics:", sqt.metrics );
+ sqt.reset();
}
-}finally{
- log( "Metrics:", sqt.metrics );
- sqt.reset();
+};
+
+if( globalThis.WorkerGlobalScope ){
+ const wPost = (type,payload)=>globalThis.postMessage({type, payload});
+ globalThis.onmessage = function({data}){
+ switch(data.type){
+ case 'run-tests':{
+ try{ runTests(); }
+ finally{ wPost('tests-end'); }
+ break;
+ }
+ default:
+ log("unhandled onmessage: ",data);
+ break;
+ }
+ };
+ sqt.setLogger((msg)=>{
+ wPost('stdout', {message: msg});
+ });
+ wPost('is-ready');
+ //globalThis.onmessage({data:{type:'run-tests'}});
+}else{
+ runTests();
}