8188894: jdk/jshell/ToolShiftTabTest.java failed with IllegalStateException
authorrfield
Wed, 13 Dec 2017 14:21:12 -0800
changeset 48347 4f9683bf0923
parent 48346 1f38b6c89f8a
child 48348 ef097d7d5b15
8188894: jdk/jshell/ToolShiftTabTest.java failed with IllegalStateException Reviewed-by: jlahoda
test/langtools/jdk/jshell/ToolShiftTabTest.java
test/langtools/jdk/jshell/UITesting.java
--- a/test/langtools/jdk/jshell/ToolShiftTabTest.java	Wed Dec 13 10:56:50 2017 -0800
+++ b/test/langtools/jdk/jshell/ToolShiftTabTest.java	Wed Dec 13 14:21:12 2017 -0800
@@ -23,7 +23,7 @@
 
 /**
  * @test
- * @bug 8166334
+ * @bug 8166334 8188894
  * @summary test shift-tab shortcuts "fixes"
  * @modules
  *     jdk.jshell/jdk.internal.jshell.tool.resources:open
@@ -107,11 +107,12 @@
 
     public void testFixImport() throws Exception {
         doRunTest((inputSink, out) -> {
-            inputSink.write("Frame");
-            inputSink.write(FIX + "i");
-            inputSink.write("1");
-            inputSink.write(".WIDTH\n");
-            waitOutput(out, "==> 1");
+            do {
+                inputSink.write("Frame");
+                inputSink.write(FIX + "i");
+                inputSink.write("1");
+                inputSink.write(".WIDTH\n");
+            } while (!waitOutput(out, "==> 1", "Results may be incomplete"));
             inputSink.write("/import\n");
             waitOutput(out, "|    import java.awt.Frame");
 
--- a/test/langtools/jdk/jshell/UITesting.java	Wed Dec 13 10:56:50 2017 -0800
+++ b/test/langtools/jdk/jshell/UITesting.java	Wed Dec 13 14:21:12 2017 -0800
@@ -135,8 +135,19 @@
     }
 
     protected void waitOutput(StringBuilder out, String expected) {
+        waitOutput(out, expected, null);
+    }
+
+    // Return true if expected is found, false if secondary is found,
+    // otherwise, time out with an IllegalStateException
+    protected boolean waitOutput(StringBuilder out, String expected, String secondary) {
         expected = expected.replaceAll("\n", laxLineEndings ? "\r?\n" : System.getProperty("line.separator"));
         Pattern expectedPattern = Pattern.compile(expected, Pattern.DOTALL);
+        Pattern secondaryPattern = null;
+        if (secondary != null) {
+            secondary = secondary.replaceAll("\n", laxLineEndings ? "\r?\n" : System.getProperty("line.separator"));
+            secondaryPattern = Pattern.compile(secondary, Pattern.DOTALL);
+        }
         synchronized (out) {
             long s = System.currentTimeMillis();
 
@@ -144,7 +155,14 @@
                 Matcher m = expectedPattern.matcher(out);
                 if (m.find()) {
                     out.delete(0, m.end());
-                    return ;
+                    return true;
+                }
+                if (secondaryPattern != null) {
+                    m = secondaryPattern.matcher(out);
+                    if (m.find()) {
+                        out.delete(0, m.end());
+                        return false;
+                    }
                 }
                 long e =  System.currentTimeMillis();
                 if ((e - s) > TIMEOUT) {