changeset 720:bbc9765d9ec6

6985115: tests create too much output Reviewed-by: mcimadamore
author jjg
date Thu, 16 Sep 2010 09:57:37 -0700
parents 6e2ccba61117
children c5df455918c4 50f9ac2f4730
files test/tools/javac/T6855236.java test/tools/javac/failover/CheckAttributedTree.java test/tools/javac/tree/AbstractTreeScannerTest.java test/tools/javac/tree/JavacTreeScannerTest.java test/tools/javac/tree/SourceTreeScannerTest.java test/tools/javap/T6868539.java test/tools/javap/T6980017.java
diffstat 7 files changed, 53 insertions(+), 35 deletions(-) [+]
line wrap: on
line diff
--- a/test/tools/javac/T6855236.java	Thu Sep 16 09:56:25 2010 -0700
+++ b/test/tools/javac/T6855236.java	Thu Sep 16 09:57:37 2010 -0700
@@ -71,12 +71,10 @@
 
         @Override
         public Object visitMethodInvocation(MethodInvocationTree node, Trees p) {
-            System.out.print("current path: ");
+            System.out.println("current path: ");
             for (Tree t : getCurrentPath()) {
-                System.out.print('/');
-                System.out.print(t);
-           }
-            System.out.println();
+                System.out.println("    " + t.getKind() + ": " + trim(t, 64));
+            }
             System.out.println("parent path: " + getCurrentPath().getParentPath());
             System.out.println("method select: " + node.getMethodSelect().toString());
             for (ExpressionTree arg : node.getArguments()) {
@@ -88,12 +86,20 @@
         @Override
         public Object visitExpressionStatement(ExpressionStatementTree node, Trees p) {
             ExpressionTree t = node.getExpression();
-            System.out.println("expression statement: " + t.toString());
+            System.out.println();
+            System.out.println("expression statement: " + trim(t, 64));
             return super.visitExpressionStatement(node, p);
         }
 
     }
 
+    private String trim(Tree t, int len) {
+        String s = t.toString().trim().replaceAll("\\s+", " ");
+        if (s.length() > len)
+            s = s.substring(0, len) + "...";
+        return s;
+    }
+
 }
 
 
--- a/test/tools/javac/failover/CheckAttributedTree.java	Thu Sep 16 09:56:25 2010 -0700
+++ b/test/tools/javac/failover/CheckAttributedTree.java	Thu Sep 16 09:57:37 2010 -0700
@@ -282,13 +282,13 @@
             Iterable<? extends CompilationUnitTree> trees = task.parse();
             task.analyze();
             List<Pair<JCCompilationUnit, JCTree>> res = new ArrayList<>();
-            System.out.println("Try to add pairs. Elems are " + analyzedElems);
+            //System.out.println("Try to add pairs. Elems are " + analyzedElems);
             for (CompilationUnitTree t : trees) {
                JCCompilationUnit cu = (JCCompilationUnit)t;
                for (JCTree def : cu.defs) {
                    if (def.getTag() == JCTree.CLASSDEF &&
                            analyzedElems.contains(((JCTree.JCClassDecl)def).sym)) {
-                       System.out.println("Adding pair...");
+                       //System.out.println("Adding pair...");
                        res.add(new Pair<>(cu, def));
                    }
                }
--- a/test/tools/javac/tree/AbstractTreeScannerTest.java	Thu Sep 16 09:56:25 2010 -0700
+++ b/test/tools/javac/tree/AbstractTreeScannerTest.java	Thu Sep 16 09:57:37 2010 -0700
@@ -182,6 +182,16 @@
     }
 
     /**
+     * Report an error. When the program is complete, the program will either
+     * exit or throw an Error if any errors have been reported.
+     * @param msg the error message
+     */
+    void error(JavaFileObject file, String msg) {
+        System.err.println(file.getName() + ": " + msg);
+        errors++;
+    }
+
+    /**
      *  Report an error for a specific tree node.
      *  @param file the source file for the tree
      *  @param t    the tree node
@@ -197,7 +207,7 @@
      */
     String trim(Tree tree, int len) {
         JCTree t = (JCTree) tree;
-        String s = t.toString().replaceAll("[\r\n]+", " ").replaceAll(" +", " ");
+        String s = t.toString().replaceAll("\\s+", " ");
         return (s.length() < len) ? s : s.substring(0, len);
     }
 
