From 524ddc940d47184bd83771781a6dbd472ccc6365 Mon Sep 17 00:00:00 2001 From: stephan Date: Tue, 29 Aug 2023 11:22:45 +0000 Subject: Init bits of a port of Java's SQLTester to JS. Far from complete. FossilOrigin-Name: 60eec5ceda80c64870713df8e9aeabeef933c007f2010792225a07d5ef36baef --- ext/wasm/SQLTester/SQLTester.run.mjs | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 ext/wasm/SQLTester/SQLTester.run.mjs (limited to 'ext/wasm/SQLTester/SQLTester.run.mjs') diff --git a/ext/wasm/SQLTester/SQLTester.run.mjs b/ext/wasm/SQLTester/SQLTester.run.mjs new file mode 100644 index 000000000..0a0f8903b --- /dev/null +++ b/ext/wasm/SQLTester/SQLTester.run.mjs @@ -0,0 +1,8 @@ +import {default as ns} from './SQLTester.mjs'; + +const log = (...args)=>{ + console.log('SQLTester.run:',...args); +}; + + +log("SQLTester is ostensibly ready."); -- cgit v1.2.3 From 0fc20a32c0fce51c34714363173c8a93771c1425 Mon Sep 17 00:00:00 2001 From: stephan Date: Tue, 29 Aug 2023 13:28:36 +0000 Subject: Get the basic parsing pieces and command dispatching in place in the JS SQLTester. FossilOrigin-Name: 8fcc2a553c1e26734902bbdee0c38183ee22b7b5c75f07405529bb79db34145a --- ext/wasm/SQLTester/SQLTester.run.mjs | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) (limited to 'ext/wasm/SQLTester/SQLTester.run.mjs') diff --git a/ext/wasm/SQLTester/SQLTester.run.mjs b/ext/wasm/SQLTester/SQLTester.run.mjs index 0a0f8903b..4efd068e3 100644 --- a/ext/wasm/SQLTester/SQLTester.run.mjs +++ b/ext/wasm/SQLTester/SQLTester.run.mjs @@ -1,8 +1,26 @@ import {default as ns} from './SQLTester.mjs'; -const log = (...args)=>{ +const log = function f(...args){ console.log('SQLTester.run:',...args); + return f; }; +console.log("Loaded",ns); +const out = function f(...args){ return f.outer.out(...args) }; +out.outer = new ns.Outer(); +out.outer.getOutputPrefix = ()=>'SQLTester.run: '; +const outln = (...args)=>{ return out.outer.outln(...args) }; -log("SQLTester is ostensibly ready."); +log("ns =",ns); +out("Hi there. ").outln("SQLTester is ostensibly ready."); + +let ts = new ns.TestScript('/foo.test', ns.Util.utf8Encode(` +# comment line +select 1; +--testcase 0.0 +#--result 1 +`)); + +const sqt = new ns.SQLTester(); +sqt.verbosity(3); +ts.run(sqt); -- cgit v1.2.3 From 69a55ca17dc711a9b75eb738ab32336936d69fd7 Mon Sep 17 00:00:00 2001 From: stephan Date: Tue, 29 Aug 2023 15:39:57 +0000 Subject: Get the JS SQLTester command handlers in place sans those which have to run SQL. FossilOrigin-Name: d21b1217964a53f33b7ba3958b34aa8560dff8ede33e66f54aa0afbab7099ec3 --- ext/wasm/SQLTester/SQLTester.run.mjs | 41 +++++++++++++++++++++++++++++------- 1 file changed, 33 insertions(+), 8 deletions(-) (limited to 'ext/wasm/SQLTester/SQLTester.run.mjs') diff --git a/ext/wasm/SQLTester/SQLTester.run.mjs b/ext/wasm/SQLTester/SQLTester.run.mjs index 4efd068e3..dc8eaa0c1 100644 --- a/ext/wasm/SQLTester/SQLTester.run.mjs +++ b/ext/wasm/SQLTester/SQLTester.run.mjs @@ -1,26 +1,51 @@ import {default as ns} from './SQLTester.mjs'; +globalThis.sqlite3 = ns.sqlite3; const log = function f(...args){ console.log('SQLTester.run:',...args); return f; }; -console.log("Loaded",ns); const out = function f(...args){ return f.outer.out(...args) }; out.outer = new ns.Outer(); out.outer.getOutputPrefix = ()=>'SQLTester.run: '; const outln = (...args)=>{ return out.outer.outln(...args) }; +const affirm = function(expr, msg){ + if( !expr ){ + throw new Error(arguments[1] + ? ("Assertion failed: "+arguments[1]) + : "Assertion failed"); + } +} + +console.log("Loaded",ns); + log("ns =",ns); out("Hi there. ").outln("SQLTester is ostensibly ready."); -let ts = new ns.TestScript('/foo.test', ns.Util.utf8Encode(` -# comment line -select 1; ---testcase 0.0 -#--result 1 +let ts = new ns.TestScript('/foo.test', ns.Util.utf8Encode( +`# comment line +--print Starting up... +--null NIL +--new :memory: +--testcase 0.0.1 +select '0.0.1'; +#--result 0.0.1 +--print done `)); const sqt = new ns.SQLTester(); -sqt.verbosity(3); -ts.run(sqt); +try{ + log( 'sqt.getCurrentDb()', sqt.getCurrentDb() ); + sqt.openDb('/foo.db', true); + log( 'sqt.getCurrentDb()', sqt.getCurrentDb() ); + sqt.verbosity(0); + affirm( 'NIL' !== sqt.nullValue() ); + ts.run(sqt); + affirm( 'NIL' === sqt.nullValue() ); +}finally{ + sqt.reset(); +} +log( 'sqt.getCurrentDb()', sqt.getCurrentDb() ); + -- cgit v1.2.3 From aa150477961c57bc0c873faf95f0bc600fc73af6 Mon Sep 17 00:00:00 2001 From: stephan Date: Tue, 29 Aug 2023 20:01:01 +0000 Subject: JS SQLTestRunner can now run the Java impl's core-most sanity tests, missing only support for directives. FossilOrigin-Name: 5e798369375ce1b0c9cdf831f835d931fbd562ff7b4db09a06d1bdca2ac1b975 --- ext/wasm/SQLTester/SQLTester.run.mjs | 53 +++++++++++++++++++++++++++++------- 1 file changed, 43 insertions(+), 10 deletions(-) (limited to 'ext/wasm/SQLTester/SQLTester.run.mjs') diff --git a/ext/wasm/SQLTester/SQLTester.run.mjs b/ext/wasm/SQLTester/SQLTester.run.mjs index dc8eaa0c1..36d1ab5dc 100644 --- a/ext/wasm/SQLTester/SQLTester.run.mjs +++ b/ext/wasm/SQLTester/SQLTester.run.mjs @@ -25,14 +25,46 @@ log("ns =",ns); out("Hi there. ").outln("SQLTester is ostensibly ready."); let ts = new ns.TestScript('/foo.test', ns.Util.utf8Encode( -`# comment line ---print Starting up... ---null NIL ---new :memory: ---testcase 0.0.1 -select '0.0.1'; -#--result 0.0.1 ---print done +` +--close all +--oom +--db 0 +--new my.db +--null zilch +--testcase 1.0 +SELECT 1, null; +--result 1 zilch +--glob *zil* +--notglob *ZIL* +SELECT 1, 2; +intentional error; +--run +--testcase json-1 +SELECT json_array(1,2,3) +--json [1,2,3] +--testcase tableresult-1 + select 1, 'a'; + select 2, 'b'; +--tableresult + # [a-z] + 2 b +--end +--testcase json-block-1 + select json_array(1,2,3); + select json_object('a',1,'b',2); +--json-block + [1,2,3] + {"a":1,"b":2} +--end +--testcase col-names-on +--column-names 1 + select 1 as 'a', 2 as 'b'; +--result a 1 b 2 +--testcase col-names-off +--column-names 0 + select 1 as 'a', 2 as 'b'; +--result 1 2 +--close `)); const sqt = new ns.SQLTester(); @@ -41,11 +73,12 @@ try{ sqt.openDb('/foo.db', true); log( 'sqt.getCurrentDb()', sqt.getCurrentDb() ); sqt.verbosity(0); - affirm( 'NIL' !== sqt.nullValue() ); + affirm( 'zilch' !== sqt.nullValue() ); ts.run(sqt); - affirm( 'NIL' === sqt.nullValue() ); + affirm( 'zilch' === sqt.nullValue() ); }finally{ sqt.reset(); } log( 'sqt.getCurrentDb()', sqt.getCurrentDb() ); +log( "Metrics:", sqt.metrics ); -- cgit v1.2.3 From 267c44771fec6758c371eb41d0ab99a9ea0c8452 Mon Sep 17 00:00:00 2001 From: stephan Date: Tue, 29 Aug 2023 20:44:40 +0000 Subject: More fleshing out of JS SQLTester. FossilOrigin-Name: 8c503dfb9fa15389613a819fcc1792e23d3c05f99a9f450f82eac5125298726f --- ext/wasm/SQLTester/SQLTester.run.mjs | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) (limited to 'ext/wasm/SQLTester/SQLTester.run.mjs') diff --git a/ext/wasm/SQLTester/SQLTester.run.mjs b/ext/wasm/SQLTester/SQLTester.run.mjs index 36d1ab5dc..5136d58a2 100644 --- a/ext/wasm/SQLTester/SQLTester.run.mjs +++ b/ext/wasm/SQLTester/SQLTester.run.mjs @@ -22,10 +22,10 @@ const affirm = function(expr, msg){ console.log("Loaded",ns); log("ns =",ns); -out("Hi there. ").outln("SQLTester is ostensibly ready."); +outln("SQLTester is ready."); -let ts = new ns.TestScript('/foo.test', ns.Util.utf8Encode( -` +let ts = new ns.TestScript('/foo.test',` +--print Hello, world. --close all --oom --db 0 @@ -65,17 +65,22 @@ SELECT json_array(1,2,3) select 1 as 'a', 2 as 'b'; --result 1 2 --close -`)); +--print Until next time +`); const sqt = new ns.SQLTester(); try{ - log( 'sqt.getCurrentDb()', sqt.getCurrentDb() ); + affirm( !sqt.getCurrentDb(), 'sqt.getCurrentDb()' ); sqt.openDb('/foo.db', true); - log( 'sqt.getCurrentDb()', sqt.getCurrentDb() ); + affirm( !!sqt.getCurrentDb(),'sqt.getCurrentDb()' ); sqt.verbosity(0); - affirm( 'zilch' !== sqt.nullValue() ); - ts.run(sqt); - affirm( 'zilch' === sqt.nullValue() ); + if(false){ + affirm( 'zilch' !== sqt.nullValue() ); + ts.run(sqt); + affirm( 'zilch' === sqt.nullValue() ); + } + sqt.addTestScript(ts); + sqt.runTests(); }finally{ sqt.reset(); } -- cgit v1.2.3 From 4f1387e9ab1b5aed8c1c901be23eb02af47854d6 Mon Sep 17 00:00:00 2001 From: stephan Date: Tue, 29 Aug 2023 21:30:37 +0000 Subject: Add directives support to JS SQLTester comparable to the Java impl. This brings the two to feature parity. FossilOrigin-Name: 7cef4a8300826adbdcb3b205e134a4272b12b4aa7dbee97731ac12282a4a9f06 --- ext/wasm/SQLTester/SQLTester.run.mjs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'ext/wasm/SQLTester/SQLTester.run.mjs') diff --git a/ext/wasm/SQLTester/SQLTester.run.mjs b/ext/wasm/SQLTester/SQLTester.run.mjs index 5136d58a2..e58db9345 100644 --- a/ext/wasm/SQLTester/SQLTester.run.mjs +++ b/ext/wasm/SQLTester/SQLTester.run.mjs @@ -25,6 +25,21 @@ log("ns =",ns); outln("SQLTester is ready."); let ts = new ns.TestScript('/foo.test',` +/* +** This is a comment. There are many like it but this one is mine. +** +** SCRIPT_MODULE_NAME: sanity-check +** xMIXED_MODULE_NAME: mixed-module +** xMODULE_NAME: module-name +** xREQUIRED_PROPERTIES: small fast reliable +** xREQUIRED_PROPERTIES: RECURSIVE_TRIGGERS +** xREQUIRED_PROPERTIES: TEMPSTORE_MEM TEMPSTORE_FILE +** +*/ +/* --verbosity 3 */ +/* ---must-fail */ +/* # must fail */ +/* --verbosity 0 */ --print Hello, world. --close all --oom -- cgit v1.2.3 From ac5e1f82ce5e4103bf31882252587f3cbb2a564b Mon Sep 17 00:00:00 2001 From: stephan Date: Wed, 30 Aug 2023 00:22:54 +0000 Subject: Add a mechanism with which to import external SQLTester scripts into the JS testing tool. FossilOrigin-Name: bb08ba020ce1d86ca6aa92f43d5ae915f67d08fa73120e1f603d150e76166624 --- ext/wasm/SQLTester/SQLTester.run.mjs | 58 +++++++++++++++++++++++------------- 1 file changed, 38 insertions(+), 20 deletions(-) (limited to 'ext/wasm/SQLTester/SQLTester.run.mjs') diff --git a/ext/wasm/SQLTester/SQLTester.run.mjs b/ext/wasm/SQLTester/SQLTester.run.mjs index e58db9345..e6730253b 100644 --- a/ext/wasm/SQLTester/SQLTester.run.mjs +++ b/ext/wasm/SQLTester/SQLTester.run.mjs @@ -1,4 +1,18 @@ +/* +** 2023-08-29 +** +** The author disclaims copyright to this source code. In place of +** a legal notice, here is a blessing: +** +** May you do good and not evil. +** May you find forgiveness for yourself and forgive others. +** May you share freely, never taking more than you give. +** +************************************************************************* +** This file contains a test application for SQLTester.js. +*/ import {default as ns} from './SQLTester.mjs'; +import {default as tests} from './test-list.mjs'; globalThis.sqlite3 = ns.sqlite3; const log = function f(...args){ @@ -19,16 +33,13 @@ const affirm = function(expr, msg){ } } -console.log("Loaded",ns); - -log("ns =",ns); -outln("SQLTester is ready."); +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. ** -** SCRIPT_MODULE_NAME: sanity-check +** SCRIPT_MODULE_NAME: sanity-check-0 ** xMIXED_MODULE_NAME: mixed-module ** xMODULE_NAME: module-name ** xREQUIRED_PROPERTIES: small fast reliable @@ -45,10 +56,10 @@ let ts = new ns.TestScript('/foo.test',` --oom --db 0 --new my.db ---null zilch +--null zilchy --testcase 1.0 SELECT 1, null; ---result 1 zilch +--result 1 zilchy --glob *zil* --notglob *ZIL* SELECT 1, 2; @@ -85,20 +96,27 @@ SELECT json_array(1,2,3) const sqt = new ns.SQLTester(); try{ - affirm( !sqt.getCurrentDb(), 'sqt.getCurrentDb()' ); - sqt.openDb('/foo.db', true); - affirm( !!sqt.getCurrentDb(),'sqt.getCurrentDb()' ); - sqt.verbosity(0); - if(false){ - affirm( 'zilch' !== sqt.nullValue() ); - ts.run(sqt); - affirm( 'zilch' === sqt.nullValue() ); + if( 0 ){ + affirm( !sqt.getCurrentDb(), 'sqt.getCurrentDb()' ); + sqt.openDb('/foo.db', true); + affirm( !!sqt.getCurrentDb(),'sqt.getCurrentDb()' ); + sqt.verbosity(0); + if(false){ + affirm( 'zilch' !== sqt.nullValue() ); + ts.run(sqt); + affirm( 'zilch' === sqt.nullValue() ); + } + 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(); } - sqt.addTestScript(ts); - sqt.runTests(); }finally{ + log( "Metrics:", sqt.metrics ); sqt.reset(); } -log( 'sqt.getCurrentDb()', sqt.getCurrentDb() ); -log( "Metrics:", sqt.metrics ); - -- cgit v1.2.3 From e621556724c044aa09e7c4fdab4e8407df83d216 Mon Sep 17 00:00:00 2001 From: stephan Date: Wed, 30 Aug 2023 11:54:43 +0000 Subject: Add a UI, of sorts, to the JS SQLTester. FossilOrigin-Name: 249e82b9917ea47c56ee1cbd3345a977d335fd3fc0d67a1ef157813ef4571c7c --- ext/wasm/SQLTester/SQLTester.run.mjs | 73 ++++++++++++++++++++++++------------ 1 file changed, 48 insertions(+), 25 deletions(-) (limited to 'ext/wasm/SQLTester/SQLTester.run.mjs') 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(); } -- cgit v1.2.3