]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
When SQLTester hits an unknown command, emit a warning and skip the rest of that...
authorstephan <stephan@noemail.net>
Tue, 8 Aug 2023 19:20:12 +0000 (19:20 +0000)
committerstephan <stephan@noemail.net>
Tue, 8 Aug 2023 19:20:12 +0000 (19:20 +0000)
FossilOrigin-Name: 3e78d22d04e6ac2606bfc5ce250a4c3b39a2062e14011ca0a8a0a85491efbfde

ext/jni/src/org/sqlite/jni/tester/SQLTester.java
ext/jni/src/tests/000_first.test
manifest
manifest.uuid

index 9273faae478726bbab22ec2c4bf6bf38489bde8f..59fb499be75d0ed44f4411e4fba0845ed7ed83ab 100644 (file)
@@ -25,6 +25,15 @@ class TestFailure extends RuntimeException {
     super(msg);
   }
 }
+
+class SkipTestRemainder extends RuntimeException {
+  public TestScript testScript;
+  public SkipTestRemainder(TestScript ts){
+    super("Skipping remainder of "+ts.getName());
+    testScript = ts;
+  }
+}
+
 /**
    This class provides an application which aims to implement the
    rudimentary SQL-driven test tool described in the accompanying
@@ -44,10 +53,12 @@ public class SQLTester {
   private String nullView;
   private int nTotalTest = 0;
   private int nTestFile = 0;
+  private int nAbortedScript = 0;
   private int nTest;
   private final sqlite3[] aDb = new sqlite3[7];
   private int iCurrentDb = 0;
   private final String initialDbName = "test.db";
+  private TestScript currentScript;
 
   public SQLTester(){
     reset();
@@ -86,17 +97,30 @@ public class SQLTester {
     openDb(0, initialDbName, true);
   }
 
+  TestScript getCurrentScript(){
+    return currentScript;
+  }
+
   public void runTests() throws Exception {
     // process each input file
-    outln("Verbose = ",outer.isVerbose());
-    for(String f : listInFiles){
-      reset();
-      setupInitialDb();
-      ++nTestFile;
-      final TestScript ts = new TestScript(f);
-      outln("---------> Test ",ts.getName()," ...");
-      ts.run(this);
-      outln("<--------- ",nTest," test(s) in ",f);
+    try {
+      for(String f : listInFiles){
+        reset();
+        setupInitialDb();
+        ++nTestFile;
+        final TestScript ts = new TestScript(f);
+        currentScript = ts;
+        outln("---------> Test ",ts.getName()," ...");
+        try{
+          ts.run(this);
+        }catch(SkipTestRemainder e){
+          /* not an error */
+          ++nAbortedScript;
+        }
+        outln("<--------- ",nTest," test(s) in ",f);
+      }
+    }finally{
+      currentScript = null;
     }
     Util.unlink(initialDbName);
   }
@@ -197,6 +221,16 @@ public class SQLTester {
 
   void setNullValue(String v){nullView = v;}
 
+  /**
+     If true, encountering an unknown command in a script causes the
+     remainder of the script to be skipped, rather than aborting the
+     whole script run.
+  */
+  boolean skipUnknownCommands(){
+    // Currently hard-coded. Potentially a flag someday.
+    return true;
+  }
+
   void incrementTestCounter(){ ++nTest; ++nTotalTest; }
 
   String escapeSqlValue(String v){
@@ -290,6 +324,7 @@ public class SQLTester {
         final String flag = a.replaceFirst("-+","");
         if( flag.equals("verbose") ){
           t.setVerbose(true);
+          t.outln("Verbose mode is on.");
         }else if( flag.equals("quiet") ) {
           t.setVerbose(false);
         }else{
@@ -300,7 +335,10 @@ public class SQLTester {
       t.addTestScript(a);
     }
     t.runTests();
-    t.outer.outln("Processed ",t.nTotalTest," test(s) in ",t.nTestFile," file(s).");
+    t.outln("Processed ",t.nTotalTest," test(s) in ",t.nTestFile," file(s).");
+    if( t.nAbortedScript > 0 ){
+      t.outln("Aborted ",t.nAbortedScript," script(s).");
+    }
   }
 }
 
@@ -366,7 +404,7 @@ class CloseDbCommand extends Command {
     if(argv.length>1){
       String arg = argv[1];
       if("all".equals(arg)){
-        t.verbose(argv[0]," all dbs");
+        //t.verbose(argv[0]," all dbs");
         t.closeAllDbs();
         return;
       }
@@ -377,7 +415,7 @@ class CloseDbCommand extends Command {
       id = t.getCurrentDbId();
     }
     t.closeDb(id);
-    t.verbose(argv[0]," db ",id);
+    //t.verbose(argv[0]," db ",id);
   }
 }
 
@@ -386,7 +424,7 @@ class DbCommand extends Command {
     argcCheck(argv,1);
     affirmNoContent(content);
     final sqlite3 db = t.setCurrentDb( Integer.parseInt(argv[1]) );
-    t.verbose(argv[0]," set db to ",db);
+    //t.verbose(argv[0]," set db to ",db);
   }
 }
 
@@ -410,7 +448,7 @@ class NewDbCommand extends Command {
     String fname = argv[1];
     Util.unlink(fname);
     final sqlite3 db = t.openDb(fname, true);
-    t.verbose(argv[0]," db ",db);
+    //t.verbose(argv[0]," db ",db);
   }
 }
 