--- a/test/tools/javac/tree/JavacTreeScannerTest.java	Thu Sep 16 09:56:25 2010 -0700
+++ b/test/tools/javac/tree/JavacTreeScannerTest.java	Thu Sep 16 09:57:37 2010 -0700
@@ -89,12 +89,13 @@
             scan(tree);
             expect = new HashSet<JCTree>();
             reflectiveScan(tree);
+
             if (found.equals(expect)) {
-                System.err.println(found.size() + " trees compared OK");
+                //System.err.println(sourcefile.getName() + ": trees compared OK");
                 return found.size();
             }
 
-            error("Differences found for " + tree.sourcefile.getName());
+            error(sourcefile, "differences found");
 
             if (found.size() != expect.size())
                 error("Size mismatch; found: " + found.size() + ", expected: " + expect.size());
@@ -103,13 +104,13 @@
             missing.addAll(expect);
             missing.removeAll(found);
             for (JCTree t: missing)
-                error(tree.sourcefile, t, "missing");
+                error(sourcefile, t, "missing");
 
             Set<JCTree> excess = new HashSet<JCTree>();
             excess.addAll(found);
             excess.removeAll(expect);
             for (JCTree t: excess)
-                error(tree.sourcefile, t, "unexpected");
+                error(sourcefile, t, "unexpected");
 
             return 0;
         }
@@ -119,7 +120,7 @@
         public void scan(JCTree tree) {
             if (tree == null)
                 return;
-            System.err.println("FOUND: " + tree.getTag() + " " + trim(tree, 64));
+            //System.err.println("FOUND: " + tree.getTag() + " " + trim(tree, 64));
             found.add(tree);
             super.scan(tree);
         }
