6985115: tests create too much output

Reviewed-by: mcimadamore
This commit is contained in:
Jonathan Gibbons 2010-09-16 09:57:37 -07:00
parent 1144807f1f
commit e0caf9f660
7 changed files with 53 additions and 35 deletions

View file

@ -71,12 +71,10 @@ public class T6855236 extends AbstractProcessor {
@Override @Override
public Object visitMethodInvocation(MethodInvocationTree node, Trees p) { public Object visitMethodInvocation(MethodInvocationTree node, Trees p) {
System.out.print("current path: "); System.out.println("current path: ");
for (Tree t : getCurrentPath()) { for (Tree t : getCurrentPath()) {
System.out.print('/'); System.out.println(" " + t.getKind() + ": " + trim(t, 64));
System.out.print(t); }
}
System.out.println();
System.out.println("parent path: " + getCurrentPath().getParentPath()); System.out.println("parent path: " + getCurrentPath().getParentPath());
System.out.println("method select: " + node.getMethodSelect().toString()); System.out.println("method select: " + node.getMethodSelect().toString());
for (ExpressionTree arg : node.getArguments()) { for (ExpressionTree arg : node.getArguments()) {
@ -88,12 +86,20 @@ public class T6855236 extends AbstractProcessor {
@Override @Override
public Object visitExpressionStatement(ExpressionStatementTree node, Trees p) { public Object visitExpressionStatement(ExpressionStatementTree node, Trees p) {
ExpressionTree t = node.getExpression(); 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); 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;
}
} }

View file

@ -282,13 +282,13 @@ public class CheckAttributedTree {
Iterable<? extends CompilationUnitTree> trees = task.parse(); Iterable<? extends CompilationUnitTree> trees = task.parse();
task.analyze(); task.analyze();
List<Pair<JCCompilationUnit, JCTree>> res = new ArrayList<>(); 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) { for (CompilationUnitTree t : trees) {
JCCompilationUnit cu = (JCCompilationUnit)t; JCCompilationUnit cu = (JCCompilationUnit)t;
for (JCTree def : cu.defs) { for (JCTree def : cu.defs) {
if (def.getTag() == JCTree.CLASSDEF && if (def.getTag() == JCTree.CLASSDEF &&
analyzedElems.contains(((JCTree.JCClassDecl)def).sym)) { analyzedElems.contains(((JCTree.JCClassDecl)def).sym)) {
System.out.println("Adding pair..."); //System.out.println("Adding pair...");
res.add(new Pair<>(cu, def)); res.add(new Pair<>(cu, def));
} }
} }

View file

@ -181,6 +181,16 @@ public abstract class AbstractTreeScannerTest {
errors++; errors++;
} }
/**
* 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. * Report an error for a specific tree node.
* @param file the source file for the tree * @param file the source file for the tree
@ -197,7 +207,7 @@ public abstract class AbstractTreeScannerTest {
*/ */
String trim(Tree tree, int len) { String trim(Tree tree, int len) {
JCTree t = (JCTree) tree; 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); return (s.length() < len) ? s : s.substring(0, len);
} }

View file

@ -89,12 +89,13 @@ public class JavacTreeScannerTest extends AbstractTreeScannerTest {
scan(tree); scan(tree);
expect = new HashSet<JCTree>(); expect = new HashSet<JCTree>();
reflectiveScan(tree); reflectiveScan(tree);
if (found.equals(expect)) { if (found.equals(expect)) {
System.err.println(found.size() + " trees compared OK"); //System.err.println(sourcefile.getName() + ": trees compared OK");
return found.size(); return found.size();
} }
error("Differences found for " + tree.sourcefile.getName()); error(sourcefile, "differences found");
if (found.size() != expect.size()) if (found.size() != expect.size())
error("Size mismatch; found: " + found.size() + ", expected: " + expect.size()); error("Size mismatch; found: " + found.size() + ", expected: " + expect.size());
@ -103,13 +104,13 @@ public class JavacTreeScannerTest extends AbstractTreeScannerTest {
missing.addAll(expect); missing.addAll(expect);
missing.removeAll(found); missing.removeAll(found);
for (JCTree t: missing) for (JCTree t: missing)
error(tree.sourcefile, t, "missing"); error(sourcefile, t, "missing");
Set<JCTree> excess = new HashSet<JCTree>(); Set<JCTree> excess = new HashSet<JCTree>();
excess.addAll(found); excess.addAll(found);
excess.removeAll(expect); excess.removeAll(expect);
for (JCTree t: excess) for (JCTree t: excess)
error(tree.sourcefile, t, "unexpected"); error(sourcefile, t, "unexpected");
return 0; return 0;
} }
@ -119,7 +120,7 @@ public class JavacTreeScannerTest extends AbstractTreeScannerTest {
public void scan(JCTree tree) { public void scan(JCTree tree) {
if (tree == null) if (tree == null)
return; return;
System.err.println("FOUND: " + tree.getTag() + " " + trim(tree, 64)); //System.err.println("FOUND: " + tree.getTag() + " " + trim(tree, 64));
found.add(tree); found.add(tree);
super.scan(tree); super.scan(tree);
} }
@ -130,7 +131,7 @@ public class JavacTreeScannerTest extends AbstractTreeScannerTest {
return; return;
if (o instanceof JCTree) { if (o instanceof JCTree) {
JCTree tree = (JCTree) o; 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); expect.add(tree);
for (Field f: getFields(tree)) { for (Field f: getFields(tree)) {
try { try {

View file

@ -91,12 +91,13 @@ public class SourceTreeScannerTest extends AbstractTreeScannerTest {
scan(tree, null); scan(tree, null);
expect = new HashSet<Tree>(); expect = new HashSet<Tree>();
reflectiveScan(tree); reflectiveScan(tree);
if (found.equals(expect)) { if (found.equals(expect)) {
System.err.println(found.size() + " trees compared OK"); //System.err.println(sourcefile.getName() + ": trees compared OK");
return found.size(); return found.size();
} }
error("Differences found for " + tree.sourcefile.getName()); error(sourcefile.getName() + ": differences found");
if (found.size() != expect.size()) if (found.size() != expect.size())
error("Size mismatch; found: " + found.size() + ", expected: " + expect.size()); error("Size mismatch; found: " + found.size() + ", expected: " + expect.size());
@ -105,13 +106,13 @@ public class SourceTreeScannerTest extends AbstractTreeScannerTest {
missing.addAll(expect); missing.addAll(expect);
missing.removeAll(found); missing.removeAll(found);
for (Tree t: missing) for (Tree t: missing)
error(tree.sourcefile, t, "missing"); error(sourcefile, t, "missing");
Set<Tree> excess = new HashSet<Tree>(); Set<Tree> excess = new HashSet<Tree>();
excess.addAll(found); excess.addAll(found);
excess.removeAll(expect); excess.removeAll(expect);
for (Tree t: excess) for (Tree t: excess)
error(tree.sourcefile, t, "unexpected"); error(sourcefile, t, "unexpected");
return 0; return 0;
} }
@ -121,7 +122,7 @@ public class SourceTreeScannerTest extends AbstractTreeScannerTest {
public Void scan(Tree tree, Void ignore) { public Void scan(Tree tree, Void ignore) {
if (tree == null) if (tree == null)
return null; return null;
System.err.println("FOUND: " + tree.getKind() + " " + trim(tree, 64)); //System.err.println("FOUND: " + tree.getKind() + " " + trim(tree, 64));
found.add(tree); found.add(tree);
return super.scan(tree, ignore); return super.scan(tree, ignore);
} }
@ -132,7 +133,7 @@ public class SourceTreeScannerTest extends AbstractTreeScannerTest {
return; return;
if (o instanceof JCTree) { if (o instanceof JCTree) {
JCTree tree = (JCTree) o; 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); expect.add(tree);
for (Field f: getFields(tree)) { for (Field f: getFields(tree)) {
if (TypeBoundKind.class.isAssignableFrom(f.getType())) { if (TypeBoundKind.class.isAssignableFrom(f.getType())) {

View file

@ -39,25 +39,25 @@ public class T6868539
} }
void run() { 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 // 2: currently unused
verify("T6868539", "Integer +123456"); // 3: Integer verify(output, "Integer +123456"); // 3: Integer
verify("T6868539", "Float +123456.0f"); // 4: Float verify(output, "Float +123456.0f"); // 4: Float
verify("T6868539", "Long +123456l"); // 5: Long verify(output, "Long +123456l"); // 5: Long
verify("T6868539", "Double +123456.0d"); // 6: Double verify(output, "Double +123456.0d"); // 6: Double
verify("T6868539", "Class +#[0-9]+ +// + T6868539"); // 7: Class verify(output, "Class +#[0-9]+ +// + T6868539"); // 7: Class
verify("T6868539", "String +#[0-9]+ +// + not found"); // 8: String verify(output, "String +#[0-9]+ +// + not found"); // 8: String
verify("T6868539", "Fieldref +#[0-9]+\\.#[0-9]+ +// +T6868539.errors:I"); // 9: Fieldref verify(output, "Fieldref +#[0-9]+\\.#[0-9]+ +// +T6868539.errors:I"); // 9: Fieldref
verify("T6868539", "Methodref +#[0-9]+\\.#[0-9]+ +// +T6868539.run:\\(\\)V"); // 10: Methodref verify(output, "Methodref +#[0-9]+\\.#[0-9]+ +// +T6868539.run:\\(\\)V"); // 10: Methodref
verify("T6868539", "InterfaceMethodref +#[0-9]+\\.#[0-9]+ +// +java/lang/Runnable\\.run:\\(\\)V"); verify(output, "InterfaceMethodref +#[0-9]+\\.#[0-9]+ +// +java/lang/Runnable\\.run:\\(\\)V");
// 11: InterfaceMethodref // 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) if (errors > 0)
throw new Error(errors + " found."); throw new Error(errors + " found.");
} }
void verify(String className, String... expects) { void verify(String output, String... expects) {
String output = javap(className);
for (String expect: expects) { for (String expect: expects) {
if (!output.matches("(?s).*" + expect + ".*")) if (!output.matches("(?s).*" + expect + ".*"))
error(expect + " not found"); error(expect + " not found");

View file

@ -39,7 +39,7 @@ public class T6980017 {
String[] args = { String[] args = {
"-v", "-v",
"-XDdetails:source", "-XDdetails:source",
"java.lang.String" "java.lang.Object"
}; };
StringWriter sw = new StringWriter(); StringWriter sw = new StringWriter();