@@ -440,7 +478,7 @@ class OpenDbCommand extends Command {
     affirmNoContent(content);
     String fname = argv[1];
     final sqlite3 db = t.openDb(fname, false);
-    t.verbose(argv[0]," db ",db);
+    //t.verbose(argv[0]," db ",db);
   }
 }
 
@@ -523,8 +561,15 @@ class CommandDispatcher {
   static void dispatch(SQLTester tester, String[] argv, String content) throws Exception{
     final Class cmdClass = getCommandByName(argv[0]);
     if(null == cmdClass){
+      final TestScript ts = tester.getCurrentScript();
+      if( tester.skipUnknownCommands() ){
+        tester.outln("WARNING: skipping remainder of ",ts.getName(),
+                     " because it contains unknown command '",argv[0],"'.");
+        throw new SkipTestRemainder(ts);
+      }
       Util.toss(IllegalArgumentException.class,
-           "No command handler found for '"+argv[0]+"'");
+                "No command handler found for '"+argv[0]+"' in ",
+                ts.getName());
     }
     final java.lang.reflect.Constructor<Command> ctor =
       cmdClass.getConstructor(SQLTester.class, String[].class, String.class);
@@ -532,7 +577,8 @@ class CommandDispatcher {
       //tester.verbose("Running ",argv[0]," with:\n", content);
       ctor.newInstance(tester, argv, content);
     }catch(java.lang.reflect.InvocationTargetException e){
-      throw (Exception)e.getCause();
+      Throwable t = e.getCause();
+      throw (t!=null && t instanceof Exception) ? (Exception)t : e;
     }
   }
 }
index c838582145ed647be9ee94075ed7ccaf424258b4..031964d667f08e4e1dc6e2df5e36ebfd0964fce1 100644 (file)
@@ -14,7 +14,7 @@ junk
 select 1;
 select 2;
 -- comment
-intentional syntax error
+-- uncomment to introduce intentional syntax error
 --oom
 --print
 This is from the print command.
@@ -33,3 +33,4 @@ select 'a'
 --open SQLTester.db
 --print
 Re-opened db.
+--an-uknown-command
index 1986118349e766bd18f2a8140c9226e8dc64c3b3..b7af88ce9c638d56283f038686ec8c581f1d4e6d 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C Correct\sthe\sspacing\soutput\sof\smulti-select\sSQL\sblocks\sfor\sSQLTester\s--result.
-D 2023-08-08T14:58:00.844
+C When\sSQLTester\shits\san\sunknown\scommand,\semit\sa\swarning\sand\sskip\sthe\srest\sof\sthat\sscript\sinstead\sof\saborting\sthe\swhole\srun,\sper\s/chat\sdiscussion.\sReduce\sverbosity\sa\sbit.
+D 2023-08-08T19:20:12.267
 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1
 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea
 F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724
@@ -266,10 +266,10 @@ F ext/jni/src/org/sqlite/jni/sqlite3_context.java d26573fc7b309228cb49786e907859
 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/Outer.java 3d9c40f8ed58ec0df05ca160986ea06ec84ec1f338b069cfba9604bbba467a01
-F ext/jni/src/org/sqlite/jni/tester/SQLTester.java c26e0be30b03b9bf233903b0dd11314a38b8c47c7f9a322d9c383deab0f1799c
+F ext/jni/src/org/sqlite/jni/tester/SQLTester.java 099c256f46dd0fe9ea00e25e2adb2b56cf1ea5765214b1a07b234179f154e6d5
 F ext/jni/src/org/sqlite/jni/tester/TestScript.java 52350fb458d7d2816377a824c18c498c4a97f0026b64278f62ff1c382a92a070
 F ext/jni/src/org/sqlite/jni/tester/test-script-interpreter.md 4a4868c70a68aa1829c1f7659daa78198187199d176778efb86a239c9e58802c
-F ext/jni/src/tests/000_first.test 752aca36279f9b0ceedaf15a4ce6bc9e0b7f9ca2749287e204d81ca2f7e41e6f
+F ext/jni/src/tests/000_first.test 67c095b9ba8d1e57ea5f996126f8a9a76c2fffbe6c0b9d4083e604f7991e54d8
 F ext/jni/src/tests/010_ignored.test ce2de6742ff1bf98d8976fda0f260ff3d280e8f8c0a99309fb59fcfef2556fcd
 F ext/lsm1/Makefile a553b728bba6c11201b795188c5708915cc4290f02b7df6ba7e8c4c943fd5cd9
 F ext/lsm1/Makefile.msc f8c878b467232226de288da320e1ac71c131f5ec91e08b21f502303347260013
@@ -2090,8 +2090,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 d2c99b96f4b61561c3fa34947ca7bfd2cd214b1913aff7ba64b7b897a574fea3
-R 93a03db65e40af7c6fe9793f15a6ca43
+P 8d98645a9e524b30f7faa1cffd8f09e7aab3c25ac7b08dd6884141dfe9cdb0d3
+R a618fd6ff82f81612f61c1de1f6b473b
 U stephan
-Z dca17c3e57d683e1e595814410eca997
+Z c4565e5d104af1325b5207d0f09e8da7
 # Remove this line to create a well-formed Fossil manifest.
index 54be3ff1d2dc554ed38fb894ccacabb0f92fa142..b087dc17ebe6e278d9be74fa7315fadd0a9989b9 100644 (file)
@@ -1 +1 @@
-8d98645a9e524b30f7faa1cffd8f09e7aab3c25ac7b08dd6884141dfe9cdb0d3
\ No newline at end of file
+3e78d22d04e6ac2606bfc5ce250a4c3b39a2062e14011ca0a8a0a85491efbfde
\ No newline at end of file