< prev index next >

test/langtools/jdk/jshell/StartOptionTest.java

Print this page
rev 52725 : [mq]: 8214491-updates

@@ -42,10 +42,12 @@
 import java.util.Locale;
 import java.util.function.Consumer;
 
 import java.util.logging.Level;
 import java.util.logging.Logger;
+import java.util.regex.Pattern;
+
 import org.testng.annotations.AfterMethod;
 import org.testng.annotations.BeforeMethod;
 import org.testng.annotations.Test;
 import jdk.jshell.tool.JavaShellToolBuilder;
 import static org.testng.Assert.assertEquals;

@@ -88,10 +90,12 @@
 
     protected void check(ByteArrayOutputStream str, Consumer<String> checkOut, String label) {
         byte[] bytes = str.toByteArray();
         str.reset();
         String out = new String(bytes, StandardCharsets.UTF_8);
+        out = stripAnsi(out);
+        out = out.replaceAll("[\r\n]+", "\n");
         if (checkOut != null) {
             checkOut.accept(out);
         } else {
             assertEquals(out, "", label + ": Expected empty -- ");
         }

@@ -361,6 +365,13 @@
         console = null;
         userout = null;
         usererr = null;
         cmdInStream = null;
     }
+
+    private static String stripAnsi(String str) {
+        if (str == null) return "";
+        return ANSI_CODE_PATTERN.matcher(str).replaceAll("");
+    }
+
+    public static final Pattern ANSI_CODE_PATTERN = Pattern.compile("\033\\[[\060-\077]*[\040-\057]*[\100-\176]");
 }
< prev index next >