]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
SQLTester can now split a test script into a series of individual commands.
authorstephan <stephan@noemail.net>
Mon, 7 Aug 2023 22:32:22 +0000 (22:32 +0000)
committerstephan <stephan@noemail.net>
Mon, 7 Aug 2023 22:32:22 +0000 (22:32 +0000)
FossilOrigin-Name: d3d1accc8b4ba0cd396ee3a58d9710a54b8e1d1b171d67595d4ef1fc7faea8cb

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

index ab2366bd7f686308dea8b77e4489454ecedf68b8..a415b917a9dc340ab5e65f7f43033a7cd704b44c 100644 (file)
@@ -21,12 +21,15 @@ public class TestScript {
     return java.nio.file.Files.readAllBytes(java.nio.file.Paths.get(filename));
   }
 
+  private void setContent(String c){
+    content = c;
+  }
   /**
      Initializes the script with the content of the given file.
   */
   public TestScript(String filename) throws IOException{
-    this.content = new String(readFile(filename),
-                              java.nio.charset.StandardCharsets.UTF_8);
+    setContent(new String(readFile(filename),
+                          java.nio.charset.StandardCharsets.UTF_8));
   }
 
   /**
@@ -34,16 +37,16 @@ public class TestScript {
      at construction-time.
   */
   public TestScript(StringBuffer content){
-    this.content = content.toString();
+    setContent(content.toString());
   }
 
   public void setVerbose(boolean b){
-    this.outer.setVerbose(b);
+    outer.setVerbose(b);
   }
 
   @SuppressWarnings("unchecked")
   private <T> TestScript verbose(T... vals){
-    this.outer.verbose(vals);
+    outer.verbose(vals);
     return this;
   }
 
