Introduced compareNamespaceWithFile() method.
This commit is contained in:
@@ -31,6 +31,7 @@ import java.util.Arrays;
|
||||
import static org.jetbrains.jet.jvm.compiler.LoadDescriptorUtil.analyzeKotlinAndLoadTestNamespace;
|
||||
import static org.jetbrains.jet.jvm.compiler.LoadDescriptorUtil.compileJavaAndLoadTestNamespaceAndBindingContextFromBinary;
|
||||
import static org.jetbrains.jet.test.util.NamespaceComparator.DONT_INCLUDE_METHODS_OF_OBJECT;
|
||||
import static org.jetbrains.jet.test.util.NamespaceComparator.compareNamespaceWithFile;
|
||||
import static org.jetbrains.jet.test.util.NamespaceComparator.compareNamespaces;
|
||||
|
||||
/**
|
||||
@@ -46,23 +47,22 @@ public abstract class AbstractLoadJavaTest extends TestCaseWithTmpdir {
|
||||
File javaFile = new File(javaFileName);
|
||||
File ktFile = new File(javaFile.getPath().replaceFirst("\\.java$", ".kt"));
|
||||
File txtFile = new File(javaFile.getPath().replaceFirst("\\.java$", ".txt"));
|
||||
NamespaceDescriptor nsa = analyzeKotlinAndLoadTestNamespace(ktFile, myTestRootDisposable, ConfigurationKind.JDK_AND_ANNOTATIONS);
|
||||
Pair<NamespaceDescriptor, BindingContext> nsbAndBindingContext = compileJavaAndLoadTestNamespaceAndBindingContextFromBinary(
|
||||
NamespaceDescriptor kotlinNamespace = analyzeKotlinAndLoadTestNamespace(ktFile, myTestRootDisposable, ConfigurationKind.JDK_AND_ANNOTATIONS);
|
||||
Pair<NamespaceDescriptor, BindingContext> javaNamespaceAndContext = compileJavaAndLoadTestNamespaceAndBindingContextFromBinary(
|
||||
Arrays.asList(javaFile, ExpectedLoadErrorsUtil.ANNOTATION_SOURCE_FILE),
|
||||
tmpdir, myTestRootDisposable, ConfigurationKind.JDK_AND_ANNOTATIONS);
|
||||
checkLoadedNamespaces(txtFile, nsa, nsbAndBindingContext);
|
||||
checkLoadedNamespaces(txtFile, kotlinNamespace, javaNamespaceAndContext);
|
||||
}
|
||||
|
||||
public static void checkLoadedNamespaces(
|
||||
File txtFile,
|
||||
NamespaceDescriptor nsa,
|
||||
Pair<NamespaceDescriptor, BindingContext> nsbAndBindingContext
|
||||
private static void checkForLoadErrorsAndCompare(
|
||||
@NotNull Pair<NamespaceDescriptor, BindingContext> javaNamespaceAndContext,
|
||||
@NotNull Runnable compareNamespacesRunnable
|
||||
) {
|
||||
NamespaceDescriptor nsb = nsbAndBindingContext.first;
|
||||
NamespaceDescriptor javaNamespace = javaNamespaceAndContext.first;
|
||||
|
||||
boolean fail = false;
|
||||
try {
|
||||
ExpectedLoadErrorsUtil.checkForLoadErrors(nsb, nsbAndBindingContext.second);
|
||||
ExpectedLoadErrorsUtil.checkForLoadErrors(javaNamespace, javaNamespaceAndContext.second);
|
||||
}
|
||||
catch (ComparisonFailure e) {
|
||||
// to let the next check run even if this one failed
|
||||
@@ -76,9 +76,34 @@ public abstract class AbstractLoadJavaTest extends TestCaseWithTmpdir {
|
||||
fail = true;
|
||||
}
|
||||
|
||||
compareNamespaces(nsa, nsb, DONT_INCLUDE_METHODS_OF_OBJECT, txtFile);
|
||||
compareNamespacesRunnable.run();
|
||||
if (fail) {
|
||||
fail("See error above");
|
||||
}
|
||||
}
|
||||
|
||||
public static void checkLoadedNamespaces(
|
||||
final File txtFile,
|
||||
final NamespaceDescriptor kotlinNamespace,
|
||||
final Pair<NamespaceDescriptor, BindingContext> javaNamespaceAndContext
|
||||
) {
|
||||
checkForLoadErrorsAndCompare(javaNamespaceAndContext, new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
compareNamespaces(kotlinNamespace, javaNamespaceAndContext.first, DONT_INCLUDE_METHODS_OF_OBJECT, txtFile);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public static void checkJavaNamespace(
|
||||
final File txtFile,
|
||||
final Pair<NamespaceDescriptor, BindingContext> javaNamespaceAndContext
|
||||
) {
|
||||
checkForLoadErrorsAndCompare(javaNamespaceAndContext, new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
compareNamespaceWithFile(javaNamespaceAndContext.first, DONT_INCLUDE_METHODS_OF_OBJECT, txtFile);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -49,6 +49,7 @@ import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import static org.jetbrains.jet.jvm.compiler.LoadDescriptorUtil.compileJavaAndLoadTestNamespaceAndBindingContextFromBinary;
|
||||
import static org.jetbrains.jet.test.util.NamespaceComparator.compareNamespaceWithFile;
|
||||
|
||||
/**
|
||||
* @author Pavel Talanov
|
||||
@@ -73,16 +74,14 @@ public final class LoadJavaCustomTest extends KotlinTestWithEnvironment {
|
||||
}
|
||||
});
|
||||
files.add(ExpectedLoadErrorsUtil.ANNOTATION_SOURCE_FILE);
|
||||
File expected = new File(expectedFileName);
|
||||
File tmpDir = JetTestUtils.tmpDir(expected.getName());
|
||||
File expectedFile = new File(expectedFileName);
|
||||
File tmpDir = JetTestUtils.tmpDir(expectedFile.getName());
|
||||
|
||||
Pair<NamespaceDescriptor, BindingContext> javaNamespaceAndBindingContext
|
||||
= compileJavaAndLoadTestNamespaceAndBindingContextFromBinary(files, tmpDir, getTestRootDisposable(),
|
||||
ConfigurationKind.JDK_ONLY);
|
||||
|
||||
NamespaceDescriptor javaNamespace = javaNamespaceAndBindingContext.first;
|
||||
//NOTE: comparing namespace to file (hack)
|
||||
AbstractLoadJavaTest.checkLoadedNamespaces(expected, javaNamespace, javaNamespaceAndBindingContext);
|
||||
AbstractLoadJavaTest.checkJavaNamespace(expectedFile, javaNamespaceAndBindingContext);
|
||||
}
|
||||
|
||||
public void testPackageLocalVisibility() throws Exception {
|
||||
@@ -172,8 +171,8 @@ public final class LoadJavaCustomTest extends KotlinTestWithEnvironment {
|
||||
LoadDescriptorUtil.TEST_PACKAGE_FQNAME, DescriptorSearchRule.INCLUDE_KOTLIN);
|
||||
assert namespaceDescriptor != null;
|
||||
|
||||
NamespaceComparator.compareNamespaces(namespaceDescriptor, namespaceDescriptor,
|
||||
NamespaceComparator.DONT_INCLUDE_METHODS_OF_OBJECT, new File(dir, "expected.txt"));
|
||||
compareNamespaceWithFile(namespaceDescriptor, NamespaceComparator.DONT_INCLUDE_METHODS_OF_OBJECT,
|
||||
new File(dir, "expected.txt"));
|
||||
|
||||
ExpectedLoadErrorsUtil.checkForLoadErrors(namespaceDescriptor, bindingTrace.getBindingContext());
|
||||
}
|
||||
|
||||
@@ -28,7 +28,7 @@ import java.io.File;
|
||||
|
||||
import static org.jetbrains.jet.jvm.compiler.LoadDescriptorUtil.*;
|
||||
import static org.jetbrains.jet.test.util.NamespaceComparator.DONT_INCLUDE_METHODS_OF_OBJECT;
|
||||
import static org.jetbrains.jet.test.util.NamespaceComparator.compareNamespaces;
|
||||
import static org.jetbrains.jet.test.util.NamespaceComparator.compareNamespaceWithFile;
|
||||
|
||||
/**
|
||||
* @author Pavel Talanov
|
||||
@@ -48,7 +48,7 @@ public final class LoadKotlinCustomTest extends TestCaseWithTmpdir {
|
||||
NamespaceDescriptor namespaceFromClass =
|
||||
compileKotlinAndLoadTestNamespaceDescriptorFromBinary(kotlinFile, tmpdir, myTestRootDisposable, ConfigurationKind.JDK_ONLY);
|
||||
|
||||
compareNamespaces(namespaceFromClass, namespaceFromClass, DONT_INCLUDE_METHODS_OF_OBJECT, expectedFile);
|
||||
compareNamespaceWithFile(namespaceFromClass, DONT_INCLUDE_METHODS_OF_OBJECT, expectedFile);
|
||||
}
|
||||
|
||||
private void loadDescriptorsFromSourceAndCompareWithTxt(@NotNull File expectedFile, @NotNull File kotlinFile)
|
||||
@@ -57,8 +57,8 @@ public final class LoadKotlinCustomTest extends TestCaseWithTmpdir {
|
||||
NamespaceDescriptor namespaceFromSource = exhaust.getBindingContext().get(BindingContext.FQNAME_TO_NAMESPACE_DESCRIPTOR,
|
||||
TEST_PACKAGE_FQNAME);
|
||||
assert namespaceFromSource != null;
|
||||
compareNamespaces(namespaceFromSource, namespaceFromSource, NamespaceComparator.DONT_INCLUDE_METHODS_OF_OBJECT.checkPrimaryConstructors(true),
|
||||
expectedFile);
|
||||
compareNamespaceWithFile(namespaceFromSource, NamespaceComparator.DONT_INCLUDE_METHODS_OF_OBJECT.checkPrimaryConstructors(true),
|
||||
expectedFile);
|
||||
}
|
||||
|
||||
private void doTest(
|
||||
|
||||
+3
-4
@@ -25,7 +25,7 @@ import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
import static org.jetbrains.jet.test.util.NamespaceComparator.DONT_INCLUDE_METHODS_OF_OBJECT;
|
||||
import static org.jetbrains.jet.test.util.NamespaceComparator.compareNamespaces;
|
||||
import static org.jetbrains.jet.test.util.NamespaceComparator.compareNamespaceWithFile;
|
||||
|
||||
public final class StaticMembersJavaDescriptorResolverTest extends AbstractJavaResolverDescriptorTest {
|
||||
|
||||
@@ -59,15 +59,14 @@ public final class StaticMembersJavaDescriptorResolverTest extends AbstractJavaR
|
||||
compileJavaFile(name + ".java");
|
||||
NamespaceDescriptor namespaceWithClass = javaDescriptorResolver.resolveNamespace(new FqName(DEFAULT_PACKAGE));
|
||||
Assert.assertNotNull(namespaceWithClass);
|
||||
compareNamespaces(namespaceWithClass, namespaceWithClass, DONT_INCLUDE_METHODS_OF_OBJECT, new File(PATH + name + "_non_static.txt"));
|
||||
compareNamespaceWithFile(namespaceWithClass, DONT_INCLUDE_METHODS_OF_OBJECT, new File(PATH + name + "_non_static.txt"));
|
||||
|
||||
NamespaceDescriptor namespaceWithStaticMembers = javaDescriptorResolver.resolveNamespace(new FqName(DEFAULT_PACKAGE + "." + name));
|
||||
File fileWithStaticMembers = new File(PATH + name + "_static.txt");
|
||||
if (namespaceWithStaticMembers == null) {
|
||||
Assert.assertTrue(!fileWithStaticMembers.exists());
|
||||
} else {
|
||||
compareNamespaces(namespaceWithStaticMembers, namespaceWithStaticMembers, DONT_INCLUDE_METHODS_OF_OBJECT,
|
||||
fileWithStaticMembers);
|
||||
compareNamespaceWithFile(namespaceWithStaticMembers, DONT_INCLUDE_METHODS_OF_OBJECT, fileWithStaticMembers);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+4
-3
@@ -25,12 +25,13 @@ import org.jetbrains.jet.lang.descriptors.NamespaceDescriptor;
|
||||
import org.jetbrains.jet.lang.psi.JetFile;
|
||||
import org.jetbrains.jet.lang.resolve.name.FqNameUnsafe;
|
||||
import org.jetbrains.jet.lang.resolve.name.Name;
|
||||
import org.jetbrains.jet.test.util.NamespaceComparator;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import static org.jetbrains.jet.test.util.NamespaceComparator.*;
|
||||
|
||||
/**
|
||||
* @author abreslav
|
||||
*/
|
||||
@@ -54,9 +55,9 @@ public abstract class AbstractLazyResolveDiagnosticsTest extends AbstractJetDiag
|
||||
// Only recurse into those namespaces mentioned in the files
|
||||
// Otherwise we'll be examining the whole JDK
|
||||
final Set<Name> names = LazyResolveTestUtil.getTopLevelPackagesFromFileList(jetFiles);
|
||||
NamespaceComparator.compareNamespaces(
|
||||
compareNamespaces(
|
||||
expected, actual,
|
||||
NamespaceComparator.RECURSIVE.filterRecursion(new Predicate<FqNameUnsafe>() {
|
||||
RECURSIVE.filterRecursion(new Predicate<FqNameUnsafe>() {
|
||||
@Override
|
||||
public boolean apply(FqNameUnsafe fqName) {
|
||||
if (fqName.isRoot()) return true;
|
||||
|
||||
+8
-8
@@ -71,13 +71,13 @@ public abstract class AbstractLazyResolveNamespaceComparingTest extends KotlinTe
|
||||
|
||||
File serializeResultsTo = new File(FileUtil.getNameWithoutExtension(testFileName) + ".txt");
|
||||
|
||||
NamespaceComparator.compareNamespaces(expected, actual,
|
||||
NamespaceComparator.DONT_INCLUDE_METHODS_OF_OBJECT.filterRecursion(
|
||||
new Predicate<FqNameUnsafe>() {
|
||||
@Override
|
||||
public boolean apply(FqNameUnsafe fqName) {
|
||||
return !KotlinBuiltIns.BUILT_INS_PACKAGE_FQ_NAME.toUnsafe().equals(fqName);
|
||||
}
|
||||
}).checkPrimaryConstructors(checkPrimaryConstructors), serializeResultsTo);
|
||||
NamespaceComparator.compareNamespaces(
|
||||
expected, actual, NamespaceComparator.DONT_INCLUDE_METHODS_OF_OBJECT.filterRecursion(
|
||||
new Predicate<FqNameUnsafe>() {
|
||||
@Override
|
||||
public boolean apply(FqNameUnsafe fqName) {
|
||||
return !KotlinBuiltIns.BUILT_INS_PACKAGE_FQ_NAME.toUnsafe().equals(fqName);
|
||||
}
|
||||
}).checkPrimaryConstructors(checkPrimaryConstructors), serializeResultsTo);
|
||||
}
|
||||
}
|
||||
|
||||
+3
-3
@@ -25,6 +25,8 @@ import org.junit.Test;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import static org.jetbrains.jet.test.util.NamespaceComparator.*;
|
||||
|
||||
/**
|
||||
* @author abreslav
|
||||
*/
|
||||
@@ -37,8 +39,6 @@ public class LazyResolveBuiltinClassesTest extends KotlinTestWithEnvironment {
|
||||
@Test
|
||||
public void testJetStandardLibrary() throws Exception {
|
||||
NamespaceDescriptor builtInsPackage = KotlinBuiltIns.getInstance().getBuiltInsPackage();
|
||||
NamespaceComparator.compareNamespaces(builtInsPackage, builtInsPackage,
|
||||
NamespaceComparator.RECURSIVE, new File("compiler/testData/builtin-classes.txt"));
|
||||
|
||||
compareNamespaceWithFile(builtInsPackage, RECURSIVE, new File("compiler/testData/builtin-classes.txt"));
|
||||
}
|
||||
}
|
||||
|
||||
+3
-3
@@ -59,9 +59,9 @@ public class LazyResolveStdlibLoadingTest extends KotlinTestWithEnvironmentManag
|
||||
ModuleDescriptor lazyModule = LazyResolveTestUtil.resolveLazily(files, stdlibEnvironment);
|
||||
|
||||
for (Name name : namespaceShortNames) {
|
||||
NamespaceDescriptor a = module.getRootNamespace().getMemberScope().getNamespace(name);
|
||||
NamespaceDescriptor b = lazyModule.getRootNamespace().getMemberScope().getNamespace(name);
|
||||
NamespaceComparator.compareNamespaces(a, b, NamespaceComparator.RECURSIVE, null);
|
||||
NamespaceDescriptor eager = module.getRootNamespace().getMemberScope().getNamespace(name);
|
||||
NamespaceDescriptor lazy = lazyModule.getRootNamespace().getMemberScope().getNamespace(name);
|
||||
NamespaceComparator.compareNamespaces(eager, lazy, NamespaceComparator.RECURSIVE, null);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -130,18 +130,42 @@ public class NamespaceComparator {
|
||||
}
|
||||
}
|
||||
|
||||
public static void compareNamespaceWithFile(
|
||||
@NotNull NamespaceDescriptor actualNamespace,
|
||||
@NotNull Configuration configuration,
|
||||
@NotNull File txtFile
|
||||
) {
|
||||
doCompareNamespaces(null, actualNamespace, configuration, txtFile);
|
||||
}
|
||||
|
||||
public static void compareNamespaces(
|
||||
@NotNull NamespaceDescriptor expectedNamespace,
|
||||
@NotNull NamespaceDescriptor actualNamespace,
|
||||
@NotNull Configuration configuration,
|
||||
@Nullable File txtFile
|
||||
) {
|
||||
if (expectedNamespace == actualNamespace) {
|
||||
throw new IllegalArgumentException("Don't invoke this method with expectedNamespace == actualNamespace." +
|
||||
"Invoke compareNamespaceWithFile() instead.");
|
||||
}
|
||||
doCompareNamespaces(expectedNamespace, actualNamespace, configuration, txtFile);
|
||||
}
|
||||
|
||||
private static void doCompareNamespaces(
|
||||
@Nullable NamespaceDescriptor expectedNamespace,
|
||||
@NotNull NamespaceDescriptor actualNamespace,
|
||||
@NotNull Configuration configuration,
|
||||
@Nullable File txtFile
|
||||
) {
|
||||
NamespaceComparator comparator = new NamespaceComparator(configuration);
|
||||
|
||||
String expectedSerialized = comparator.serializeRecursively(expectedNamespace);
|
||||
String actualSerialized = comparator.serializeRecursively(actualNamespace);
|
||||
|
||||
Assert.assertEquals("Expected and actual namespaces differ", expectedSerialized, actualSerialized);
|
||||
if (expectedNamespace != null) {
|
||||
String expectedSerialized = comparator.serializeRecursively(expectedNamespace);
|
||||
|
||||
Assert.assertEquals("Expected and actual namespaces differ", expectedSerialized, actualSerialized);
|
||||
}
|
||||
|
||||
if (txtFile != null) {
|
||||
try {
|
||||
@@ -151,7 +175,7 @@ public class NamespaceComparator {
|
||||
}
|
||||
String expected = FileUtil.loadFile(txtFile, true);
|
||||
|
||||
// compare with hardcopy: make sure nothing is lost in output
|
||||
// compare with hard copy: make sure nothing is lost in output
|
||||
Assert.assertEquals("Expected and actual namespaces differ from " + txtFile.getName(), expected, actualSerialized);
|
||||
}
|
||||
catch (IOException e) {
|
||||
|
||||
Reference in New Issue
Block a user