@@ -130,7 +131,7 @@
                 return;
             if (o instanceof JCTree) {
                 JCTree tree = (JCTree) o;
-                System.err.println("EXPECT: " + tree.getTag() + " " + trim(tree, 64));
+                //System.err.println("EXPECT: " + tree.getTag() + " " + trim(tree, 64));
                 expect.add(tree);
                 for (Field f: getFields(tree)) {
                     try {
--- a/test/tools/javac/tree/SourceTreeScannerTest.java	Thu Sep 16 09:56:25 2010 -0700
+++ b/test/tools/javac/tree/SourceTreeScannerTest.java	Thu Sep 16 09:57:37 2010 -0700
@@ -91,12 +91,13 @@
             scan(tree, null);
             expect = new HashSet<Tree>();
             reflectiveScan(tree);
+
             if (found.equals(expect)) {
-                System.err.println(found.size() + " trees compared OK");
+                //System.err.println(sourcefile.getName() + ": trees compared OK");
                 return found.size();
             }
 
-            error("Differences found for " + tree.sourcefile.getName());
+            error(sourcefile.getName() + ": differences found");
 
             if (found.size() != expect.size())
                 error("Size mismatch; found: " + found.size() + ", expected: " + expect.size());
@@ -105,13 +106,13 @@
             missing.addAll(expect);
             missing.removeAll(found);
             for (Tree t: missing)
-                error(tree.sourcefile, t, "missing");
+                error(sourcefile, t, "missing");
 
             Set<Tree> excess = new HashSet<Tree>();
             excess.addAll(found);
             excess.removeAll(expect);
             for (Tree t: excess)
-                error(tree.sourcefile, t, "unexpected");
+                error(sourcefile, t, "unexpected");
 
             return 0;
         }
@@ -121,7 +122,7 @@
         public Void scan(Tree tree, Void ignore) {
             if (tree == null)
                 return null;
-            System.err.println("FOUND: " + tree.getKind() + " " + trim(tree, 64));
+            //System.err.println("FOUND: " + tree.getKind() + " " + trim(tree, 64));
             found.add(tree);
             return super.scan(tree, ignore);
         }
@@ -132,7 +133,7 @@
                 return;
             if (o instanceof JCTree) {
                 JCTree tree = (JCTree) o;
-                System.err.println("EXPECT: " + tree.getKind() + " " + trim(tree, 64));
+                //System.err.println("EXPECT: " + tree.getKind() + " " + trim(tree, 64));
                 expect.add(tree);
                 for (Field f: getFields(tree)) {
                     if (TypeBoundKind.class.isAssignableFrom(f.getType())) {
--- a/test/tools/javap/T6868539.java	Thu Sep 16 09:56:25 2010 -0700
+++ b/test/tools/javap/T6868539.java	Thu Sep 16 09:57:37 2010 -0700
@@ -39,25 +39,25 @@
     }
 
     void run() {
-        verify("T6868539", "Utf8 +java/lang/String");                                   // 1: Utf8
+        String output = javap("T6868539");
+        verify(output, "Utf8 +java/lang/String");                                   // 1: Utf8
                                                                                         // 2: currently unused
-        verify("T6868539", "Integer +123456");                                          // 3: Integer
-        verify("T6868539", "Float +123456.0f");                                         // 4: Float
-        verify("T6868539", "Long +123456l");                                            // 5: Long
-        verify("T6868539", "Double +123456.0d");                                        // 6: Double
-        verify("T6868539", "Class +#[0-9]+ +// + T6868539");                            // 7: Class
-        verify("T6868539", "String +#[0-9]+ +// + not found");                          // 8: String
-        verify("T6868539", "Fieldref +#[0-9]+\\.#[0-9]+ +// +T6868539.errors:I");       // 9: Fieldref
-        verify("T6868539", "Methodref +#[0-9]+\\.#[0-9]+ +// +T6868539.run:\\(\\)V");   // 10: Methodref
-        verify("T6868539", "InterfaceMethodref +#[0-9]+\\.#[0-9]+ +// +java/lang/Runnable\\.run:\\(\\)V");
+        verify(output, "Integer +123456");                                          // 3: Integer
+        verify(output, "Float +123456.0f");                                         // 4: Float
+        verify(output, "Long +123456l");                                            // 5: Long
+        verify(output, "Double +123456.0d");                                        // 6: Double
+        verify(output, "Class +#[0-9]+ +// + T6868539");                            // 7: Class
+        verify(output, "String +#[0-9]+ +// + not found");                          // 8: String
+        verify(output, "Fieldref +#[0-9]+\\.#[0-9]+ +// +T6868539.errors:I");       // 9: Fieldref
+        verify(output, "Methodref +#[0-9]+\\.#[0-9]+ +// +T6868539.run:\\(\\)V");   // 10: Methodref
+        verify(output, "InterfaceMethodref +#[0-9]+\\.#[0-9]+ +// +java/lang/Runnable\\.run:\\(\\)V");
                                                                                         // 11: InterfaceMethodref
-        verify("T6868539", "NameAndType +#[0-9]+:#[0-9]+ +// +run:\\(\\)V");            // 12: NameAndType
+        verify(output, "NameAndType +#[0-9]+:#[0-9]+ +// +run:\\(\\)V");            // 12: NameAndType
         if (errors > 0)
             throw new Error(errors + " found.");
     }
 
-    void verify(String className, String... expects) {
-        String output = javap(className);
+    void verify(String output, String... expects) {
         for (String expect: expects) {
             if (!output.matches("(?s).*" + expect + ".*"))
                 error(expect + " not found");
--- a/test/tools/javap/T6980017.java	Thu Sep 16 09:56:25 2010 -0700
+++ b/test/tools/javap/T6980017.java	Thu Sep 16 09:57:37 2010 -0700
@@ -39,7 +39,7 @@
         String[] args = {
             "-v",
             "-XDdetails:source",
-            "java.lang.String"
+            "java.lang.Object"
         };
 
         StringWriter sw = new StringWriter();