[TEST] Migrate AbstractDiagnosticsTestWithJsStdLib to new test runners

This commit is contained in:
Dmitriy Novozhilov
2020-12-14 16:16:46 +03:00
parent 1fe5148f0d
commit 71ffaa2d97
27 changed files with 419 additions and 167 deletions
@@ -0,0 +1,64 @@
/*
* 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.frontend.classic.handlers
import org.jetbrains.kotlin.checkers.CheckerDebugInfoReporter
import org.jetbrains.kotlin.checkers.utils.DebugInfoUtil
import org.jetbrains.kotlin.config.LanguageFeature
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor
import org.jetbrains.kotlin.test.directives.DiagnosticsDirectives
import org.jetbrains.kotlin.test.directives.model.DirectivesContainer
import org.jetbrains.kotlin.test.frontend.classic.ClassicFrontendOutputArtifact
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.util.RecursiveDescriptorComparator
import org.jetbrains.kotlin.test.util.RecursiveDescriptorComparator.RECURSIVE_ALL
import org.jetbrains.kotlin.test.utils.MultiModuleInfoDumper
import org.jetbrains.kotlin.test.utils.MultiModuleInfoDumperImpl
import org.jetbrains.kotlin.test.utils.withExtension
class DynamicCallsDumpHandler(testServices: TestServices) : ClassicFrontendAnalysisHandler(testServices) {
companion object {
private const val DYNAMIC_PREFIX = ".dynamic.txt"
}
override val directivesContainers: List<DirectivesContainer>
get() = listOf(DiagnosticsDirectives)
private val dumper: MultiModuleInfoDumper = MultiModuleInfoDumperImpl(moduleHeaderTemplate = "// -- Module: <%s> --")
override fun processModule(module: TestModule, info: ClassicFrontendOutputArtifact) {
val dynamicCallDescriptors = mutableListOf<DeclarationDescriptor>()
for (ktFile in info.ktFiles.values) {
DebugInfoUtil.markDebugAnnotations(
ktFile,
info.analysisResult.bindingContext,
CheckerDebugInfoReporter(
dynamicCallDescriptors,
markDynamicCalls = true,
debugAnnotations = mutableListOf(),
withNewInference = info.languageVersionSettings.supportsFeature(LanguageFeature.NewInference),
platform = null
)
)
}
val serializer = RecursiveDescriptorComparator(RECURSIVE_ALL)
val builder = dumper.builderForModule(module)
for (descriptor in dynamicCallDescriptors) {
builder.append(serializer.serializeRecursively(descriptor))
}
}
override fun processAfterAllModules(someAssertionWasFailed: Boolean) {
if (dumper.isEmpty()) return
val expectedFile = testServices.moduleStructure.originalTestDataFiles.first().withExtension(DYNAMIC_PREFIX)
if (expectedFile.exists()) {
val resultDump = dumper.generateResultingDump()
assertions.assertEqualsToFile(expectedFile, resultDump)
}
}
}
@@ -26,6 +26,10 @@ fun main(args: Array<String>) {
model("diagnostics/tests", excludedPattern = excludedFirTestdataPattern)
model("diagnostics/testsWithStdLib", excludedPattern = excludedFirTestdataPattern)
}
testClass<AbstractDiagnosticsTestWithJsStdLib> {
model("diagnostics/testsWithJsStdLib")
}
}
testGroup("compiler/tests-common-new/tests-gen", "compiler/fir/analysis-tests/testData") {
@@ -0,0 +1,53 @@
/*
* 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.runners
import org.jetbrains.kotlin.platform.js.JsPlatforms
import org.jetbrains.kotlin.test.builders.TestConfigurationBuilder
import org.jetbrains.kotlin.test.directives.JvmEnvironmentConfigurationDirectives
import org.jetbrains.kotlin.test.frontend.classic.ClassicFrontendFacade
import org.jetbrains.kotlin.test.frontend.classic.handlers.ClassicDiagnosticsHandler
import org.jetbrains.kotlin.test.frontend.classic.handlers.DeclarationsDumpHandler
import org.jetbrains.kotlin.test.frontend.classic.handlers.DynamicCallsDumpHandler
import org.jetbrains.kotlin.test.frontend.classic.handlers.OldNewInferenceMetaInfoProcessor
import org.jetbrains.kotlin.test.model.BackendKind
import org.jetbrains.kotlin.test.model.DependencyKind
import org.jetbrains.kotlin.test.model.FrontendKinds
import org.jetbrains.kotlin.test.services.AdditionalDiagnosticsSourceFilesProvider
import org.jetbrains.kotlin.test.services.CoroutineHelpersSourceFilesProvider
import org.jetbrains.kotlin.test.services.configuration.JsEnvironmentConfigurator
abstract class AbstractDiagnosticsTestWithJsStdLib : AbstractKotlinCompilerTest() {
override fun TestConfigurationBuilder.configuration() {
globalDefaults {
frontend = FrontendKinds.ClassicFrontend
backend = BackendKind.NoBackend
targetPlatform = JsPlatforms.defaultJsPlatform
dependencyKind = DependencyKind.Source
}
defaultDirectives {
+JvmEnvironmentConfigurationDirectives.USE_PSI_CLASS_FILES_READING
}
enableMetaInfoHandler()
useConfigurators(::JsEnvironmentConfigurator,)
useMetaInfoProcessors(::OldNewInferenceMetaInfoProcessor)
useAdditionalSourceProviders(
::AdditionalDiagnosticsSourceFilesProvider,
::CoroutineHelpersSourceFilesProvider,
)
useFrontendFacades(::ClassicFrontendFacade)
useFrontendHandlers(
::DeclarationsDumpHandler,
::ClassicDiagnosticsHandler,
::DynamicCallsDumpHandler,
)
}
}
@@ -26,3 +26,9 @@ val File.firTestDataFile: File
} else {
parentFile.resolve("${name.removeSuffix(KT)}$FIR_KT")
}
fun File.withExtension(extension: String): File {
@Suppress("NAME_SHADOWING")
val extension = extension.removePrefix(".")
return parentFile.resolve("$nameWithoutExtension.$extension")
}