8022773: ScriptEngineTest.printManyTest fails
authorsundar
Tue, 27 Aug 2013 15:54:45 +0530
changeset 19636 ce19ba858512
parent 19635 b1a895c53316
child 19637 fbba16718d6c
8022773: ScriptEngineTest.printManyTest fails Reviewed-by: lagergren, attila
nashorn/test/src/jdk/nashorn/api/scripting/ScriptEngineTest.java
--- a/nashorn/test/src/jdk/nashorn/api/scripting/ScriptEngineTest.java	Mon Aug 26 15:33:40 2013 -0300
+++ b/nashorn/test/src/jdk/nashorn/api/scripting/ScriptEngineTest.java	Tue Aug 27 15:54:45 2013 +0530
@@ -30,6 +30,7 @@
 import static org.testng.Assert.assertTrue;
 import static org.testng.Assert.fail;
 
+import java.io.PrintWriter;
 import java.io.StringReader;
 import java.io.StringWriter;
 import java.lang.reflect.Method;
@@ -400,8 +401,7 @@
             exp.printStackTrace();
             fail(exp.getMessage());
         }
-        // dos2unix - fix line endings if running on windows
-        assertEquals(sw.toString().replaceAll("\r", ""), "hello world\n");
+        assertEquals(sw.toString(), println("hello world"));
     }
 
     @Test
@@ -490,8 +490,7 @@
             fail(t.getMessage());
         }
 
-        // dos2unix - fix line endings if running on windows
-        assertEquals(sw.toString().replaceAll("\r", ""), "hello\n");
+        assertEquals(sw.toString(), println("hello"));
     }
 
     @Test
@@ -508,7 +507,14 @@
             fail(t.getMessage());
         }
 
-        // dos2unix - fix line endings if running on windows
-        assertEquals(sw.toString().replaceAll("\r", ""), "34 true hello\n");
+        assertEquals(sw.toString(), println("34 true hello"));
+    }
+
+    private static final String LINE_SEPARATOR = System.getProperty("line.separator");
+
+    // Returns String that would be the result of calling PrintWriter.println
+    // of the given String. (This is to handle platform specific newline).
+    private static String println(final String str) {
+        return str + LINE_SEPARATOR;
     }
 }