[Test] Migrate IrTextTestGenerated to new infrastructure
This commit is contained in:
committed by
TeamCityServer
parent
5ae5f660f6
commit
aaa3fa5845
Generated
+2721
File diff suppressed because it is too large
Load Diff
+9
-4
@@ -23,7 +23,6 @@ import org.jetbrains.kotlin.test.services.jvm.compiledClassesManager
|
||||
import org.jetbrains.kotlin.test.services.sourceFileProvider
|
||||
import org.jetbrains.kotlin.test.util.KtTestUtil
|
||||
import java.io.File
|
||||
import java.nio.file.Paths
|
||||
|
||||
class JavaCompilerFacade(private val testServices: TestServices) {
|
||||
@OptIn(ExperimentalStdlibApi::class)
|
||||
@@ -51,7 +50,8 @@ class JavaCompilerFacade(private val testServices: TestServices) {
|
||||
)
|
||||
|
||||
val javaFiles = module.javaFiles.map { testServices.sourceFileProvider.getRealFileForSourceFile(it) }
|
||||
compileJavaFiles(configuration[JVMConfigurationKeys.JVM_TARGET] ?: JvmTarget.DEFAULT, javaFiles, finalJavacOptions)
|
||||
val ignoreErrors = CodegenTestDirectives.IGNORE_JAVA_ERRORS in module.directives
|
||||
compileJavaFiles(configuration[JVMConfigurationKeys.JVM_TARGET] ?: JvmTarget.DEFAULT, javaFiles, finalJavacOptions, ignoreErrors)
|
||||
}
|
||||
|
||||
@OptIn(ExperimentalStdlibApi::class)
|
||||
@@ -73,10 +73,15 @@ class JavaCompilerFacade(private val testServices: TestServices) {
|
||||
}
|
||||
}
|
||||
|
||||
private fun compileJavaFiles(jvmTarget: JvmTarget, files: List<File>, javacOptions: List<String>) {
|
||||
private fun compileJavaFiles(jvmTarget: JvmTarget, files: List<File>, javacOptions: List<String>, ignoreErrors: Boolean) {
|
||||
val targetIsJava8OrLower = System.getProperty("java.version").startsWith("1.")
|
||||
if (targetIsJava8OrLower) {
|
||||
org.jetbrains.kotlin.test.compileJavaFiles(files, javacOptions, assertions = testServices.assertions)
|
||||
org.jetbrains.kotlin.test.compileJavaFiles(
|
||||
files,
|
||||
javacOptions,
|
||||
assertions = testServices.assertions,
|
||||
ignoreJavaErrors = ignoreErrors
|
||||
)
|
||||
return
|
||||
}
|
||||
val jdkHome = when (jvmTarget) {
|
||||
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
/*
|
||||
* Copyright 2010-2021 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.backend.handlers
|
||||
|
||||
import org.jetbrains.kotlin.test.backend.ir.IrBackendInput
|
||||
import org.jetbrains.kotlin.test.model.BackendInputHandler
|
||||
import org.jetbrains.kotlin.test.model.BackendKinds
|
||||
import org.jetbrains.kotlin.test.services.TestServices
|
||||
|
||||
abstract class AbstractIrHandler(testServices: TestServices) : BackendInputHandler<IrBackendInput>(testServices, BackendKinds.IrBackend)
|
||||
+116
@@ -0,0 +1,116 @@
|
||||
/*
|
||||
* Copyright 2010-2021 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.backend.handlers
|
||||
|
||||
import org.jetbrains.kotlin.backend.common.serialization.signature.IdSignatureDescriptor
|
||||
import org.jetbrains.kotlin.config.languageVersionSettings
|
||||
import org.jetbrains.kotlin.descriptors.ModuleDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.findClassAcrossModuleDependencies
|
||||
import org.jetbrains.kotlin.ir.IrVerifier
|
||||
import org.jetbrains.kotlin.ir.backend.js.lower.serialization.ir.JsManglerDesc
|
||||
import org.jetbrains.kotlin.ir.declarations.IrClass
|
||||
import org.jetbrains.kotlin.ir.declarations.IrFile
|
||||
import org.jetbrains.kotlin.ir.declarations.impl.IrFactoryImpl
|
||||
import org.jetbrains.kotlin.ir.util.*
|
||||
import org.jetbrains.kotlin.name.ClassId
|
||||
import org.jetbrains.kotlin.name.FqName
|
||||
import org.jetbrains.kotlin.test.backend.ir.IrBackendInput
|
||||
import org.jetbrains.kotlin.test.directives.CodegenTestDirectives
|
||||
import org.jetbrains.kotlin.test.directives.CodegenTestDirectives.DUMP_EXTERNAL_CLASS
|
||||
import org.jetbrains.kotlin.test.directives.CodegenTestDirectives.DUMP_IR
|
||||
import org.jetbrains.kotlin.test.directives.CodegenTestDirectives.EXTERNAL_FILE
|
||||
import org.jetbrains.kotlin.test.directives.FirDiagnosticsDirectives
|
||||
import org.jetbrains.kotlin.test.directives.FirDiagnosticsDirectives.FIR_IDENTICAL
|
||||
import org.jetbrains.kotlin.test.directives.model.DirectivesContainer
|
||||
import org.jetbrains.kotlin.test.model.FrontendKinds
|
||||
import org.jetbrains.kotlin.test.model.TestModule
|
||||
import org.jetbrains.kotlin.test.services.TestServices
|
||||
import org.jetbrains.kotlin.test.services.moduleStructure
|
||||
import org.jetbrains.kotlin.test.utils.MultiModuleInfoDumperImpl
|
||||
import org.jetbrains.kotlin.test.utils.withExtension
|
||||
import org.jetbrains.kotlin.test.utils.withSuffixAndExtension
|
||||
import java.io.File
|
||||
|
||||
class IrTextDumpHandler(testServices: TestServices) : AbstractIrHandler(testServices) {
|
||||
override val directivesContainers: List<DirectivesContainer>
|
||||
get() = listOf(CodegenTestDirectives, FirDiagnosticsDirectives)
|
||||
|
||||
private val baseDumper = MultiModuleInfoDumperImpl()
|
||||
private val buildersForSeparateFileDumps: MutableMap<File, StringBuilder> = mutableMapOf()
|
||||
|
||||
@OptIn(ExperimentalStdlibApi::class)
|
||||
override fun processModule(module: TestModule, info: IrBackendInput) {
|
||||
if (DUMP_IR !in module.directives) return
|
||||
val irFiles = info.backendInput.irModuleFragment.files
|
||||
val testFileToIrFile = irFiles.mapNotNull { irFile ->
|
||||
val name = irFile.fileEntry.name.removePrefix("/")
|
||||
val testFile = module.files.firstOrNull { it.name == name } ?: return@mapNotNull null
|
||||
testFile to irFile
|
||||
}
|
||||
val builder = baseDumper.builderForModule(module)
|
||||
for ((testFile, irFile) in testFileToIrFile) {
|
||||
if (EXTERNAL_FILE in testFile.directives) continue
|
||||
val actualDump = irFile.dumpTreesFromLineNumber(lineNumber = 0, normalizeNames = true)
|
||||
builder.append(actualDump)
|
||||
verify(irFile)
|
||||
|
||||
val irFileCopy = irFile.deepCopyWithSymbols()
|
||||
val dumpOfCopy = irFileCopy.dumpTreesFromLineNumber(lineNumber = 0, normalizeNames = true)
|
||||
assertions.assertEquals(actualDump, dumpOfCopy) { "IR dump mismatch after deep copy with symbols" }
|
||||
}
|
||||
compareDumpsOfExternalClasses(module, info)
|
||||
}
|
||||
|
||||
private fun compareDumpsOfExternalClasses(module: TestModule, info: IrBackendInput) {
|
||||
val externalClassFqns = module.directives[DUMP_EXTERNAL_CLASS]
|
||||
if (externalClassFqns.isEmpty()) return
|
||||
|
||||
// TODO: why JS one is used here in original AbstractIrTextTestCase?
|
||||
val mangler = JsManglerDesc
|
||||
val signaturer = IdSignatureDescriptor(mangler)
|
||||
val irModule = info.backendInput.irModuleFragment
|
||||
val stubGenerator = DeclarationStubGenerator(
|
||||
irModule.descriptor,
|
||||
SymbolTable(signaturer, IrFactoryImpl), // TODO
|
||||
module.languageVersionSettings
|
||||
)
|
||||
|
||||
val baseFile = testServices.moduleStructure.originalTestDataFiles.first()
|
||||
for (externalClassFqn in externalClassFqns) {
|
||||
val classDump = stubGenerator.generateExternalClass(irModule.descriptor, externalClassFqn).dump()
|
||||
val expectedFile = baseFile.withSuffixAndExtension("__$externalClassFqn", module.dumpExtension)
|
||||
assertions.assertEqualsToFile(expectedFile, classDump)
|
||||
}
|
||||
}
|
||||
|
||||
private fun DeclarationStubGenerator.generateExternalClass(descriptor: ModuleDescriptor, externalClassFqn: String): IrClass {
|
||||
val classDescriptor =
|
||||
descriptor.findClassAcrossModuleDependencies(ClassId.topLevel(FqName(externalClassFqn)))
|
||||
?: throw AssertionError("Can't find a class in external dependencies: $externalClassFqn")
|
||||
|
||||
return generateMemberStub(classDescriptor) as IrClass
|
||||
}
|
||||
|
||||
override fun processAfterAllModules(someAssertionWasFailed: Boolean) {
|
||||
val moduleStructure = testServices.moduleStructure
|
||||
val defaultExpectedFile = moduleStructure.originalTestDataFiles.first().withExtension(moduleStructure.modules.first().dumpExtension)
|
||||
checkOneExpectedFile(defaultExpectedFile, baseDumper.generateResultingDump())
|
||||
buildersForSeparateFileDumps.entries.forEach { (expectedFile, dump) -> checkOneExpectedFile(expectedFile, dump.toString()) }
|
||||
}
|
||||
|
||||
private fun checkOneExpectedFile(expectedFile: File, actualDump: String) {
|
||||
if (actualDump.isNotEmpty()) {
|
||||
assertions.assertEqualsToFile(expectedFile, actualDump)
|
||||
}
|
||||
}
|
||||
|
||||
private fun verify(irFile: IrFile) {
|
||||
IrVerifier(assertions).verifyWithAssert(irFile)
|
||||
}
|
||||
|
||||
private val TestModule.dumpExtension: String
|
||||
get() = if (frontendKind == FrontendKinds.ClassicFrontend || FIR_IDENTICAL in directives) "txt" else "fir.txt"
|
||||
}
|
||||
+8
-5
@@ -6,9 +6,9 @@
|
||||
package org.jetbrains.kotlin.test.directives
|
||||
|
||||
import org.jetbrains.kotlin.test.TargetBackend
|
||||
import org.jetbrains.kotlin.test.backend.handlers.IrTextDumpHandler
|
||||
import org.jetbrains.kotlin.test.backend.handlers.NoCompilationErrorsHandler
|
||||
import org.jetbrains.kotlin.test.backend.ir.JvmIrBackendFacade
|
||||
import org.jetbrains.kotlin.test.directives.model.DirectiveApplicability
|
||||
import org.jetbrains.kotlin.test.directives.model.DirectiveApplicability.File
|
||||
import org.jetbrains.kotlin.test.directives.model.DirectiveApplicability.Global
|
||||
import org.jetbrains.kotlin.test.directives.model.SimpleDirectivesContainer
|
||||
@@ -56,13 +56,16 @@ object CodegenTestDirectives : SimpleDirectivesContainer() {
|
||||
""".trimIndent()
|
||||
)
|
||||
|
||||
val IGNORE_JAVA_ERRORS by directive(
|
||||
description = "Ignore compilation errors from java"
|
||||
)
|
||||
|
||||
val IGNORE_FIR_DIAGNOSTICS by directive(
|
||||
description = "Run backend even FIR reported some diagnostics with ERROR severity"
|
||||
)
|
||||
|
||||
val IR_FILE by stringDirective(
|
||||
description = "Specifies file name for IR text dump",
|
||||
applicability = File
|
||||
val DUMP_IR by directive(
|
||||
description = "Dumps generated backend IR (enables ${IrTextDumpHandler::class})"
|
||||
)
|
||||
|
||||
val DUMP_EXTERNAL_CLASS by stringDirective(
|
||||
@@ -70,7 +73,7 @@ object CodegenTestDirectives : SimpleDirectivesContainer() {
|
||||
)
|
||||
|
||||
val EXTERNAL_FILE by directive(
|
||||
description = "Indicates that test file is external",
|
||||
description = "Indicates that test file is external and should be skipped in ${IrTextDumpHandler::class}",
|
||||
applicability = File
|
||||
)
|
||||
}
|
||||
|
||||
+9
-1
@@ -15,7 +15,15 @@ abstract class AbstractKotlinCompilerWithTargetBackendTest(
|
||||
super.configure(builder)
|
||||
with(builder) {
|
||||
globalDefaults {
|
||||
targetBackend = this@AbstractKotlinCompilerWithTargetBackendTest.targetBackend
|
||||
val targetBackendFromMarker = this@AbstractKotlinCompilerWithTargetBackendTest.targetBackend
|
||||
if (targetBackend == null) {
|
||||
targetBackend = this@AbstractKotlinCompilerWithTargetBackendTest.targetBackend
|
||||
} else {
|
||||
require(targetBackend == targetBackendFromMarker) {
|
||||
"""Target backend in configuration specified to $targetBackend but in
|
||||
|AbstractKotlinCompilerWithTargetBackendTest parent it is set to $targetBackendFromMarker""".trimMargin()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+66
@@ -0,0 +1,66 @@
|
||||
/*
|
||||
* Copyright 2010-2021 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.runners.ir
|
||||
|
||||
import org.jetbrains.kotlin.platform.jvm.JvmPlatforms
|
||||
import org.jetbrains.kotlin.test.TargetBackend
|
||||
import org.jetbrains.kotlin.test.backend.BlackBoxCodegenSuppressor
|
||||
import org.jetbrains.kotlin.test.backend.handlers.*
|
||||
import org.jetbrains.kotlin.test.builders.TestConfigurationBuilder
|
||||
import org.jetbrains.kotlin.test.directives.CodegenTestDirectives.DUMP_IR
|
||||
import org.jetbrains.kotlin.test.frontend.classic.ClassicFrontend2IrConverter
|
||||
import org.jetbrains.kotlin.test.frontend.classic.ClassicFrontendFacade
|
||||
import org.jetbrains.kotlin.test.frontend.fir.Fir2IrResultsConverter
|
||||
import org.jetbrains.kotlin.test.frontend.fir.FirFrontendFacade
|
||||
import org.jetbrains.kotlin.test.model.*
|
||||
import org.jetbrains.kotlin.test.runners.AbstractKotlinCompilerWithTargetBackendTest
|
||||
import org.jetbrains.kotlin.test.services.configuration.CommonEnvironmentConfigurator
|
||||
import org.jetbrains.kotlin.test.services.configuration.JvmEnvironmentConfigurator
|
||||
import org.jetbrains.kotlin.test.services.sourceProviders.AdditionalDiagnosticsSourceFilesProvider
|
||||
import org.jetbrains.kotlin.test.services.sourceProviders.CodegenHelpersSourceFilesProvider
|
||||
import org.jetbrains.kotlin.test.services.sourceProviders.CoroutineHelpersSourceFilesProvider
|
||||
|
||||
abstract class AbstractIrTextTestBase(
|
||||
private val frontend: FrontendKind<*>
|
||||
) : AbstractKotlinCompilerWithTargetBackendTest(TargetBackend.JVM_IR) {
|
||||
override fun TestConfigurationBuilder.configuration() {
|
||||
globalDefaults {
|
||||
frontend = this@AbstractIrTextTestBase.frontend
|
||||
targetPlatform = JvmPlatforms.defaultJvmPlatform
|
||||
artifactKind = BinaryKind.NoArtifact
|
||||
targetBackend = TargetBackend.JVM_IR
|
||||
dependencyKind = DependencyKind.Source
|
||||
}
|
||||
|
||||
defaultDirectives {
|
||||
+DUMP_IR
|
||||
}
|
||||
|
||||
useConfigurators(
|
||||
::CommonEnvironmentConfigurator,
|
||||
::JvmEnvironmentConfigurator
|
||||
)
|
||||
|
||||
useAdditionalSourceProviders(
|
||||
::AdditionalDiagnosticsSourceFilesProvider,
|
||||
::CoroutineHelpersSourceFilesProvider,
|
||||
::CodegenHelpersSourceFilesProvider,
|
||||
)
|
||||
|
||||
useFrontendFacades(
|
||||
::ClassicFrontendFacade,
|
||||
::FirFrontendFacade
|
||||
)
|
||||
useFrontend2BackendConverters(
|
||||
::ClassicFrontend2IrConverter,
|
||||
::Fir2IrResultsConverter
|
||||
)
|
||||
|
||||
useBackendHandlers(::IrTextDumpHandler)
|
||||
}
|
||||
}
|
||||
|
||||
open class AbstractIrTextTest : AbstractIrTextTestBase(FrontendKinds.ClassicFrontend)
|
||||
Reference in New Issue
Block a user