@@ -53,43 +56,53 @@ public class TestScript {
      C-style comments from expected script output, which might or might not
      be a real problem.
    */
-  private String chunkContent(){
+  private List<String> chunkContent(String input){
     final String sCComment =
       "[/][*]([*](?![/])|[^*])*[*][/]"
       //"/\\*[^/*]*(?:(?!/\\*|\\*/)[/*][^/*]*)*\\*/"
       ;
-    final String s3Dash = "^---[^\\n]*\\n";
+    final String s3Dash = "^---+[^\\n]*\\n";
     final String sTclComment = "^#[^\\n]*\\n";
     final String sEmptyLine = "^\\n";
-    final String sCommand = "^--.*$";
     final List<String> lPats = new ArrayList<>();
     lPats.add(sCComment);
     lPats.add(s3Dash);
     lPats.add(sTclComment);
     lPats.add(sEmptyLine);
-    //lPats.add(sCommand);
-    verbose("Content:").verbose(content).verbose("<EOF>");
-    String tmp = content;
+    //verbose("Content:").verbose(input).verbose("<EOF>");
+    String tmp = input;
     for( String s : lPats ){
       final Pattern p = Pattern.compile(
         s, Pattern.MULTILINE
       );
       final Matcher m = p.matcher(tmp);
-      verbose("Pattern {{{",p.pattern(),"}}} with flags",
+      /*verbose("Pattern {{{",p.pattern(),"}}} with flags",
               ""+p.flags(),"matches:"
-      );
+              );*/
       int n = 0;
-      while(m.find()){
-        verbose("#"+(++n)+"\t",m.group(0).trim());
-      }
+      //while( m.find() ) verbose("#"+(++n)+"\t",m.group(0).trim());
       tmp = m.replaceAll("");
     }
-    //final Pattern patCComments = new Pattern();
-    //tmp = content.replace(sCComment,"");
-    //tmp = tmp.replace(s3Dash,"");
-    //tmp = tmp.replace(sTclComment,"");
-    //tmp = tmp.replace(sEmptyLine,"");
-    return tmp;
+    // Chunk the newly-stripped text into individual commands.
+    final String sCommand = "^--";
+    final List<String> rc = new ArrayList<>();
+    final Pattern p = Pattern.compile(
+      sCommand, Pattern.MULTILINE
+    );
+    final Matcher m = p.matcher(tmp);
+    int ndxPrev = 0, pos = 0;
+    String chunk;
+    while( m.find() ){
+      pos = m.start();
+      chunk = tmp.substring(ndxPrev, pos).trim();
+      if( !chunk.isEmpty() ) rc.add( chunk );
+      ndxPrev = pos + 2;
+    }
+    if( ndxPrev != pos + 2 ){
+      chunk = tmp.substring(ndxPrev, tmp.length()).trim();
+      if( !chunk.isEmpty() ) rc.add( chunk );
+    }
+    return rc;
   }
 
   /**
@@ -97,7 +110,12 @@ public class TestScript {
      in some form or other (possibly mangled from its original).
   */
   public void dump(){
-    String s = this.chunkContent();
-    this.verbose("chunked script:").verbose(s).verbose("<EOF>");
+    List<String> list = chunkContent(content);
+    verbose("script chunked by command:");
+    int n = 0;
+    for(String c : list){
+      verbose("#"+(++n),c);
+    }
+    verbose("<EOF>");
   }
 }
index 9b5c75c01f9443b0036f772a2fcf0c84ec0a069e..0037ef3ec331e2d6d43b2dfd72db9e7bc6d0f696 100644 (file)
@@ -4,6 +4,9 @@
 
 --null NULL
 --- also ignored
+--testcase first
+input for the first
+command;
 --testcase second
 select 1
 --result /* ignored */
index d287075a5c2b0c6b472c311e73854c04555d759a..3758d4f51e119695f9a8c187824471b43b7effcf 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C SQLTester\scan\snow\sread\sa\sscript\sand\sstrip\sit\sof\sall\snoise\scontent.
-D 2023-08-07T22:02:43.384
+C SQLTester\scan\snow\ssplit\sa\stest\sscript\sinto\sa\sseries\sof\sindividual\scommands.
+D 2023-08-07T22:32:22.258
 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1
 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea
 F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724
@@ -266,9 +266,9 @@ F ext/jni/src/org/sqlite/jni/sqlite3_stmt.java 78e6d1b95ac600a9475e9db4623f69449
 F ext/jni/src/org/sqlite/jni/sqlite3_value.java 3d1d4903e267bc0bc81d57d21f5e85978eff389a1a6ed46726dbe75f85e6914a
 F ext/jni/src/org/sqlite/jni/tester/Outer.java 8931ff9f152d22a822ff98831a4e924da48016ff1f1f84042390a6f51ad7b48f
 F ext/jni/src/org/sqlite/jni/tester/SQLTester.java edcab1ea3d7848523416b881061f8095e8f7ae2a626e07947a55a4215898e040
-F ext/jni/src/org/sqlite/jni/tester/TestScript.java 470e5c08d8badfa3194d06960fe830eb54fd78d2e086bb1f270af499ffea5f25
+F ext/jni/src/org/sqlite/jni/tester/TestScript.java 00007d167ce5b40506a624bad1fb8571a0b975285849a7bd8fd7c0ebcfb3f785
 F ext/jni/src/org/sqlite/jni/tester/test-script-interpreter.md ba3cf6584783939c8797a67203e63ec588430fdc0b7719f24873e6731c6d0445
-F ext/jni/src/tests/000_first.test 9a6622455cc4be00d332be655e0d2d5cf07a2d2b041f8d1950f66bda4873deed
+F ext/jni/src/tests/000_first.test a06b72b6815246a21f6a4b14126bbc40b9cd1e3b03410431ed50203cfa942e9b
 F ext/lsm1/Makefile a553b728bba6c11201b795188c5708915cc4290f02b7df6ba7e8c4c943fd5cd9
 F ext/lsm1/Makefile.msc f8c878b467232226de288da320e1ac71c131f5ec91e08b21f502303347260013
 F ext/lsm1/lsm-test/README 87ea529d2abe615e856d4714bfe8bb185e6c2771b8612aa6298588b7b43e6f86
@@ -2088,8 +2088,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 2aa8f0edecd3fc30eec28987cdbf1003ace154ddc1447b6f8715ecf38d3b06fb
-R f4841d676ff176af3cb93558f987461f
+P 59bd392817ac69ffdf60ab7a2094b0d616bf593da060b6acf1b4ce9837847fcb
+R 63407ef8cfa2823943afd16b1a637995
 U stephan
-Z c343b0e8d67b2614399479523c827e4a
+Z 2b2535b40ad95e4630d07d7436d967c8
 # Remove this line to create a well-formed Fossil manifest.
index cd524757ae82e93fe92607f381e574c6514086af..08b4c777f71537b07e3266b95ac5817c3a828edc 100644 (file)
@@ -1 +1 @@
-59bd392817ac69ffdf60ab7a2094b0d616bf593da060b6acf1b4ce9837847fcb
\ No newline at end of file
+d3d1accc8b4ba0cd396ee3a58d9710a54b8e1d1b171d67595d4ef1fc7faea8cb
\ No newline at end of file