[jruby-joni] 82/194: dedup test logic

Hideki Yamane henrich at moszumanska.debian.org
Thu Feb 1 12:04:29 UTC 2018


This is an automated email from the git hooks/post-receive script.

henrich pushed a commit to branch debian/sid
in repository jruby-joni.

commit ce65eaf9f9491487ec510ec41a2c299dfad22112
Author: Marcin Mielzynski <lopx at gazeta.pl>
Date:   Sun Dec 31 17:46:25 2017 +0100

    dedup test logic
---
 pom.xml                               |   2 +-
 test/org/joni/test/Test.java          | 137 ++++++----------------------------
 test/org/joni/test/TestInterrupt.java |  22 +++---
 3 files changed, 37 insertions(+), 124 deletions(-)

diff --git a/pom.xml b/pom.xml
index 27053a8..eb05e49 100644
--- a/pom.xml
+++ b/pom.xml
@@ -71,7 +71,7 @@
     <dependency>
       <groupId>junit</groupId>
       <artifactId>junit</artifactId>
-      <version>4.10</version>
+      <version>4.12</version>
       <scope>test</scope>
     </dependency>
     <dependency>
diff --git a/test/org/joni/test/Test.java b/test/org/joni/test/Test.java
index 5050d35..26b9532 100644
--- a/test/org/joni/test/Test.java
+++ b/test/org/joni/test/Test.java
@@ -36,9 +36,9 @@ import org.joni.exception.JOniException;
 public abstract class Test {
     static final boolean VERBOSE = false;
     static final WarnCallback TEST_WARNINGS = new WarnCallback() {
-		public void warn(String message) {
-		}
-	};
+        public void warn(String message) {
+        }
+    };
 
     int nsucc;
     int nerror;
