[JS Test] Introduce tests for loading metadata produced by JS compiler

This commit is contained in:
Dmitriy Novozhilov
2023-05-31 12:43:51 +03:00
committed by Space Team
parent 2290a096d1
commit 7eca772ec2
13 changed files with 3957 additions and 120 deletions
@@ -230,6 +230,11 @@ fun main(args: Array<String>) {
// testClass<AbstractFirJsSteppingTest> {
// model("debug/stepping")
// }
testClass<AbstractFirLoadK2CompiledJsKotlinTest> {
model("loadJava/compiledKotlin", extension = "kt")
model("loadJava/compiledKotlinWithStdlib", extension = "kt")
}
}
}
}
@@ -0,0 +1,58 @@
/*
* Copyright 2010-2023 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.js.test.fir
import org.jetbrains.kotlin.js.test.converters.FirJsKlibBackendFacade
import org.jetbrains.kotlin.js.test.ir.commonConfigurationForJsCodegenTest
import org.jetbrains.kotlin.test.*
import org.jetbrains.kotlin.test.backend.ir.IrBackendInput
import org.jetbrains.kotlin.test.builders.TestConfigurationBuilder
import org.jetbrains.kotlin.test.builders.configureKlibArtifactsHandlersStep
import org.jetbrains.kotlin.test.directives.FirDiagnosticsDirectives.FIR_PARSER
import org.jetbrains.kotlin.test.frontend.fir.Fir2IrResultsConverter
import org.jetbrains.kotlin.test.frontend.fir.FirFrontendFacade
import org.jetbrains.kotlin.test.frontend.fir.FirOutputArtifact
import org.jetbrains.kotlin.test.model.*
import org.jetbrains.kotlin.test.runners.AbstractKotlinCompilerWithTargetBackendTest
abstract class AbstractFirLoadCompiledJsKotlinTestBase<F : ResultingArtifact.FrontendOutput<F>> :
AbstractKotlinCompilerWithTargetBackendTest(TargetBackend.JS_IR)
{
protected abstract val frontendKind: FrontendKind<F>
protected abstract val frontendFacade: Constructor<FrontendFacade<F>>
protected abstract val frontendToBackendConverter: Constructor<Frontend2BackendConverter<F, IrBackendInput>>
override fun TestConfigurationBuilder.configuration() {
commonConfigurationForJsCodegenTest(
frontendKind,
frontendFacade,
frontendToBackendConverter,
::FirJsKlibBackendFacade,
)
configureKlibArtifactsHandlersStep {
useHandlers(::KlibLoadedMetadataDumpHandler)
}
useAfterAnalysisCheckers(::FirMetadataLoadingTestSuppressor)
}
}
open class AbstractFirLoadK2CompiledJsKotlinTest : AbstractFirLoadCompiledJsKotlinTestBase<FirOutputArtifact>() {
override val frontendKind: FrontendKind<FirOutputArtifact>
get() = FrontendKinds.FIR
override val frontendFacade: Constructor<FrontendFacade<FirOutputArtifact>>
get() = ::FirFrontendFacade
override val frontendToBackendConverter: Constructor<Frontend2BackendConverter<FirOutputArtifact, IrBackendInput>>
get() = ::Fir2IrResultsConverter
override fun configure(builder: TestConfigurationBuilder) {
super.configure(builder)
builder.defaultDirectives {
FIR_PARSER with FirParser.LightTree
}
}
}
@@ -56,15 +56,10 @@ abstract class AbstractJsBlackBoxCodegenTestBase<R : ResultingArtifact.FrontendO
}
protected fun TestConfigurationBuilder.commonConfigurationForJsBlackBoxCodegenTest() {
globalDefaults {
frontend = targetFrontend
targetPlatform = JsPlatforms.defaultJsPlatform
dependencyKind = DependencyKind.Binary
}
commonConfigurationForJsCodegenTest(targetFrontend, frontendFacade, frontendToBackendConverter, backendFacade)
val pathToRootOutputDir = System.getProperty("kotlin.js.test.root.out.dir") ?: error("'kotlin.js.test.root.out.dir' is not set")
defaultDirectives {
+DiagnosticsDirectives.REPORT_ONLY_EXPLICITLY_DEFINED_DEBUG_INFO
JsEnvironmentConfigurationDirectives.PATH_TO_ROOT_OUTPUT_DIR with pathToRootOutputDir
JsEnvironmentConfigurationDirectives.PATH_TO_TEST_DIR with pathToTestDir
JsEnvironmentConfigurationDirectives.TEST_GROUP_OUTPUT_DIR_PREFIX with testGroupOutputDirPrefix
@@ -74,6 +69,11 @@ abstract class AbstractJsBlackBoxCodegenTestBase<R : ResultingArtifact.FrontendO
if (getBoolean("kotlin.js.ir.skipRegularMode")) +JsEnvironmentConfigurationDirectives.SKIP_REGULAR_MODE
}
useAdditionalSourceProviders(
::JsAdditionalSourceProvider,
::CoroutineHelpersSourceFilesProvider,
)
forTestsNotMatching("compiler/testData/codegen/box/diagnostics/functions/tailRecursion/*") {
defaultDirectives {
DIAGNOSTICS with "-warnings"
@@ -84,47 +84,20 @@ abstract class AbstractJsBlackBoxCodegenTestBase<R : ResultingArtifact.FrontendO
enableMetaInfoHandler()
}
useConfigurators(
::CommonEnvironmentConfigurator,
::JsEnvironmentConfigurator,
)
useAdditionalSourceProviders(
::JsAdditionalSourceProvider,
::CoroutineHelpersSourceFilesProvider,
)
useAdditionalService(::JsLibraryProvider)
useAfterAnalysisCheckers(
::JsFailingTestSuppressor,
::BlackBoxCodegenSuppressor,
::JsArtifactsDumpHandler
)
facadeStep(frontendFacade)
classicFrontendHandlersStep {
commonClassicFrontendHandlersForCodegenTest()
useHandlers(::ClassicDiagnosticsHandler)
}
firHandlersStep {
useHandlers(::FirDiagnosticsHandler)
}
facadeStep(frontendToBackendConverter)
irHandlersStep {
configureIrHandlersStep {
useHandlers(::IrMangledNameAndSignatureDumpHandler)
}
facadeStep(backendFacade)
klibArtifactsHandlersStep()
afterBackendFacade?.let { facadeStep(it) }
facadeStep(recompileFacade)
jsArtifactsHandlersStep {
useHandlers(::JsSourceMapPathRewriter)
}
useAfterAnalysisCheckers(
::JsArtifactsDumpHandler
)
forTestsMatching("compiler/testData/codegen/box/involvesIrInterpreter/*") {
enableMetaInfoHandler()
configureKlibArtifactsHandlersStep {
@@ -136,3 +109,53 @@ abstract class AbstractJsBlackBoxCodegenTestBase<R : ResultingArtifact.FrontendO
}
}
}
@Suppress("reformat")
fun <
R : ResultingArtifact.FrontendOutput<R>,
I : ResultingArtifact.BackendInput<I>,
A : ResultingArtifact.Binary<A>
> TestConfigurationBuilder.commonConfigurationForJsCodegenTest(
targetFrontend: FrontendKind<R>,
frontendFacade: Constructor<FrontendFacade<R>>,
frontendToBackendConverter: Constructor<Frontend2BackendConverter<R, I>>,
backendFacade: Constructor<BackendFacade<I, A>>,
) {
globalDefaults {
frontend = targetFrontend
targetPlatform = JsPlatforms.defaultJsPlatform
dependencyKind = DependencyKind.Binary
}
defaultDirectives {
+DiagnosticsDirectives.REPORT_ONLY_EXPLICITLY_DEFINED_DEBUG_INFO
}
useConfigurators(
::CommonEnvironmentConfigurator,
::JsEnvironmentConfigurator,
)
useAdditionalService(::JsLibraryProvider)
useAfterAnalysisCheckers(
::JsFailingTestSuppressor,
::BlackBoxCodegenSuppressor,
)
facadeStep(frontendFacade)
classicFrontendHandlersStep {
commonClassicFrontendHandlersForCodegenTest()
useHandlers(::ClassicDiagnosticsHandler)
}
firHandlersStep {
useHandlers(::FirDiagnosticsHandler)
}
facadeStep(frontendToBackendConverter)
irHandlersStep()
facadeStep(backendFacade)
klibArtifactsHandlersStep()
}
@@ -20,11 +20,8 @@ import org.jetbrains.kotlin.name.FqName
import org.jetbrains.kotlin.test.TargetBackend
import org.jetbrains.kotlin.test.directives.JsEnvironmentConfigurationDirectives
import org.jetbrains.kotlin.test.model.TestModule
import org.jetbrains.kotlin.test.services.TestService
import org.jetbrains.kotlin.test.services.TestServices
import org.jetbrains.kotlin.test.services.compilerConfigurationProvider
import org.jetbrains.kotlin.test.services.*
import org.jetbrains.kotlin.test.services.configuration.JsEnvironmentConfigurator
import org.jetbrains.kotlin.test.services.jsLibraryProvider
import java.io.ByteArrayOutputStream
import java.io.File
@@ -46,14 +43,14 @@ private class TestArtifactCache(val moduleName: String, val binaryAsts: MutableM
}
class JsIrIncrementalDataProvider(private val testServices: TestServices) : TestService {
private val fullRuntimeKlib: String = System.getProperty("kotlin.js.full.stdlib.path")
private val defaultRuntimeKlib = System.getProperty("kotlin.js.reduced.stdlib.path")
private val kotlinTestKLib = System.getProperty("kotlin.js.kotlin.test.path")
private val fullRuntimeKlib = testServices.standardLibrariesPathProvider.fullJsStdlib()
private val defaultRuntimeKlib = testServices.standardLibrariesPathProvider.defaultJsStdlib()
private val kotlinTestKLib = testServices.standardLibrariesPathProvider.kotlinTestJsKLib()
private val predefinedKlibHasIcCache = mutableMapOf<String, TestArtifactCache?>(
File(fullRuntimeKlib).absolutePath to null,
File(kotlinTestKLib).absolutePath to null,
File(defaultRuntimeKlib).absolutePath to null
fullRuntimeKlib.absolutePath to null,
kotlinTestKLib.absolutePath to null,
defaultRuntimeKlib.absolutePath to null
)
private val icCache: MutableMap<String, TestArtifactCache> = mutableMapOf()