[TEST] Extract compiler-specific test utils from :tests-common to new module
This commit is contained in:
+1
-2
@@ -6,11 +6,10 @@
|
||||
package org.jetbrains.kotlin.fir
|
||||
|
||||
import org.jetbrains.kotlin.test.ConfigurationKind
|
||||
import org.jetbrains.kotlin.test.TestJdkKind
|
||||
|
||||
abstract class AbstractFirDiagnosticsWithStdlibTest : AbstractFirDiagnosticsTest() {
|
||||
|
||||
override fun extractConfigurationKind(files: List<TestFile>): ConfigurationKind {
|
||||
return ConfigurationKind.ALL
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,6 +7,9 @@
|
||||
|
||||
package org.jetbrains.kotlin.test
|
||||
|
||||
import java.io.File
|
||||
import java.util.*
|
||||
import kotlin.collections.ArrayList
|
||||
import kotlin.contracts.ExperimentalContracts
|
||||
import kotlin.contracts.contract
|
||||
|
||||
@@ -34,3 +37,45 @@ internal fun assertTrue(message: String, value: Boolean) {
|
||||
fail(message)
|
||||
}
|
||||
}
|
||||
|
||||
abstract class Assertions {
|
||||
fun assertEqualsToFile(expectedFile: File, actual: String, sanitizer: (String) -> String = { it }) {
|
||||
assertEqualsToFile(expectedFile, actual, sanitizer) { "Actual data differs from file content" }
|
||||
}
|
||||
|
||||
abstract fun assertEqualsToFile(
|
||||
expectedFile: File,
|
||||
actual: String,
|
||||
sanitizer: (String) -> String = { it },
|
||||
message: (() -> String)
|
||||
)
|
||||
|
||||
abstract fun assertEquals(expected: Any?, actual: Any?, message: (() -> String)? = null)
|
||||
abstract fun assertNotEquals(expected: Any?, actual: Any?, message: (() -> String)? = null)
|
||||
abstract fun assertTrue(value: Boolean, message: (() -> String)? = null)
|
||||
abstract fun assertFalse(value: Boolean, message: (() -> String)? = null)
|
||||
abstract fun assertNotNull(value: Any?, message: (() -> String)? = null)
|
||||
abstract fun <T> assertSameElements(expected: Collection<T>, actual: Collection<T>, message: (() -> String)?)
|
||||
|
||||
fun <T> assertContainsElements(collection: Collection<T>, vararg expected: T) {
|
||||
assertContainsElements(collection, expected.toList())
|
||||
}
|
||||
|
||||
fun <T> assertContainsElements(collection: Collection<T>, expected: Collection<T>) {
|
||||
val copy = ArrayList(collection)
|
||||
copy.retainAll(expected)
|
||||
assertSameElements(copy, expected) { renderCollectionToString(collection) }
|
||||
}
|
||||
|
||||
fun renderCollectionToString(collection: Iterable<*>): String {
|
||||
if (!collection.iterator().hasNext()) {
|
||||
return "<empty>"
|
||||
}
|
||||
|
||||
return collection.joinToString("\n")
|
||||
}
|
||||
|
||||
abstract fun assertAll(exceptions: List<AssertionError>)
|
||||
|
||||
abstract fun fail(message: () -> String): Nothing
|
||||
}
|
||||
|
||||
+1
-1
@@ -5,8 +5,8 @@
|
||||
|
||||
package org.jetbrains.kotlin.test.model
|
||||
|
||||
import org.jetbrains.kotlin.test.Assertions
|
||||
import org.jetbrains.kotlin.test.directives.model.DirectivesContainer
|
||||
import org.jetbrains.kotlin.test.services.Assertions
|
||||
import org.jetbrains.kotlin.test.services.ServiceRegistrationData
|
||||
import org.jetbrains.kotlin.test.services.TestServices
|
||||
import org.jetbrains.kotlin.test.services.assertions
|
||||
|
||||
+3
-22
@@ -5,27 +5,8 @@
|
||||
|
||||
package org.jetbrains.kotlin.test.services
|
||||
|
||||
import java.io.File
|
||||
import org.jetbrains.kotlin.test.Assertions
|
||||
|
||||
abstract class Assertions : TestService {
|
||||
fun assertEqualsToFile(expectedFile: File, actual: String, sanitizer: (String) -> String = { it }) {
|
||||
assertEqualsToFile(expectedFile, actual, sanitizer) { "Actual data differs from file content" }
|
||||
}
|
||||
abstract class AssertionsService : Assertions(), TestService
|
||||
|
||||
abstract fun assertEqualsToFile(
|
||||
expectedFile: File,
|
||||
actual: String,
|
||||
sanitizer: (String) -> String = { it },
|
||||
message: (() -> String)
|
||||
)
|
||||
|
||||
abstract fun assertEquals(expected: Any?, actual: Any?, message: (() -> String)? = null)
|
||||
abstract fun assertNotEquals(expected: Any?, actual: Any?, message: (() -> String)? = null)
|
||||
abstract fun assertTrue(value: Boolean, message: (() -> String)? = null)
|
||||
abstract fun assertFalse(value: Boolean, message: (() -> String)? = null)
|
||||
abstract fun assertAll(exceptions: List<AssertionError>)
|
||||
|
||||
abstract fun fail(message: () -> String): Nothing
|
||||
}
|
||||
|
||||
val TestServices.assertions: Assertions by TestServices.testServiceAccessor()
|
||||
val TestServices.assertions: AssertionsService by TestServices.testServiceAccessor()
|
||||
|
||||
+1
@@ -5,6 +5,7 @@
|
||||
|
||||
package org.jetbrains.kotlin.test.services
|
||||
|
||||
import org.jetbrains.kotlin.test.Assertions
|
||||
import org.jetbrains.kotlin.test.model.*
|
||||
|
||||
abstract class DependencyProvider : TestService {
|
||||
|
||||
+1
-1
@@ -5,8 +5,8 @@
|
||||
|
||||
package org.jetbrains.kotlin.test.services.impl
|
||||
|
||||
import org.jetbrains.kotlin.test.Assertions
|
||||
import org.jetbrains.kotlin.test.directives.model.*
|
||||
import org.jetbrains.kotlin.test.services.Assertions
|
||||
|
||||
class RegisteredDirectivesParser(private val container: DirectivesContainer, private val assertions: Assertions) {
|
||||
companion object {
|
||||
|
||||
@@ -22,6 +22,7 @@ dependencies {
|
||||
testImplementation("org.junit.platform:junit-platform-commons:1.7.0")
|
||||
testApi(projectTests(":compiler:test-infrastructure"))
|
||||
testImplementation(projectTests(":compiler:test-infrastructure-utils"))
|
||||
testImplementation(projectTests(":compiler:tests-compiler-utils"))
|
||||
|
||||
testImplementation(intellijDep()) {
|
||||
// This dependency is needed only for FileComparisonFailure
|
||||
@@ -32,7 +33,30 @@ dependencies {
|
||||
// This is needed only for using FileComparisonFailure, which relies on JUnit 3 classes
|
||||
testRuntimeOnly(commonDep("junit:junit"))
|
||||
testRuntimeOnly(intellijDep()) {
|
||||
includeJars("jna", rootProject = rootProject)
|
||||
includeJars(
|
||||
"jps-model",
|
||||
"extensions",
|
||||
"util",
|
||||
"platform-api",
|
||||
"platform-impl",
|
||||
"idea",
|
||||
"guava",
|
||||
"trove4j",
|
||||
"asm-all",
|
||||
"log4j",
|
||||
"jdom",
|
||||
"streamex",
|
||||
"bootstrap",
|
||||
"jna",
|
||||
rootProject = rootProject
|
||||
)
|
||||
}
|
||||
|
||||
Platform[202] {
|
||||
testRuntimeOnly(intellijDep()) { includeJars("intellij-deps-fastutil-8.3.1-1") }
|
||||
}
|
||||
Platform[203].orHigher {
|
||||
testRuntimeOnly(intellijDep()) { includeJars("intellij-deps-fastutil-8.3.1-3") }
|
||||
}
|
||||
testRuntimeOnly(toolsJar())
|
||||
}
|
||||
|
||||
+1
-1
@@ -16,7 +16,7 @@ typealias Constructor<T> = (TestServices) -> T
|
||||
@DefaultsDsl
|
||||
class TestConfigurationBuilder {
|
||||
val defaultsProviderBuilder: DefaultsProviderBuilder = DefaultsProviderBuilder()
|
||||
lateinit var assertions: Assertions
|
||||
lateinit var assertions: AssertionsService
|
||||
|
||||
private val facades: MutableList<Constructor<AbstractTestFacade<*, *>>> = mutableListOf()
|
||||
|
||||
|
||||
+2
-2
@@ -5,14 +5,14 @@
|
||||
|
||||
package org.jetbrains.kotlin.test.frontend.fir.handlers
|
||||
|
||||
import org.jetbrains.kotlin.fir.AbstractFirDiagnosticsTest
|
||||
import org.jetbrains.kotlin.fir.FirCfgConsistencyChecker
|
||||
import org.jetbrains.kotlin.test.frontend.fir.FirOutputArtifact
|
||||
import org.jetbrains.kotlin.test.model.TestModule
|
||||
import org.jetbrains.kotlin.test.services.TestServices
|
||||
|
||||
class FirCfgConsistencyHandler(testServices: TestServices) : FirAnalysisHandler(testServices) {
|
||||
override fun processModule(module: TestModule, info: FirOutputArtifact) {
|
||||
info.firFiles.values.forEach { it.accept(AbstractFirDiagnosticsTest.CfgConsistencyChecker) }
|
||||
info.firFiles.values.forEach { it.accept(FirCfgConsistencyChecker(assertions)) }
|
||||
}
|
||||
|
||||
override fun processAfterAllModules(someAssertionWasFailed: Boolean) {}
|
||||
|
||||
+2
-2
@@ -18,7 +18,7 @@ import org.jetbrains.kotlin.test.utils.TestDisposable
|
||||
|
||||
class TestConfigurationImpl(
|
||||
defaultsProvider: DefaultsProvider,
|
||||
assertions: Assertions,
|
||||
assertions: AssertionsService,
|
||||
|
||||
facades: List<Constructor<AbstractTestFacade<*, *>>>,
|
||||
|
||||
@@ -86,7 +86,7 @@ class TestConfigurationImpl(
|
||||
)
|
||||
register(CompilerConfigurationProvider::class, environmentProvider)
|
||||
|
||||
register(Assertions::class, assertions)
|
||||
register(AssertionsService::class, assertions)
|
||||
register(DefaultsProvider::class, defaultsProvider)
|
||||
|
||||
register(DefaultRegisteredDirectivesProvider::class, DefaultRegisteredDirectivesProvider(defaultRegisteredDirectives))
|
||||
|
||||
+9
-1
@@ -14,7 +14,7 @@ import java.io.File
|
||||
import java.io.IOException
|
||||
import org.junit.jupiter.api.Assertions as JUnit5PlatformAssertions
|
||||
|
||||
object JUnit5Assertions : Assertions() {
|
||||
object JUnit5Assertions : AssertionsService() {
|
||||
override fun assertEqualsToFile(expectedFile: File, actual: String, sanitizer: (String) -> String, message: () -> String) {
|
||||
try {
|
||||
val actualText = actual.trim { it <= ' ' }.convertLineSeparators().trimTrailingWhitespacesAndAddNewlineAtEOF()
|
||||
@@ -56,6 +56,14 @@ object JUnit5Assertions : Assertions() {
|
||||
JUnit5PlatformAssertions.assertAll(exceptions.map { Executable { throw it } })
|
||||
}
|
||||
|
||||
override fun assertNotNull(value: Any?, message: (() -> String)?) {
|
||||
JUnit5PlatformAssertions.assertNotNull(value, message)
|
||||
}
|
||||
|
||||
override fun <T> assertSameElements(expected: Collection<T>, actual: Collection<T>, message: (() -> String)?) {
|
||||
JUnit5PlatformAssertions.assertIterableEquals(expected, actual, message)
|
||||
}
|
||||
|
||||
override fun fail(message: () -> String): Nothing {
|
||||
org.junit.jupiter.api.fail(message)
|
||||
}
|
||||
|
||||
+1
@@ -10,6 +10,7 @@ import org.jetbrains.kotlin.platform.TargetPlatform
|
||||
import org.jetbrains.kotlin.platform.js.JsPlatforms
|
||||
import org.jetbrains.kotlin.platform.jvm.JvmPlatforms
|
||||
import org.jetbrains.kotlin.platform.konan.NativePlatforms
|
||||
import org.jetbrains.kotlin.test.Assertions
|
||||
import org.jetbrains.kotlin.test.builders.LanguageVersionSettingsBuilder
|
||||
import org.jetbrains.kotlin.test.directives.ModuleStructureDirectives
|
||||
import org.jetbrains.kotlin.test.directives.model.ComposedRegisteredDirectives
|
||||
|
||||
@@ -46,7 +46,7 @@ dependencies {
|
||||
testCompile(project(":native:frontend.native"))
|
||||
testCompileOnly(project(":plugins:android-extensions-compiler"))
|
||||
testApi(projectTests(":generators:test-generator"))
|
||||
testCompile(projectTests(":compiler:tests-classic-compiler-utils"))
|
||||
testCompile(projectTests(":compiler:tests-compiler-utils"))
|
||||
testCompile(project(":kotlin-test:kotlin-test-jvm"))
|
||||
testCompile(projectTests(":compiler:tests-common-jvm6"))
|
||||
testCompile(project(":kotlin-scripting-compiler-impl"))
|
||||
|
||||
+6
-1
@@ -525,7 +525,12 @@ abstract class AbstractDiagnosticsTest : BaseDiagnosticsTest() {
|
||||
return
|
||||
}
|
||||
|
||||
val comparator = RecursiveDescriptorComparator(createdAffectedPackagesConfiguration(testFiles, modules.values))
|
||||
val comparator = RecursiveDescriptorComparator(
|
||||
createdAffectedPackagesConfiguration(
|
||||
testFiles,
|
||||
modules.values
|
||||
)
|
||||
)
|
||||
|
||||
val isMultiModuleTest = modules.size != 1
|
||||
|
||||
|
||||
@@ -6,7 +6,6 @@
|
||||
package org.jetbrains.kotlin.fir
|
||||
|
||||
import com.intellij.psi.PsiElement
|
||||
import junit.framework.TestCase
|
||||
import org.jetbrains.kotlin.KtNodeTypes
|
||||
import org.jetbrains.kotlin.checkers.diagnostics.factories.DebugInfoDiagnosticFactory1
|
||||
import org.jetbrains.kotlin.checkers.utils.TypeOfCall
|
||||
@@ -21,13 +20,8 @@ import org.jetbrains.kotlin.fir.declarations.FirProperty
|
||||
import org.jetbrains.kotlin.fir.expressions.FirExpression
|
||||
import org.jetbrains.kotlin.fir.expressions.FirExpressionWithSmartcast
|
||||
import org.jetbrains.kotlin.fir.expressions.FirFunctionCall
|
||||
import org.jetbrains.kotlin.fir.references.FirControlFlowGraphReference
|
||||
import org.jetbrains.kotlin.fir.references.FirNamedReference
|
||||
import org.jetbrains.kotlin.fir.references.FirResolvedNamedReference
|
||||
import org.jetbrains.kotlin.fir.resolve.dfa.FirControlFlowGraphReferenceImpl
|
||||
import org.jetbrains.kotlin.fir.resolve.dfa.cfg.CFGNode
|
||||
import org.jetbrains.kotlin.fir.resolve.dfa.cfg.ControlFlowGraph
|
||||
import org.jetbrains.kotlin.fir.resolve.dfa.cfg.EdgeKind
|
||||
import org.jetbrains.kotlin.fir.resolve.dfa.cfg.FirControlFlowGraphRenderVisitor
|
||||
import org.jetbrains.kotlin.fir.resolve.transformers.createAllCompilerResolveProcessors
|
||||
import org.jetbrains.kotlin.fir.symbols.AbstractFirBasedSymbol
|
||||
@@ -38,9 +32,9 @@ import org.jetbrains.kotlin.fir.types.ConeKotlinType
|
||||
import org.jetbrains.kotlin.fir.types.FirTypeRef
|
||||
import org.jetbrains.kotlin.fir.types.coneTypeSafe
|
||||
import org.jetbrains.kotlin.fir.visitors.FirDefaultVisitorVoid
|
||||
import org.jetbrains.kotlin.fir.visitors.FirVisitorVoid
|
||||
import org.jetbrains.kotlin.name.FqNameUnsafe
|
||||
import org.jetbrains.kotlin.test.KotlinTestUtils
|
||||
import org.jetbrains.kotlin.test.util.JUnit4Assertions
|
||||
import org.jetbrains.kotlin.util.OperatorNameConventions
|
||||
import org.jetbrains.kotlin.utils.addIfNotNull
|
||||
import java.io.File
|
||||
@@ -292,60 +286,7 @@ abstract class AbstractFirDiagnosticsTest : AbstractFirBaseDiagnosticsTest() {
|
||||
}
|
||||
|
||||
private fun checkCfgEdgeConsistency(firFiles: List<FirFile>) {
|
||||
firFiles.forEach { it.accept(CfgConsistencyChecker) }
|
||||
}
|
||||
|
||||
object CfgConsistencyChecker : FirVisitorVoid() {
|
||||
override fun visitElement(element: FirElement) {
|
||||
element.acceptChildren(this)
|
||||
}
|
||||
|
||||
override fun visitControlFlowGraphReference(controlFlowGraphReference: FirControlFlowGraphReference) {
|
||||
val graph = (controlFlowGraphReference as? FirControlFlowGraphReferenceImpl)?.controlFlowGraph ?: return
|
||||
assertEquals(ControlFlowGraph.State.Completed, graph.state)
|
||||
checkConsistency(graph)
|
||||
checkOrder(graph)
|
||||
}
|
||||
|
||||
private fun checkConsistency(graph: ControlFlowGraph) {
|
||||
for (node in graph.nodes) {
|
||||
for (to in node.followingNodes) {
|
||||
checkEdge(node, to)
|
||||
}
|
||||
for (from in node.previousNodes) {
|
||||
checkEdge(from, node)
|
||||
}
|
||||
if (node.followingNodes.isEmpty() && node.previousNodes.isEmpty()) {
|
||||
throw AssertionError("Unconnected CFG node: $node")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private val cfgKinds = listOf(EdgeKind.DeadForward, EdgeKind.CfgForward, EdgeKind.DeadBackward, EdgeKind.CfgBackward)
|
||||
|
||||
private fun checkEdge(from: CFGNode<*>, to: CFGNode<*>) {
|
||||
assertContainsElements(from.followingNodes, to)
|
||||
assertContainsElements(to.previousNodes, from)
|
||||
val fromKind = from.outgoingEdges.getValue(to).kind
|
||||
val toKind = to.incomingEdges.getValue(from).kind
|
||||
TestCase.assertEquals(fromKind, toKind)
|
||||
if (from.isDead && to.isDead) {
|
||||
assertContainsElements(cfgKinds, toKind)
|
||||
}
|
||||
}
|
||||
|
||||
private fun checkOrder(graph: ControlFlowGraph) {
|
||||
val visited = mutableSetOf<CFGNode<*>>()
|
||||
for (node in graph.nodes) {
|
||||
for (previousNode in node.previousNodes) {
|
||||
if (previousNode.owner != graph) continue
|
||||
if (!node.incomingEdges.getValue(previousNode).kind.isBack) {
|
||||
assertTrue(previousNode in visited)
|
||||
}
|
||||
}
|
||||
visited += node
|
||||
}
|
||||
}
|
||||
firFiles.forEach { it.accept(FirCfgConsistencyChecker(JUnit4Assertions)) }
|
||||
}
|
||||
|
||||
private fun checkCfgDumpNotExists(testDataFile: File) {
|
||||
|
||||
+4
-3
@@ -39,7 +39,7 @@ import org.jetbrains.kotlin.test.KotlinTestUtils.newConfiguration
|
||||
import org.jetbrains.kotlin.test.TestCaseWithTmpdir
|
||||
import org.jetbrains.kotlin.test.TestJdkKind
|
||||
import org.jetbrains.kotlin.test.util.KtTestUtil
|
||||
import org.jetbrains.kotlin.test.util.RecursiveDescriptorComparator.validateAndCompareDescriptorWithFile
|
||||
import org.jetbrains.kotlin.test.util.RecursiveDescriptorComparatorAdaptor.validateAndCompareDescriptorWithFile
|
||||
import org.junit.Assert
|
||||
import java.io.File
|
||||
import java.io.IOException
|
||||
@@ -83,8 +83,9 @@ abstract class AbstractCompileJavaAgainstKotlinTest : TestCaseWithTmpdir() {
|
||||
|
||||
if (!compiledSuccessfully) return
|
||||
|
||||
val configuration = newConfiguration(ConfigurationKind.ALL, TestJdkKind.FULL_JDK,
|
||||
KtTestUtil.getAnnotationsJar(), out)
|
||||
val configuration = newConfiguration(
|
||||
ConfigurationKind.ALL, TestJdkKind.FULL_JDK,
|
||||
KtTestUtil.getAnnotationsJar(), out)
|
||||
configuration.put(JVMConfigurationKeys.USE_PSI_CLASS_FILES_READING, true)
|
||||
val environment = KotlinCoreEnvironment.createForTests(testRootDisposable, configuration, EnvironmentConfigFiles.JVM_CONFIG_FILES)
|
||||
setupLanguageVersionSettingsForCompilerTests(ktFile.readText(), environment)
|
||||
|
||||
+4
-3
@@ -38,7 +38,7 @@ import org.jetbrains.kotlin.test.KotlinTestUtils.newConfiguration
|
||||
import org.jetbrains.kotlin.test.TestCaseWithTmpdir
|
||||
import org.jetbrains.kotlin.test.TestJdkKind
|
||||
import org.jetbrains.kotlin.test.util.KtTestUtil
|
||||
import org.jetbrains.kotlin.test.util.RecursiveDescriptorComparator.validateAndCompareDescriptorWithFile
|
||||
import org.jetbrains.kotlin.test.util.RecursiveDescriptorComparatorAdaptor.validateAndCompareDescriptorWithFile
|
||||
import org.junit.Assert
|
||||
import java.io.File
|
||||
import java.lang.annotation.Retention
|
||||
@@ -69,8 +69,9 @@ abstract class AbstractCompileKotlinAgainstJavaTest : TestCaseWithTmpdir() {
|
||||
|
||||
val environment = KotlinCoreEnvironment.createForTests(
|
||||
testRootDisposable,
|
||||
newConfiguration(ConfigurationKind.ALL, TestJdkKind.MOCK_JDK,
|
||||
KtTestUtil.getAnnotationsJar(), out),
|
||||
newConfiguration(
|
||||
ConfigurationKind.ALL, TestJdkKind.MOCK_JDK,
|
||||
KtTestUtil.getAnnotationsJar(), out),
|
||||
EnvironmentConfigFiles.JVM_CONFIG_FILES
|
||||
)
|
||||
|
||||
|
||||
+9
-3
@@ -31,7 +31,9 @@ import org.jetbrains.kotlin.resolve.DescriptorUtils;
|
||||
import org.jetbrains.kotlin.serialization.deserialization.descriptors.DeserializedClassDescriptor;
|
||||
import org.jetbrains.kotlin.test.*;
|
||||
import org.jetbrains.kotlin.test.util.DescriptorValidator;
|
||||
import org.jetbrains.kotlin.test.util.JUnit4Assertions;
|
||||
import org.jetbrains.kotlin.test.util.KtTestUtil;
|
||||
import org.jetbrains.kotlin.test.util.RecursiveDescriptorComparator.Configuration;
|
||||
import org.junit.Assert;
|
||||
|
||||
import java.io.File;
|
||||
@@ -44,14 +46,18 @@ import static org.jetbrains.kotlin.test.KotlinTestUtils.compileKotlinWithJava;
|
||||
import static org.jetbrains.kotlin.test.KotlinTestUtils.newConfiguration;
|
||||
import static org.jetbrains.kotlin.test.util.DescriptorValidator.ValidationVisitor.errorTypesAllowed;
|
||||
import static org.jetbrains.kotlin.test.util.DescriptorValidator.ValidationVisitor.errorTypesForbidden;
|
||||
import static org.jetbrains.kotlin.test.util.RecursiveDescriptorComparator.*;
|
||||
import static org.jetbrains.kotlin.test.util.RecursiveDescriptorComparator.DONT_INCLUDE_METHODS_OF_OBJECT;
|
||||
import static org.jetbrains.kotlin.test.util.RecursiveDescriptorComparator.RECURSIVE;
|
||||
import static org.jetbrains.kotlin.test.util.RecursiveDescriptorComparatorAdaptor.compareDescriptors;
|
||||
import static org.jetbrains.kotlin.test.util.RecursiveDescriptorComparatorAdaptor.validateAndCompareDescriptorWithFile;
|
||||
|
||||
/*
|
||||
The generated test compares package descriptors loaded from kotlin sources and read from compiled java.
|
||||
*/
|
||||
public abstract class AbstractLoadJavaTest extends TestCaseWithTmpdir {
|
||||
// There are two modules in each test case (sources and dependencies), so we should render declarations from both of them
|
||||
public static final Configuration COMPARATOR_CONFIGURATION = DONT_INCLUDE_METHODS_OF_OBJECT.renderDeclarationsFromOtherModules(true);
|
||||
public static final Configuration
|
||||
COMPARATOR_CONFIGURATION = DONT_INCLUDE_METHODS_OF_OBJECT.renderDeclarationsFromOtherModules(true);
|
||||
|
||||
protected void doTestCompiledJava(@NotNull String javaFileName) throws Exception {
|
||||
doTestCompiledJava(javaFileName, COMPARATOR_CONFIGURATION);
|
||||
@@ -346,7 +352,7 @@ public abstract class AbstractLoadJavaTest extends TestCaseWithTmpdir {
|
||||
) {
|
||||
boolean fail = false;
|
||||
try {
|
||||
ExpectedLoadErrorsUtil.checkForLoadErrors(javaPackage, bindingContext);
|
||||
ExpectedLoadErrorsUtil.checkForLoadErrors(javaPackage, bindingContext, JUnit4Assertions.INSTANCE);
|
||||
}
|
||||
catch (ComparisonFailure e) {
|
||||
// to let the next check run even if this one failed
|
||||
|
||||
+5
-4
@@ -30,6 +30,7 @@ import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.resolve.lazy.JvmResolveUtil
|
||||
import org.jetbrains.kotlin.test.*
|
||||
import org.jetbrains.kotlin.test.util.RecursiveDescriptorComparator
|
||||
import org.jetbrains.kotlin.test.util.RecursiveDescriptorComparatorAdaptor
|
||||
import java.io.File
|
||||
import java.net.URLClassLoader
|
||||
|
||||
@@ -64,10 +65,10 @@ abstract class AbstractLocalClassProtoTest : TestCaseWithTmpdir() {
|
||||
val classDescriptor = components.classDeserializer.deserializeClass(clazz.classId)
|
||||
?: error("Class is not resolved: $clazz (classId = ${clazz.classId})")
|
||||
|
||||
RecursiveDescriptorComparator.validateAndCompareDescriptorWithFile(
|
||||
classDescriptor,
|
||||
RecursiveDescriptorComparator.DONT_INCLUDE_METHODS_OF_OBJECT,
|
||||
KotlinTestUtils.replaceExtension(source, "txt")
|
||||
RecursiveDescriptorComparatorAdaptor.validateAndCompareDescriptorWithFile(
|
||||
classDescriptor,
|
||||
RecursiveDescriptorComparator.DONT_INCLUDE_METHODS_OF_OBJECT,
|
||||
KotlinTestUtils.replaceExtension(source, "txt")
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
+2
-1
@@ -22,6 +22,7 @@ import org.jetbrains.kotlin.test.ConfigurationKind
|
||||
import org.jetbrains.kotlin.test.KotlinTestWithEnvironment
|
||||
import org.jetbrains.kotlin.test.TestJdkKind
|
||||
import org.jetbrains.kotlin.test.util.RecursiveDescriptorComparator
|
||||
import org.jetbrains.kotlin.test.util.RecursiveDescriptorComparatorAdaptor
|
||||
import java.io.File
|
||||
|
||||
abstract class AbstractBuiltInsWithJDKMembersTest : KotlinTestWithEnvironment() {
|
||||
@@ -40,7 +41,7 @@ abstract class AbstractBuiltInsWithJDKMembersTest : KotlinTestWithEnvironment()
|
||||
val loaded = module.packageFragmentProvider.packageFragments(packageFqName)
|
||||
.filterIsInstance<BuiltInsPackageFragment>()
|
||||
.single { !it.isFallback }
|
||||
RecursiveDescriptorComparator.validateAndCompareDescriptorWithFile(
|
||||
RecursiveDescriptorComparatorAdaptor.validateAndCompareDescriptorWithFile(
|
||||
loaded, configuration,
|
||||
File("compiler/testData/builtin-classes/$builtinVersionName/" + packageFqName.asString().replace('.', '-') + ".txt")
|
||||
)
|
||||
|
||||
@@ -8,7 +8,6 @@ package org.jetbrains.kotlin.test
|
||||
import com.google.common.collect.ImmutableList
|
||||
import com.google.common.collect.ImmutableMap
|
||||
import org.jetbrains.kotlin.builtins.StandardNames
|
||||
import org.jetbrains.kotlin.checkers.CompilerTestLanguageVersionSettings
|
||||
import org.jetbrains.kotlin.checkers.ENABLE_JVM_PREVIEW
|
||||
import org.jetbrains.kotlin.checkers.parseLanguageVersionSettings
|
||||
import org.jetbrains.kotlin.cli.common.CLIConfigurationKeys
|
||||
|
||||
@@ -0,0 +1,50 @@
|
||||
/*
|
||||
* Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.test.util
|
||||
|
||||
import org.jetbrains.kotlin.test.Assertions
|
||||
import org.jetbrains.kotlin.test.KotlinTestUtils
|
||||
import org.jetbrains.kotlin.test.testFramework.KtUsefulTestCase
|
||||
import org.junit.Assert
|
||||
import java.io.File
|
||||
|
||||
object JUnit4Assertions : Assertions() {
|
||||
override fun assertEqualsToFile(expectedFile: File, actual: String, sanitizer: (String) -> String, message: () -> String) {
|
||||
KotlinTestUtils.assertEqualsToFile(expectedFile, actual, sanitizer)
|
||||
}
|
||||
|
||||
override fun assertEquals(expected: Any?, actual: Any?, message: (() -> String)?) {
|
||||
Assert.assertEquals(message?.invoke(), expected, actual)
|
||||
}
|
||||
|
||||
override fun assertNotEquals(expected: Any?, actual: Any?, message: (() -> String)?) {
|
||||
Assert.assertNotEquals(message?.invoke(), expected, actual)
|
||||
}
|
||||
|
||||
override fun assertTrue(value: Boolean, message: (() -> String)?) {
|
||||
Assert.assertTrue(message?.invoke(), value)
|
||||
}
|
||||
|
||||
override fun assertFalse(value: Boolean, message: (() -> String)?) {
|
||||
Assert.assertFalse(message?.invoke(), value)
|
||||
}
|
||||
|
||||
override fun assertNotNull(value: Any?, message: (() -> String)?) {
|
||||
Assert.assertNotNull(message?.invoke(), value)
|
||||
}
|
||||
|
||||
override fun <T> assertSameElements(expected: Collection<T>, actual: Collection<T>, message: (() -> String)?) {
|
||||
KtUsefulTestCase.assertSameElements(message?.invoke() ?: "", expected, actual)
|
||||
}
|
||||
|
||||
override fun assertAll(exceptions: List<AssertionError>) {
|
||||
exceptions.forEach { throw it }
|
||||
}
|
||||
|
||||
override fun fail(message: () -> String): Nothing {
|
||||
throw AssertionError(message.invoke())
|
||||
}
|
||||
}
|
||||
+54
@@ -0,0 +1,54 @@
|
||||
/*
|
||||
* Copyright 2010-2016 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.test.util;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor;
|
||||
import org.jetbrains.kotlin.test.Assertions;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
public class RecursiveDescriptorComparatorAdaptor {
|
||||
private static final Assertions assertions = JUnit4Assertions.INSTANCE;
|
||||
|
||||
public static void compareDescriptors(
|
||||
@NotNull DeclarationDescriptor expected,
|
||||
@NotNull DeclarationDescriptor actual,
|
||||
@NotNull RecursiveDescriptorComparator.Configuration configuration,
|
||||
@Nullable File txtFile
|
||||
) {
|
||||
RecursiveDescriptorComparator.compareDescriptors(expected, actual, configuration, txtFile, assertions);
|
||||
}
|
||||
|
||||
public static void validateAndCompareDescriptorWithFile(
|
||||
@NotNull DeclarationDescriptor actual,
|
||||
@NotNull RecursiveDescriptorComparator.Configuration configuration,
|
||||
@NotNull File txtFile
|
||||
) {
|
||||
RecursiveDescriptorComparator.validateAndCompareDescriptorWithFile(actual, configuration, txtFile, assertions);
|
||||
}
|
||||
|
||||
public static void validateAndCompareDescriptors(
|
||||
@NotNull DeclarationDescriptor expected,
|
||||
@NotNull DeclarationDescriptor actual,
|
||||
@NotNull RecursiveDescriptorComparator.Configuration configuration,
|
||||
@Nullable File txtFile
|
||||
) {
|
||||
RecursiveDescriptorComparator.validateAndCompareDescriptors(expected, actual, configuration, txtFile, assertions);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
|
||||
plugins {
|
||||
kotlin("jvm")
|
||||
id("jps-compatible")
|
||||
}
|
||||
|
||||
dependencies {
|
||||
testCompile(kotlinStdlib("jdk8"))
|
||||
testCompile(project(":kotlin-scripting-compiler"))
|
||||
testCompile(project(":core:descriptors"))
|
||||
testCompile(project(":core:descriptors.jvm"))
|
||||
testCompile(project(":core:deserialization"))
|
||||
testCompile(project(":compiler:util"))
|
||||
testCompile(project(":compiler:tests-mutes"))
|
||||
testCompile(project(":compiler:backend"))
|
||||
testCompile(project(":compiler:ir.ir2cfg"))
|
||||
testCompile(project(":compiler:frontend"))
|
||||
testCompile(project(":compiler:frontend.java"))
|
||||
testCompile(project(":compiler:util"))
|
||||
testCompile(project(":compiler:psi"))
|
||||
testCompile(project(":compiler:cli-common"))
|
||||
testCompile(project(":compiler:cli"))
|
||||
testCompile(project(":compiler:cli-js"))
|
||||
testCompile(project(":compiler:serialization"))
|
||||
testCompile(projectTests(":compiler:test-infrastructure-utils"))
|
||||
testCompileOnly(intellijCoreDep()) { includeJars("intellij-core") }
|
||||
|
||||
testCompile(intellijDep()) {
|
||||
includeJars(
|
||||
"jps-model",
|
||||
"extensions",
|
||||
"util",
|
||||
"platform-api",
|
||||
"platform-impl",
|
||||
"idea",
|
||||
"idea_rt",
|
||||
"guava",
|
||||
"trove4j",
|
||||
"asm-all",
|
||||
"log4j",
|
||||
"jdom",
|
||||
"streamex",
|
||||
"bootstrap",
|
||||
rootProject = rootProject
|
||||
)
|
||||
isTransitive = false
|
||||
}
|
||||
}
|
||||
|
||||
sourceSets {
|
||||
"main" { none() }
|
||||
"test" { projectDefault() }
|
||||
}
|
||||
|
||||
testsJar {}
|
||||
+67
@@ -0,0 +1,67 @@
|
||||
/*
|
||||
* Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.fir
|
||||
|
||||
import org.jetbrains.kotlin.fir.references.FirControlFlowGraphReference
|
||||
import org.jetbrains.kotlin.fir.resolve.dfa.FirControlFlowGraphReferenceImpl
|
||||
import org.jetbrains.kotlin.fir.resolve.dfa.cfg.CFGNode
|
||||
import org.jetbrains.kotlin.fir.resolve.dfa.cfg.ControlFlowGraph
|
||||
import org.jetbrains.kotlin.fir.resolve.dfa.cfg.EdgeKind
|
||||
import org.jetbrains.kotlin.fir.visitors.FirVisitorVoid
|
||||
import org.jetbrains.kotlin.test.Assertions
|
||||
|
||||
class FirCfgConsistencyChecker(private val assertions: Assertions) : FirVisitorVoid() {
|
||||
override fun visitElement(element: FirElement) {
|
||||
element.acceptChildren(this)
|
||||
}
|
||||
|
||||
override fun visitControlFlowGraphReference(controlFlowGraphReference: FirControlFlowGraphReference) {
|
||||
val graph = (controlFlowGraphReference as? FirControlFlowGraphReferenceImpl)?.controlFlowGraph ?: return
|
||||
assertions.assertEquals(ControlFlowGraph.State.Completed, graph.state)
|
||||
checkConsistency(graph)
|
||||
checkOrder(graph)
|
||||
}
|
||||
|
||||
private fun checkConsistency(graph: ControlFlowGraph) {
|
||||
for (node in graph.nodes) {
|
||||
for (to in node.followingNodes) {
|
||||
checkEdge(node, to)
|
||||
}
|
||||
for (from in node.previousNodes) {
|
||||
checkEdge(from, node)
|
||||
}
|
||||
if (node.followingNodes.isEmpty() && node.previousNodes.isEmpty()) {
|
||||
throw AssertionError("Unconnected CFG node: $node")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private val cfgKinds = listOf(EdgeKind.DeadForward, EdgeKind.CfgForward, EdgeKind.DeadBackward, EdgeKind.CfgBackward)
|
||||
|
||||
private fun checkEdge(from: CFGNode<*>, to: CFGNode<*>) {
|
||||
assertions.assertContainsElements(from.followingNodes, to)
|
||||
assertions.assertContainsElements(to.previousNodes, from)
|
||||
val fromKind = from.outgoingEdges.getValue(to).kind
|
||||
val toKind = to.incomingEdges.getValue(from).kind
|
||||
assertions.assertEquals(fromKind, toKind)
|
||||
if (from.isDead && to.isDead) {
|
||||
assertions.assertContainsElements(cfgKinds, toKind)
|
||||
}
|
||||
}
|
||||
|
||||
private fun checkOrder(graph: ControlFlowGraph) {
|
||||
val visited = mutableSetOf<CFGNode<*>>()
|
||||
for (node in graph.nodes) {
|
||||
for (previousNode in node.previousNodes) {
|
||||
if (previousNode.owner != graph) continue
|
||||
if (!node.incomingEdges.getValue(previousNode).kind.isBack) {
|
||||
assertions.assertTrue(previousNode in visited)
|
||||
}
|
||||
}
|
||||
visited += node
|
||||
}
|
||||
}
|
||||
}
|
||||
+8
-20
@@ -1,17 +1,6 @@
|
||||
/*
|
||||
* Copyright 2010-2015 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
* Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.jvm.compiler;
|
||||
@@ -27,18 +16,17 @@ import org.jetbrains.kotlin.resolve.DescriptorUtils;
|
||||
import org.jetbrains.kotlin.resolve.constants.ConstantValue;
|
||||
import org.jetbrains.kotlin.resolve.jvm.JvmBindingContextSlices;
|
||||
import org.jetbrains.kotlin.resolve.scopes.MemberScope;
|
||||
import org.jetbrains.kotlin.test.Assertions;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
import static org.jetbrains.kotlin.test.testFramework.KtUsefulTestCase.assertNotNull;
|
||||
import static org.jetbrains.kotlin.test.testFramework.KtUsefulTestCase.assertSameElements;
|
||||
|
||||
public class ExpectedLoadErrorsUtil {
|
||||
public static final String ANNOTATION_CLASS_NAME = "org.jetbrains.kotlin.jvm.compiler.annotation.ExpectLoadError";
|
||||
|
||||
public static void checkForLoadErrors(
|
||||
@NotNull PackageViewDescriptor packageFromJava,
|
||||
@NotNull BindingContext bindingContext
|
||||
@NotNull BindingContext bindingContext,
|
||||
@NotNull Assertions assertions
|
||||
) {
|
||||
Map<SourceElement, List<String>> expectedErrors = getExpectedLoadErrors(packageFromJava);
|
||||
Map<SourceElement, List<String>> actualErrors = getActualLoadErrors(bindingContext);
|
||||
@@ -47,10 +35,10 @@ public class ExpectedLoadErrorsUtil {
|
||||
List<String> actual = actualErrors.get(source);
|
||||
List<String> expected = expectedErrors.get(source);
|
||||
|
||||
assertNotNull("Unexpected load error(s):\n" + actual + "\ncontainer:" + source, expected);
|
||||
assertNotNull("Missing load error(s):\n" + expected + "\ncontainer:" + source, actual);
|
||||
assertions.assertNotNull(expected, () -> "Unexpected load error(s):\n" + actual + "\ncontainer:" + source);
|
||||
assertions.assertNotNull(actual, () -> "Missing load error(s):\n" + expected + "\ncontainer:" + source);
|
||||
|
||||
assertSameElements("Unexpected/missing load error(s)\ncontainer:" + source, actual, expected);
|
||||
assertions.assertSameElements(actual, expected, () -> "Unexpected/missing load error(s)\ncontainer:" + source);
|
||||
}
|
||||
}
|
||||
|
||||
+3
-15
@@ -1,17 +1,6 @@
|
||||
/*
|
||||
* Copyright 2010-2015 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
* Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.test.util;
|
||||
@@ -26,7 +15,6 @@ import org.jetbrains.kotlin.resolve.DescriptorUtils;
|
||||
import org.jetbrains.kotlin.resolve.scopes.MemberScope;
|
||||
import org.jetbrains.kotlin.types.KotlinType;
|
||||
import org.jetbrains.kotlin.types.KotlinTypeKt;
|
||||
import org.junit.Assert;
|
||||
|
||||
import java.io.PrintStream;
|
||||
import java.util.Collection;
|
||||
@@ -563,7 +551,7 @@ public class DescriptorValidator {
|
||||
|
||||
public void done() {
|
||||
if (errorsFound) {
|
||||
Assert.fail("Descriptor validation failed (see messages above)");
|
||||
throw new AssertionError("Descriptor validation failed (see messages above)");
|
||||
}
|
||||
}
|
||||
}
|
||||
+19
-26
@@ -1,17 +1,6 @@
|
||||
/*
|
||||
* Copyright 2010-2016 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
* Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.test.util;
|
||||
@@ -36,9 +25,8 @@ import org.jetbrains.kotlin.resolve.DescriptorUtils;
|
||||
import org.jetbrains.kotlin.resolve.MemberComparator;
|
||||
import org.jetbrains.kotlin.resolve.scopes.ChainedMemberScope;
|
||||
import org.jetbrains.kotlin.resolve.scopes.MemberScope;
|
||||
import org.jetbrains.kotlin.test.KotlinTestUtils;
|
||||
import org.jetbrains.kotlin.test.Assertions;
|
||||
import org.jetbrains.kotlin.utils.Printer;
|
||||
import org.junit.Assert;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
@@ -300,49 +288,54 @@ public class RecursiveDescriptorComparator {
|
||||
private static void compareDescriptorWithFile(
|
||||
@NotNull DeclarationDescriptor actual,
|
||||
@NotNull Configuration configuration,
|
||||
@NotNull File txtFile
|
||||
@NotNull File txtFile,
|
||||
@NotNull Assertions assertions
|
||||
) {
|
||||
doCompareDescriptors(null, actual, configuration, txtFile);
|
||||
doCompareDescriptors(null, actual, configuration, txtFile, assertions);
|
||||
}
|
||||
|
||||
public static void compareDescriptors(
|
||||
@NotNull DeclarationDescriptor expected,
|
||||
@NotNull DeclarationDescriptor actual,
|
||||
@NotNull Configuration configuration,
|
||||
@Nullable File txtFile
|
||||
@Nullable File txtFile,
|
||||
@NotNull Assertions assertions
|
||||
) {
|
||||
if (expected == actual) {
|
||||
throw new IllegalArgumentException("Don't invoke this method with expected == actual." +
|
||||
"Invoke compareDescriptorWithFile() instead.");
|
||||
}
|
||||
doCompareDescriptors(expected, actual, configuration, txtFile);
|
||||
doCompareDescriptors(expected, actual, configuration, txtFile, assertions);
|
||||
}
|
||||
|
||||
public static void validateAndCompareDescriptorWithFile(
|
||||
@NotNull DeclarationDescriptor actual,
|
||||
@NotNull Configuration configuration,
|
||||
@NotNull File txtFile
|
||||
@NotNull File txtFile,
|
||||
@NotNull Assertions assertions
|
||||
) {
|
||||
DescriptorValidator.validate(configuration.validationStrategy, actual);
|
||||
compareDescriptorWithFile(actual, configuration, txtFile);
|
||||
compareDescriptorWithFile(actual, configuration, txtFile, assertions);
|
||||
}
|
||||
|
||||
public static void validateAndCompareDescriptors(
|
||||
@NotNull DeclarationDescriptor expected,
|
||||
@NotNull DeclarationDescriptor actual,
|
||||
@NotNull Configuration configuration,
|
||||
@Nullable File txtFile
|
||||
@Nullable File txtFile,
|
||||
@NotNull Assertions assertions
|
||||
) {
|
||||
DescriptorValidator.validate(configuration.validationStrategy, expected);
|
||||
DescriptorValidator.validate(configuration.validationStrategy, actual);
|
||||
compareDescriptors(expected, actual, configuration, txtFile);
|
||||
compareDescriptors(expected, actual, configuration, txtFile, assertions);
|
||||
}
|
||||
|
||||
private static void doCompareDescriptors(
|
||||
@Nullable DeclarationDescriptor expected,
|
||||
@NotNull DeclarationDescriptor actual,
|
||||
@NotNull Configuration configuration,
|
||||
@Nullable File txtFile
|
||||
@Nullable File txtFile,
|
||||
@NotNull Assertions assertions
|
||||
) {
|
||||
RecursiveDescriptorComparator comparator = new RecursiveDescriptorComparator(configuration);
|
||||
|
||||
@@ -351,11 +344,11 @@ public class RecursiveDescriptorComparator {
|
||||
if (expected != null) {
|
||||
String expectedSerialized = comparator.serializeRecursively(expected);
|
||||
|
||||
Assert.assertEquals("Expected and actual descriptors differ", expectedSerialized, actualSerialized);
|
||||
assertions.assertEquals(expectedSerialized, actualSerialized, () -> "Expected and actual descriptors differ");
|
||||
}
|
||||
|
||||
if (txtFile != null) {
|
||||
KotlinTestUtils.assertEqualsToFile(txtFile, actualSerialized);
|
||||
assertions.assertEqualsToFile(txtFile, actualSerialized, (s) -> s);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -107,7 +107,7 @@ class ReplCompilerJava8Test : KtUsefulTestCase() {
|
||||
}
|
||||
|
||||
private fun makeConfiguration() = KotlinTestUtils.newConfiguration(
|
||||
ConfigurationKind.ALL, TestJdkKind.FULL_JDK, File(KotlinIntegrationTestBase.getCompilerLib(), "kotlin-stdlib.jar"), tmpdir
|
||||
ConfigurationKind.ALL, TestJdkKind.FULL_JDK, File(KotlinIntegrationTestBase.getCompilerLib(), "kotlin-stdlib.jar"), tmpdir
|
||||
).also {
|
||||
loadScriptingPlugin(it)
|
||||
}
|
||||
|
||||
@@ -186,7 +186,7 @@ class KotlinCliJavaFileManagerTest : KotlinTestWithEnvironment() {
|
||||
javaFilesDir = KtTestUtil.tmpDir("java-file-manager-test")
|
||||
|
||||
val configuration = KotlinTestUtils.newConfiguration(
|
||||
ConfigurationKind.JDK_ONLY, TestJdkKind.MOCK_JDK, emptyList(), listOf(javaFilesDir)
|
||||
ConfigurationKind.JDK_ONLY, TestJdkKind.MOCK_JDK, emptyList(), listOf(javaFilesDir)
|
||||
)
|
||||
|
||||
return KotlinCoreEnvironment.createForTests(testRootDisposable, configuration, EnvironmentConfigFiles.JVM_CONFIG_FILES)
|
||||
|
||||
+1
-1
@@ -38,7 +38,7 @@ import org.jetbrains.kotlin.test.ConfigurationKind
|
||||
import org.jetbrains.kotlin.test.KotlinTestUtils
|
||||
import org.jetbrains.kotlin.test.MockLibraryUtil
|
||||
import org.jetbrains.kotlin.test.TestJdkKind
|
||||
import org.jetbrains.kotlin.test.util.RecursiveDescriptorComparator.validateAndCompareDescriptorWithFile
|
||||
import org.jetbrains.kotlin.test.util.RecursiveDescriptorComparatorAdaptor.validateAndCompareDescriptorWithFile
|
||||
import org.jetbrains.kotlin.utils.PathUtil
|
||||
import org.jetbrains.org.objectweb.asm.*
|
||||
import org.jetbrains.org.objectweb.asm.tree.AbstractInsnNode
|
||||
|
||||
@@ -68,9 +68,9 @@ class KotlinClassFinderTest : KotlinTestWithEnvironmentManagement() {
|
||||
|
||||
private fun createEnvironment(tmpdir: File?): KotlinCoreEnvironment {
|
||||
return KotlinCoreEnvironment.createForTests(
|
||||
testRootDisposable,
|
||||
KotlinTestUtils.newConfiguration(ConfigurationKind.ALL, TestJdkKind.MOCK_JDK, tmpdir),
|
||||
EnvironmentConfigFiles.JVM_CONFIG_FILES
|
||||
testRootDisposable,
|
||||
KotlinTestUtils.newConfiguration(ConfigurationKind.ALL, TestJdkKind.MOCK_JDK, tmpdir),
|
||||
EnvironmentConfigFiles.JVM_CONFIG_FILES
|
||||
).apply {
|
||||
// Activate Kotlin light class finder
|
||||
JvmResolveUtil.analyze(this)
|
||||
|
||||
@@ -90,9 +90,9 @@ class KotlinJavacBasedClassFinderTest : KotlinTestWithEnvironmentManagement() {
|
||||
|
||||
private fun createEnvironment(tmpdir: File?, files: List<File> = emptyList()): KotlinCoreEnvironment {
|
||||
return KotlinCoreEnvironment.createForTests(
|
||||
testRootDisposable,
|
||||
KotlinTestUtils.newConfiguration(ConfigurationKind.ALL, TestJdkKind.MOCK_JDK, tmpdir),
|
||||
EnvironmentConfigFiles.JVM_CONFIG_FILES
|
||||
testRootDisposable,
|
||||
KotlinTestUtils.newConfiguration(ConfigurationKind.ALL, TestJdkKind.MOCK_JDK, tmpdir),
|
||||
EnvironmentConfigFiles.JVM_CONFIG_FILES
|
||||
).apply {
|
||||
registerJavac(files)
|
||||
// Activate Kotlin light class finder
|
||||
|
||||
@@ -72,7 +72,7 @@ class MemoryOptimizationsTest : KtUsefulTestCase() {
|
||||
val environment =
|
||||
KotlinTestUtils
|
||||
.createEnvironmentWithJdkAndNullabilityAnnotationsFromIdea(
|
||||
testRootDisposable, ConfigurationKind.ALL, TestJdkKind.FULL_JDK
|
||||
testRootDisposable, ConfigurationKind.ALL, TestJdkKind.FULL_JDK
|
||||
)
|
||||
val moduleDescriptor =
|
||||
JvmResolveUtil.analyze(
|
||||
|
||||
+3
-3
@@ -87,15 +87,15 @@ class TypeQualifierAnnotationResolverTest : KtUsefulTestCase() {
|
||||
|
||||
private fun buildTypeQualifierResolverAndFindClass(className: String): Pair<AnnotationTypeQualifierResolver, ClassDescriptor> {
|
||||
val configuration = KotlinTestUtils.newConfiguration(
|
||||
ConfigurationKind.ALL, TestJdkKind.FULL_JDK,
|
||||
listOf(
|
||||
ConfigurationKind.ALL, TestJdkKind.FULL_JDK,
|
||||
listOf(
|
||||
KtTestUtil.getAnnotationsJar(),
|
||||
MockLibraryUtil.compileJavaFilesLibraryToJar(
|
||||
FOREIGN_ANNOTATIONS_SOURCES_PATH,
|
||||
"foreign-annotations"
|
||||
)
|
||||
),
|
||||
listOf(File(TEST_DATA_PATH))
|
||||
listOf(File(TEST_DATA_PATH))
|
||||
).apply {
|
||||
languageVersionSettings = LanguageVersionSettingsImpl(
|
||||
LanguageVersion.LATEST_STABLE, ApiVersion.LATEST_STABLE, mapOf(JvmAnalysisFlags.javaTypeEnhancementState to JavaTypeEnhancementState.STRICT)
|
||||
|
||||
+5
-4
@@ -26,6 +26,7 @@ import org.jetbrains.kotlin.storage.LockBasedStorageManager
|
||||
import org.jetbrains.kotlin.test.KotlinTestUtils
|
||||
import org.jetbrains.kotlin.test.TestCaseWithTmpdir
|
||||
import org.jetbrains.kotlin.test.util.RecursiveDescriptorComparator
|
||||
import org.jetbrains.kotlin.test.util.RecursiveDescriptorComparatorAdaptor
|
||||
import java.io.File
|
||||
import java.io.FileInputStream
|
||||
|
||||
@@ -56,10 +57,10 @@ class BuiltInsSerializerTest : TestCaseWithTmpdir() {
|
||||
module.initialize(packageFragmentProvider)
|
||||
module.setDependencies(module, module.builtIns.builtInsModule)
|
||||
|
||||
RecursiveDescriptorComparator.validateAndCompareDescriptorWithFile(
|
||||
module.getPackage(TEST_PACKAGE_FQNAME),
|
||||
RecursiveDescriptorComparator.DONT_INCLUDE_METHODS_OF_OBJECT,
|
||||
File(source.replace(".kt", ".txt"))
|
||||
RecursiveDescriptorComparatorAdaptor.validateAndCompareDescriptorWithFile(
|
||||
module.getPackage(TEST_PACKAGE_FQNAME),
|
||||
RecursiveDescriptorComparator.DONT_INCLUDE_METHODS_OF_OBJECT,
|
||||
File(source.replace(".kt", ".txt"))
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
@@ -37,7 +37,7 @@ import org.jetbrains.kotlin.storage.LockBasedStorageManager;
|
||||
import org.jetbrains.kotlin.test.ConfigurationKind;
|
||||
import org.jetbrains.kotlin.test.KotlinTestWithEnvironment;
|
||||
import org.jetbrains.kotlin.test.TestJdkKind;
|
||||
import org.jetbrains.kotlin.test.util.RecursiveDescriptorComparator;
|
||||
import org.jetbrains.kotlin.test.util.RecursiveDescriptorComparatorAdaptor;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Collections;
|
||||
@@ -61,7 +61,7 @@ public class LoadBuiltinsTest extends KotlinTestWithEnvironment {
|
||||
if (fromLazyResolve instanceof LazyPackageDescriptor) {
|
||||
PackageFragmentDescriptor deserialized =
|
||||
CollectionsKt.single(PackageFragmentProviderKt.packageFragments(packageFragmentProvider, packageFqName));
|
||||
RecursiveDescriptorComparator.validateAndCompareDescriptors(
|
||||
RecursiveDescriptorComparatorAdaptor.validateAndCompareDescriptors(
|
||||
fromLazyResolve, deserialized, AbstractBuiltInsWithJDKMembersTest.createComparatorConfiguration(),
|
||||
new File("compiler/testData/builtin-classes/default/" + packageFqName.asString().replace('.', '-') + ".txt")
|
||||
);
|
||||
|
||||
+5
-4
@@ -39,6 +39,7 @@ import org.jetbrains.kotlin.storage.LockBasedStorageManager
|
||||
import org.jetbrains.kotlin.test.KotlinTestUtils
|
||||
import org.jetbrains.kotlin.test.TestCaseWithTmpdir
|
||||
import org.jetbrains.kotlin.test.util.RecursiveDescriptorComparator
|
||||
import org.jetbrains.kotlin.test.util.RecursiveDescriptorComparatorAdaptor
|
||||
import org.jetbrains.kotlin.utils.JsMetadataVersion
|
||||
import org.jetbrains.kotlin.utils.KotlinJavascriptMetadataUtils
|
||||
import org.jetbrains.kotlin.utils.sure
|
||||
@@ -62,10 +63,10 @@ class KotlinJavascriptSerializerTest : TestCaseWithTmpdir() {
|
||||
serialize(configuration, metaFile)
|
||||
val module = deserialize(metaFile)
|
||||
|
||||
RecursiveDescriptorComparator.validateAndCompareDescriptorWithFile(
|
||||
module.getPackage(TEST_PACKAGE_FQNAME),
|
||||
RecursiveDescriptorComparator.DONT_INCLUDE_METHODS_OF_OBJECT,
|
||||
File(source.replace(".kt", ".txt"))
|
||||
RecursiveDescriptorComparatorAdaptor.validateAndCompareDescriptorWithFile(
|
||||
module.getPackage(TEST_PACKAGE_FQNAME),
|
||||
RecursiveDescriptorComparator.DONT_INCLUDE_METHODS_OF_OBJECT,
|
||||
File(source.replace(".kt", ".txt"))
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
+3
-3
@@ -34,7 +34,7 @@ import org.jetbrains.kotlin.test.*
|
||||
import org.jetbrains.kotlin.test.TestFiles.TestFileFactoryNoModules
|
||||
import org.jetbrains.kotlin.test.util.DescriptorValidator.ValidationVisitor.errorTypesForbidden
|
||||
import org.jetbrains.kotlin.test.util.KtTestUtil
|
||||
import org.jetbrains.kotlin.test.util.RecursiveDescriptorComparator
|
||||
import org.jetbrains.kotlin.test.util.RecursiveDescriptorComparatorAdaptor
|
||||
import org.jetbrains.kotlin.test.util.RecursiveDescriptorComparator.Configuration
|
||||
import org.jetbrains.kotlin.utils.Printer
|
||||
import org.jetbrains.kotlin.utils.sure
|
||||
@@ -94,7 +94,7 @@ abstract class AbstractJvmRuntimeDescriptorLoaderTest : TestCaseWithTmpdir() {
|
||||
|
||||
val differentResultFile = KotlinTestUtils.replaceExtension(file, "runtime.txt")
|
||||
if (differentResultFile.exists()) {
|
||||
RecursiveDescriptorComparator.validateAndCompareDescriptorWithFile(actual, comparatorConfiguration, differentResultFile)
|
||||
RecursiveDescriptorComparatorAdaptor.validateAndCompareDescriptorWithFile(actual, comparatorConfiguration, differentResultFile)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -102,7 +102,7 @@ abstract class AbstractJvmRuntimeDescriptorLoaderTest : TestCaseWithTmpdir() {
|
||||
tmpdir, testRootDisposable, jdkKind, ConfigurationKind.ALL, true, false, false, null
|
||||
).first
|
||||
|
||||
RecursiveDescriptorComparator.validateAndCompareDescriptors(expected, actual, comparatorConfiguration, null)
|
||||
RecursiveDescriptorComparatorAdaptor.validateAndCompareDescriptors(expected, actual, comparatorConfiguration, null)
|
||||
}
|
||||
|
||||
private fun DeclarationDescriptor.isJavaAnnotationConstructor() =
|
||||
|
||||
@@ -17,6 +17,7 @@ import org.jetbrains.kotlin.psi.KtFile
|
||||
import org.jetbrains.kotlin.test.InTextDirectivesUtils
|
||||
import org.jetbrains.kotlin.test.util.DescriptorValidator.ValidationVisitor.errorTypesForbidden
|
||||
import org.jetbrains.kotlin.test.util.RecursiveDescriptorComparator
|
||||
import org.jetbrains.kotlin.test.util.RecursiveDescriptorComparatorAdaptor
|
||||
import org.junit.Assert
|
||||
import java.io.File
|
||||
|
||||
@@ -46,7 +47,7 @@ abstract class AbstractResolveByStubTest : KotlinLightCodeInsightFixtureTestCase
|
||||
|
||||
val fileToCompareTo = File(FileUtil.getNameWithoutExtension(path) + ".txt")
|
||||
|
||||
RecursiveDescriptorComparator.validateAndCompareDescriptorWithFile(
|
||||
RecursiveDescriptorComparatorAdaptor.validateAndCompareDescriptorWithFile(
|
||||
packageViewDescriptor,
|
||||
RecursiveDescriptorComparator.DONT_INCLUDE_METHODS_OF_OBJECT
|
||||
.filterRecursion(RecursiveDescriptorComparator.SKIP_BUILT_INS_PACKAGES)
|
||||
|
||||
@@ -115,6 +115,7 @@ include ":benchmarks",
|
||||
":compiler:cli-js-klib",
|
||||
":compiler:incremental-compilation-impl",
|
||||
":compiler:android-tests",
|
||||
":compiler:tests-compiler-utils",
|
||||
":compiler:tests-common",
|
||||
":compiler:tests-mutes",
|
||||
":compiler:tests-mutes:tc-integration",
|
||||
|
||||
Reference in New Issue
Block a user