From 8358afbcd130d02a030a8fdb600498af98c42097 Mon Sep 17 00:00:00 2001 From: Andrey Breslav Date: Sat, 9 Jun 2012 15:49:26 +0400 Subject: [PATCH] More diagnostic messages + output filter --- .../cli/jvm/compiler/NamespaceComparator.java | 49 ++++++++++++++----- 1 file changed, 36 insertions(+), 13 deletions(-) diff --git a/compiler/tests/org/jetbrains/jet/cli/jvm/compiler/NamespaceComparator.java b/compiler/tests/org/jetbrains/jet/cli/jvm/compiler/NamespaceComparator.java index 7ee66f8b8e8..1d4f0fb1fae 100644 --- a/compiler/tests/org/jetbrains/jet/cli/jvm/compiler/NamespaceComparator.java +++ b/compiler/tests/org/jetbrains/jet/cli/jvm/compiler/NamespaceComparator.java @@ -16,6 +16,8 @@ package org.jetbrains.jet.cli.jvm.compiler; +import com.google.common.base.Predicate; +import com.google.common.base.Predicates; import com.intellij.openapi.util.io.FileUtil; import org.jetbrains.annotations.NotNull; import org.jetbrains.jet.codegen.PropertyCodegen; @@ -45,14 +47,30 @@ import java.util.*; public class NamespaceComparator { private final boolean includeObject; + private final Predicate includeIntoOutput; - private NamespaceComparator(boolean includeObject) { + private NamespaceComparator(boolean includeObject, Predicate includeIntoOutput) { this.includeObject = includeObject; + this.includeIntoOutput = includeIntoOutput; } - public static void compareNamespaces(@NotNull NamespaceDescriptor nsa, @NotNull NamespaceDescriptor nsb, boolean includeObject, - @NotNull File txtFile) { - String serialized = new NamespaceComparator(includeObject).doCompareNamespaces(nsa, nsb); + public static void compareNamespaces( + @NotNull NamespaceDescriptor nsa, + @NotNull NamespaceDescriptor nsb, + boolean includeObject, + @NotNull File txtFile + ) { + compareNamespaces(nsa, nsb, includeObject, Predicates.alwaysTrue(), txtFile); + } + + public static void compareNamespaces( + @NotNull NamespaceDescriptor nsa, + @NotNull NamespaceDescriptor nsb, + boolean includeObject, + @NotNull Predicate includeIntoOutput, + @NotNull File txtFile + ) { + String serialized = new NamespaceComparator(includeObject, includeIntoOutput).doCompareNamespaces(nsa, nsb); try { if (!txtFile.exists()) { FileUtil.writeToFile(txtFile, serialized); @@ -104,9 +122,12 @@ public class NamespaceComparator { System.err.println("Namespace not found: " + namespaceDescriptorA.getQualifiedName()); } else { - sb.append("// \n"); - sb.append(doCompareNamespaces(namespaceDescriptorA, namespaceDescriptorB)); - sb.append("// \n"); + String comparison = doCompareNamespaces(namespaceDescriptorA, namespaceDescriptorB); + if (includeIntoOutput.apply(namespaceDescriptorA)) { + sb.append("// \n"); + sb.append(comparison); + sb.append("// \n"); + } } } else { @@ -117,15 +138,15 @@ public class NamespaceComparator { for (Name name : sorted(classifierNames)) { ClassifierDescriptor ca = nsa.getMemberScope().getClassifier(name); ClassifierDescriptor cb = nsb.getMemberScope().getClassifier(name); - Assert.assertTrue(ca != null); - Assert.assertTrue(cb != null); + Assert.assertTrue("Classifier not found in " + nsa + ": " + name, ca != null); + Assert.assertTrue("Classifier not found in " + nsb + ": " + name, cb != null); compareClassifiers(ca, cb, sb); } for (Name name : sorted(propertyNames)) { Set pa = nsa.getMemberScope().getProperties(name); Set pb = nsb.getMemberScope().getProperties(name); - compareDeclarationSets(pa, pb, sb); + compareDeclarationSets("Properties in package " + nsa, pa, pb, sb); Assert.assertTrue(nsb.getMemberScope().getFunctions(Name.identifier(PropertyCodegen.getterName(name))).isEmpty()); Assert.assertTrue(nsb.getMemberScope().getFunctions(Name.identifier(PropertyCodegen.setterName(name))).isEmpty()); @@ -134,17 +155,19 @@ public class NamespaceComparator { for (Name name : sorted(functionNames)) { Set fa = nsa.getMemberScope().getFunctions(name); Set fb = nsb.getMemberScope().getFunctions(name); - compareDeclarationSets(fa, fb, sb); + compareDeclarationSets("Functions in package " + nsa, fa, fb, sb); } return sb.toString(); } - private static void compareDeclarationSets(Set a, Set b, + private static void compareDeclarationSets(String message, + Set a, + Set b, @NotNull StringBuilder sb) { String at = serializedDeclarationSets(a); String bt = serializedDeclarationSets(b); - Assert.assertEquals(at, bt); + Assert.assertEquals(message, at, bt); sb.append(at); }