@@ -56,7 +56,7 @@ public abstract class Test {
     protected int length(byte[]bytes) {
         return bytes.length;
     }
-    
+
     protected void assertTrue(boolean expression, String... failMessage) {
         if (expression) {
             nsucc++;
@@ -66,11 +66,11 @@ public abstract class Test {
         }
     }
 
-    public void xx(byte[]pattern, byte[]str, int from, int to, int mem, boolean not) {
+    public void xx(byte[]pattern, byte[]str, int from, int to, int mem, boolean not) throws InterruptedException {
         xx(pattern, str, from, to, mem, not, option());
     }
-    
-    public int xx(byte[]pattern, byte[]str, int from, int to, int mem, boolean not, int option) {
+
+    public int xx(byte[]pattern, byte[]str, int from, int to, int mem, boolean not, int option) throws InterruptedException {
         Regex reg;
 
         try {
@@ -94,73 +94,6 @@ public abstract class Test {
 
         int r = 0;
         try {
-            r = m.search(0, length(str), Option.NONE);
-            region = m.getEagerRegion();
-        } catch (JOniException je) {
-            Config.err.println("Pattern: " + repr(pattern) + " Str: " + repr(str));
-            je.printStackTrace(Config.err);
-            Config.err.println("ERROR: " + je.getMessage());
-            nerror++;
-            return Matcher.FAILED;
-        } catch (Exception e) {
-            Config.err.println("Pattern: " + repr(pattern) + " Str: " + repr(str));
-            e.printStackTrace(Config.err);
-            Config.err.println("SEVERE ERROR: " + e.getMessage());
-            nerror++;
-            return Matcher.FAILED;
-        }
-
-        if (r == -1) {
-            if (not) {
-                if (VERBOSE) Config.log.println("OK(N): /" + repr(pattern) + "/ '" + repr(str) + "'");
-                nsucc++;
-            } else {
-                Config.log.println("FAIL: /" + repr(pattern) + "/ '" + repr(str) + "'");
-                nfail++;
-            }
-        } else {
-            if (not) {
-                Config.log.println("FAIL(N): /" + repr(pattern) + "/ '" + repr(str) + "'");
-                nfail++;
-            } else {
-                if (region.beg[mem] == from && region.end[mem] == to) {
-                    if (VERBOSE)  Config.log.println("OK: /" + repr(pattern) + "/ '" +repr(str) + "'");
-                    nsucc++;
-                } else {
-                    Config.log.println("FAIL: /" + repr(pattern) + "/ '" + repr(str) + "' " +
-                            from + "-" + to + " : " + region.beg[mem] + "-" + region.end[mem]
-                            );
-                    nfail++;
-                }
-            }
-        }
-        return r;
-    }
-    
-    public void xxi(byte[]pattern, byte[]str, int from, int to, int mem, boolean not, int option) throws InterruptedException {
-        Regex reg;
-
-        try {
-            reg = new Regex(pattern, 0, length(pattern), option, encoding(), syntax(), TEST_WARNINGS);
-        } catch (JOniException je) {
-            Config.err.println("Pattern: " + repr(pattern) + " Str: " + repr(str));
-            je.printStackTrace(Config.err);
-            Config.err.println("ERROR: " + je.getMessage());
-            nerror++;
-            return;
-        } catch (Exception e) {
-            Config.err.println("Pattern: " + repr(pattern) + " Str: " + repr(str));
-            e.printStackTrace(Config.err);
-            Config.err.println("SEVERE ERROR: " + e.getMessage());
-            nerror++;
-            return;
-        }
-
-        Matcher m = reg.matcher(str, 0, length(str));
-        Region region;
-
-        int r = 0;
-        try {
             r = m.searchInterruptible(0, length(str), Option.NONE);
             region = m.getEagerRegion();
         } catch (JOniException je) {
@@ -168,7 +101,7 @@ public abstract class Test {
             je.printStackTrace(Config.err);
             Config.err.println("ERROR: " + je.getMessage());
             nerror++;
-            return;
+            return Matcher.FAILED;
         } catch (InterruptedException e) {
             throw e;
         } catch (Exception e) {
@@ -176,7 +109,7 @@ public abstract class Test {
             e.printStackTrace(Config.err);
             Config.err.println("SEVERE ERROR: " + e.getMessage());
             nerror++;
-            return;
+            return Matcher.FAILED;
         }
 
         if (r == -1) {
@@ -203,57 +136,46 @@ public abstract class Test {
                 }
             }
         }
+        return r;
     }
 
-    protected void x2(byte[]pattern, byte[]str, int from, int to) {
+    protected void x2(byte[]pattern, byte[]str, int from, int to) throws InterruptedException {
         xx(pattern, str, from, to, 0, false);
     }
 
-    protected void x2(byte[]pattern, byte[]str, int from, int to, int option) {
+    protected void x2(byte[]pattern, byte[]str, int from, int to, int option) throws InterruptedException {
         xx(pattern, str, from, to, 0, false, option);
     }
 
-    protected void x3(byte[]pattern, byte[]str, int from, int to, int mem) {
+    protected void x3(byte[]pattern, byte[]str, int from, int to, int mem) throws InterruptedException {
         xx(pattern, str, from, to, mem, false);
     }
 
-    protected void n(byte[]pattern, byte[]str) {
+    protected void n(byte[]pattern, byte[]str) throws InterruptedException {
         xx(pattern, str, 0, 0, 0, true);
     }
 
-    protected void n(byte[]pattern, byte[]str, int option) {
+    protected void n(byte[]pattern, byte[]str, int option) throws InterruptedException {
         xx(pattern, str, 0, 0, 0, true, option);
     }
 
-    public void xxs(String pattern, String str, int from, int to, int mem, boolean not) {
+    public void xxs(String pattern, String str, int from, int to, int mem, boolean not) throws InterruptedException {
         xxs(pattern, str, from, to, mem, not, option());
     }
 
-    public void xxs(String pattern, String str, int from, int to, int mem, boolean not, int option) {
+    public void xxs(String pattern, String str, int from, int to, int mem, boolean not, int option) throws InterruptedException {
         try{
             xx(pattern.getBytes(testEncoding()), str.getBytes(testEncoding()), from, to, mem, not, option);
         } catch (UnsupportedEncodingException uee) {
             uee.printStackTrace();
         }
     }
-    
-    public void xxsi(String pattern, String str, int from, int to, int mem, boolean not) throws InterruptedException {
-        xxsi(pattern, str, from, to, mem, not, option());
-    }
-
-    public void xxsi(String pattern, String str, int from, int to, int mem, boolean not, int option) throws InterruptedException {
-        try{
-            xxi(pattern.getBytes(testEncoding()), str.getBytes(testEncoding()), from, to, mem, not, option);
-        } catch (UnsupportedEncodingException uee) {
-            uee.printStackTrace();
-        }
-    }    
 
-    public int x2s(String pattern, String str, int from, int to) {
+    public int x2s(String pattern, String str, int from, int to) throws InterruptedException {
         return x2s(pattern, str, from, to, option());
     }
 
-    public int x2s(String pattern, String str, int from, int to, int option) {
+    public int x2s(String pattern, String str, int from, int to, int option) throws InterruptedException {
         try{
             return xx(pattern.getBytes(testEncoding()), str.getBytes(testEncoding()), from, to, 0, false, option);
         } catch (UnsupportedEncodingException uee) {
@@ -261,24 +183,11 @@ public abstract class Test {
             return Matcher.FAILED;
         }
     }
-    
-    public void x2si(String pattern, String str, int from, int to) throws InterruptedException {
-        x2si(pattern, str, from, to, option());
-    }
-
-    public void x2si(String pattern, String str, int from, int to, int option) throws InterruptedException {
-        try{
-        xxi(pattern.getBytes(testEncoding()), str.getBytes(testEncoding()), from, to, 0, false, option);
-        } catch (UnsupportedEncodingException uee) {
-            uee.printStackTrace();
-        }
-    }    
-
-    public void x3s(String pattern, String str, int from, int to, int mem) {
+    public void x3s(String pattern, String str, int from, int to, int mem) throws InterruptedException {
         x3s(pattern, str, from, to, mem, option());
     }
 
-    public void x3s(String pattern, String str, int from, int to, int mem, int option) {
+    public void x3s(String pattern, String str, int from, int to, int mem, int option) throws InterruptedException {
         try{
             xx(pattern.getBytes(testEncoding()), str.getBytes(testEncoding()), from, to, mem, false, option);
         } catch (UnsupportedEncodingException uee) {
@@ -286,11 +195,11 @@ public abstract class Test {
         }
     }
 
-    public void ns(String pattern, String str) {
+    public void ns(String pattern, String str) throws InterruptedException {
         ns(pattern, str, option());
     }
 
-    public void ns(String pattern, String str, int option) {
+    public void ns(String pattern, String str, int option) throws InterruptedException {
         try{
             xx(pattern.getBytes(testEncoding()), str.getBytes(testEncoding()), 0, 0, 0, true, option);
         } catch (UnsupportedEncodingException uee) {
diff --git a/test/org/joni/test/TestInterrupt.java b/test/org/joni/test/TestInterrupt.java
index 587aff6..bebf02e 100755
--- a/test/org/joni/test/TestInterrupt.java
+++ b/test/org/joni/test/TestInterrupt.java
@@ -44,28 +44,32 @@ public class TestInterrupt extends Test {
     public void test() throws InterruptedException {
         interruptAfter(new InterruptibleRunnable() {
             public void run() throws InterruptedException {
-                x2si("a?a?a?a?a?a?a?a?a?a?a?a?a?a?a?a?a?a?a?a?a?a?a?a?a?a?a?a?a?aaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
+                x2s("a?a?a?a?a?a?a?a?a?a?a?a?a?a?a?a?a?a?a?a?a?a?a?a?a?a?a?a?a?aaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
                         "aaaaaaaaaaaaaaaaaaaaaaaaaaaaa", 0, 0);
             }
         }, 1000, 15000);
 
         final int status[] = new int[1];
-        
+
         interruptAfter(new InterruptibleRunnable() {
             public void run() throws InterruptedException {
-                status[0] = x2s("a?a?a?a?a?a?a?a?a?a?a?a?a?a?a?a?a?a?a?a?a?a?a?a?a?a?a?a?a?aaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
-                        "aaaaaaaaaaaaaaaaaaaaaaaaaaaaa", 0, 0);
+                try {
+                    x2s("a?a?a?a?a?a?a?a?a?a?a?a?a?a?a?a?a?a?a?a?a?a?a?a?a?a?a?a?a?aaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
+                            "aaaaaaaaaaaaaaaaaaaaaaaaaaaaa", 0, 0);
+                } catch (InterruptedException ie) {
+                    status[0] = Matcher.INTERRUPTED;
+                }
             }
         }, 1000, 15000);
-        
+
         assertTrue(status[0] == Matcher.INTERRUPTED, "Status was not INTERRUPTED: " + status[0]);
     }
-    
+
     private void interruptAfter(InterruptibleRunnable block, int delayBeforeInterrupt, int acceptableMaximumTime) {
         final long start[] = new long[1];
-        
+
         final Thread currentThread = Thread.currentThread();
-        
+
         new Timer().schedule(new TimerTask() {
             @Override public void run() {
                 start[0] = System.currentTimeMillis();
@@ -73,7 +77,7 @@ public class TestInterrupt extends Test {
                 currentThread.interrupt();
             }
         }, delayBeforeInterrupt);
-        
+
         try {
             block.run();
         } catch (InterruptedException e) {

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-java/jruby-joni.git



More information about the pkg-java-commits mailing list