]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
Add directives support to JS SQLTester comparable to the Java impl. This brings the...
authorstephan <stephan@noemail.net>
Tue, 29 Aug 2023 21:30:37 +0000 (21:30 +0000)
committerstephan <stephan@noemail.net>
Tue, 29 Aug 2023 21:30:37 +0000 (21:30 +0000)
FossilOrigin-Name: 7cef4a8300826adbdcb3b205e134a4272b12b4aa7dbee97731ac12282a4a9f06

ext/wasm/SQLTester/SQLTester.mjs
ext/wasm/SQLTester/SQLTester.run.mjs
manifest
manifest.uuid

index c8ab2fa5cc2e1048597d3d4b4a78c61b0bd6f934..aa02d7a5ec597775f6f66e133b2bc2d60eac5523 100644 (file)
@@ -53,8 +53,13 @@ const ResultRowMode = newObj({
 });
 
 class SQLTesterException extends globalThis.Error {
-  constructor(...args){
-    super(args.join(''));
+  constructor(testScript, ...args){
+    if(testScript){
+      super( [testScript.getOutputPrefix()+": ", ...args].join('') );
+    }else{
+      super( args.join('') );
+    }
+    this.name = 'SQLTesterException';
   }
   isFatal() { return false; }
 }
@@ -64,8 +69,9 @@ SQLTesterException.toss = (...args)=>{
 }
 
 class DbException extends SQLTesterException {
-  constructor(pDb, rc, closeDb){
-    super("DB error #"+rc+": "+sqlite3.capi.sqlite3_errmsg(pDb));
+  constructor(testScript, pDb, rc, closeDb){
+    super(testScript, "DB error #"+rc+": "+sqlite3.capi.sqlite3_errmsg(pDb));
+    this.name = 'DbException';
     if( closeDb ) sqlite3.capi.sqlite3_close_v2(pDb);
   }
   isFatal() { return true; }
@@ -73,28 +79,27 @@ class DbException extends SQLTesterException {
 
 class TestScriptFailed extends SQLTesterException {
   constructor(testScript, ...args){
-    super(testScript.getOutputPrefix(),': ',...args);
+    super(testScript,...args);
+    this.name = 'TestScriptFailed';
   }
   isFatal() { return true; }
 }
 
 class UnknownCommand extends SQLTesterException {
-  constructor(...args){
-    super(...args);
+  constructor(testScript, cmdName){
+    super(testScript, cmdName);
+    this.name = 'UnknownCommand';
   }
 }
 
 class IncompatibleDirective extends SQLTesterException {
-  constructor(...args){
-    super(...args);
+  constructor(testScript, ...args){
+    super(testScript,...args);
+    this.name = 'IncompatibleDirective';
   }
 }
 
 const toss = (errType, ...args)=>{
-  if( !(errType instanceof SQLTesterException)){
-    args.unshift(errType);
-    errType = SQLTesterException;
-  }
   throw new errType(...args);
 };
 
@@ -429,7 +434,7 @@ class SQLTester {
       }catch(e){
         if(e instanceof SQLTesterException){
           threw = true;
-          this.outln("🔥EXCEPTION: ",''+e);
+          this.outln("🔥EXCEPTION: ",e);
           ++this.metrics.nAbortedScript;
           if( this.#keepGoing ){
             this.outln("Continuing anyway becaure of the keep-going option.");
@@ -537,7 +542,7 @@ class SQLTester {
         );
         if( 0!==rc ){
           if(throwOnError){
-            throw new DbException(pDb, rc);
+            throw new DbException(self, pDb, rc);
           }else if( sb ){
             self.#appendDbErr(db, sb, rc);
           }
@@ -699,7 +704,32 @@ class TestScript {
   }
 
   #checkForDirective(tester,line){
-    //todo
+    if(line.startsWith("#")){
+      throw new IncompatibleDirective(this, "C-preprocessor input: "+line);
+    }else if(line.startsWith("---")){
+      throw new IncompatibleDirective(this, "triple-dash: ",line);
+    }
+    let m = Rx.scriptModuleName.exec(line);
+    if( m ){
+      this.#moduleName = m[1];
+      return;
+    }
+    m = Rx.requiredProperties.exec(line);
+    if( m ){
+      const rp = m[1];
+      //if( ! checkRequiredProperties( tester, rp.split("\\s+") ) ){
+      throw new IncompatibleDirective(this, "REQUIRED_PROPERTIES: "+rp);
+      //}
+    }
+
+    m = Rx.mixedModuleName.exec(line);
+    if( m ){
+      throw new IncompatibleDirective(this, m[1]+": "+m[3]);
+    }
+    if( line.indexOf("\n|")>=0 ){
+      throw new IncompatibleDirective(this, "newline-pipe combination.");
+    }
+
   }
 
   #getCommandArgv(line){
@@ -734,7 +764,7 @@ class TestScript {
     this.#outer.verbosity(tester.verbosity());
     let line, directive, argv = [];
     while( null != (line = this.getLine()) ){
-      this.verbose3("input line: ",line);
+      this.verbose3("run() input line: ",line);
       this.#checkForDirective(tester, line);
       argv = this.#getCommandArgv(line);
       if( argv ){
@@ -747,10 +777,10 @@ class TestScript {
   }
 
   #processCommand(tester, argv){
-    this.verbose1("running command: ",argv[0], " ", Util.argvToString(argv));
+    this.verbose2("processCommand(): ",argv[0], " ", Util.argvToString(argv));
     if(this.#outer.verbosity()>1){
       const input = tester.getInputText();
-      if( !!input ) this.verbose3("Input buffer = ",input);
+      this.verbose3("processCommand() input buffer = ",input);
     }
     CommandDispatcher.dispatch(tester, this, argv);
   }
@@ -1084,7 +1114,7 @@ class TestCaseCommand extends Command {
 //! --verbosity command
 class VerbosityCommand extends Command {
   process(t, ts, argv){
-    t.argcCheck(ts,argv,1);
+    this.argcCheck(ts,argv,1);
     ts.verbosity( parseInt(argv[1]) );
   }
 }
@@ -1123,7 +1153,7 @@ class CommandDispatcher {
   static dispatch(tester, testScript, argv){
     const cmd = CommandDispatcher.getCommandByName(argv[0]);
     if( !cmd ){
-      toss(UnknownCommand,argv[0],' ',testScript.getOutputPrefix());
+      toss(UnknownCommand,testScript,argv[0]);
     }
     cmd.process(tester, testScript, argv);
   }
index 5136d58a28666df1741dc0eaf3cae573bb1cd6bf..e58db93450720c279f93988b2ee7eaabf7ef16b1 100644 (file)
@@ -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
index b7930866b8d9b1c8ce772f5217d34bc8bd0e6800..c8e5581fdaa0c91e51863454b02e16ad1d03d1c3 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C More\sfleshing\sout\sof\sJS\sSQLTester.
-D 2023-08-29T20:44:40.606
+C Add\sdirectives\ssupport\sto\sJS\sSQLTester\scomparable\sto\sthe\sJava\simpl.\sThis\sbrings\sthe\stwo\sto\sfeature\sparity.
+D 2023-08-29T21:30:37.122
 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1
 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea
 F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724
@@ -548,8 +548,8 @@ F ext/wasm/EXPORTED_FUNCTIONS.fiddle.in 27450c8b8c70875a260aca55435ec927068b34ce
 F ext/wasm/GNUmakefile 0e362f3fc04eab6628cbe4f1e35f4ab4a200881f6b5f753b27fb45eabeddd9d2
 F ext/wasm/README-dist.txt 6382cb9548076fca472fb3330bbdba3a55c1ea0b180ff9253f084f07ff383576
 F ext/wasm/README.md a8a2962c3aebdf8d2104a9102e336c5554e78fc6072746e5daf9c61514e7d193
-F ext/wasm/SQLTester/SQLTester.mjs ed6bc486d804829883d05a94cbc5ace1b468837fcaf687d87f17969a659100ae
-F ext/wasm/SQLTester/SQLTester.run.mjs e053a4e94b22a97f5981a0ce927b77c542d68a564d723dbaeb7b299d817bb915
+F ext/wasm/SQLTester/SQLTester.mjs 40583ad88bbc32c602e9bfbcd7a90ea6bdfeed41994c1fcc0a7e9d0ffdcd9a5e
+F ext/wasm/SQLTester/SQLTester.run.mjs de03763f8085a130e17706a8c475d7bab37f77eff4f5322b0cc33504733394d7
 F ext/wasm/SQLTester/index.html 88d87e3ccbc33e7ab3773a8e48c1172e876951c4be31d1307c3700671262cddf
 F ext/wasm/api/EXPORTED_FUNCTIONS.sqlite3-api d6a5078f48a5301ed17b9a30331075d9b2506e1360c1f0dee0c7816c10acd9ab
 F ext/wasm/api/EXPORTED_FUNCTIONS.sqlite3-see fb29e62082a658f0d81102488414d422c393c4b20cc2f685b216bc566237957b
@@ -2111,8 +2111,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 5e798369375ce1b0c9cdf831f835d931fbd562ff7b4db09a06d1bdca2ac1b975
-R 3c7d31cab0e76e0f71d5ac9e71d46fd7
+P 8c503dfb9fa15389613a819fcc1792e23d3c05f99a9f450f82eac5125298726f
+R e03f3f1709d7ca32242a0e49e3b98e3f
 U stephan
-Z 3b4eebe6c916b635f59799d0c8f89ba5
+Z ecc2ea98d4d7da8116d2d29b184f2709
 # Remove this line to create a well-formed Fossil manifest.
index 8feab071783b109a0a593129c6f428262b613e58..cb91036e81445fb0328df84c790aad6e4fa46afc 100644 (file)
@@ -1 +1 @@
-8c503dfb9fa15389613a819fcc1792e23d3c05f99a9f450f82eac5125298726f
\ No newline at end of file
+7cef4a8300826adbdcb3b205e134a4272b12b4aa7dbee97731ac12282a4a9f06
\ No newline at end of file