changeset 2810:b0b25c1f6cbd

8023522: tools/javac/tree/TypeAnnotationsPretty.java test cases with @TA newline fail on windows only Reviewed-by: darcy
author jjg
date Thu, 29 Aug 2013 11:57:52 -0700
parents 0e6577980181
children 9c0e192c0926
files test/tools/javac/tree/TypeAnnotationsPretty.java
diffstat 1 files changed, 16 insertions(+), 17 deletions(-) [+]
line wrap: on
line diff
--- a/test/tools/javac/tree/TypeAnnotationsPretty.java	Thu Aug 29 11:41:20 2013 -0700
+++ b/test/tools/javac/tree/TypeAnnotationsPretty.java	Thu Aug 29 11:57:52 2013 -0700
@@ -23,7 +23,7 @@
 
 /*
  * @test
- * @bug 1234567
+ * @bug 8023522
  * @summary test Pretty print of type annotations
  * @author wmdietl
  */
@@ -87,7 +87,7 @@
         }
         if (!tap.mismatches.isEmpty()) {
             for (String mm : tap.mismatches)
-                System.err.println(mm + "\n");
+                System.err.println(mm + NL);
             throw new RuntimeException("Tests failed!");
         }
     }
@@ -107,6 +107,7 @@
             "@Target(ElementType.TYPE_USE)" +
             "@interface TD {}";
 
+    private static final String NL = System.getProperty("line.separator");
 
     private void runField(String code) throws IOException {
         String src = prefix +
@@ -116,17 +117,10 @@
         JavacTaskImpl ct = (JavacTaskImpl) tool.getTask(null, null, null, null,
                 null, Arrays.asList(new MyFileObject(src)));
 
-
         for (CompilationUnitTree cut : ct.parse()) {
             JCTree.JCVariableDecl var =
                     (JCTree.JCVariableDecl) ((ClassTree) cut.getTypeDecls().get(0)).getMembers().get(0);
-
-            if (!code.equals(var.toString())) {
-                mismatches.add("Expected: " + code +
-                        "\nObtained: " + var.toString());
-            } else {
-                matches.add("Passed: " + code);
-            }
+            checkMatch(code, var);
         }
     }
 
@@ -140,15 +134,20 @@
 
 
         for (CompilationUnitTree cut : ct.parse()) {
-            JCTree.JCMethodDecl var =
+            JCTree.JCMethodDecl meth =
                     (JCTree.JCMethodDecl) ((ClassTree) cut.getTypeDecls().get(0)).getMembers().get(0);
+            checkMatch(code, meth);
+        }
+    }
 
-            if (!code.equals(var.toString())) {
-                mismatches.add("Expected: " + code +
-                        "\nObtained: " + var.toString());
-            } else {
-                matches.add("Passed: " + code);
-            }
+    void checkMatch(String code, JCTree tree) {
+        String expect = code.replace("\n", NL);
+        String found = tree.toString();
+        if (!expect.equals(found)) {
+            mismatches.add("Expected: " + expect + NL +
+                    "Obtained: " + found);
+        } else {
+            matches.add("Passed: " + expect);
         }
     }
 }