From ccc72e51256979c9285810d4d7705c88f07726ea Mon Sep 17 00:00:00 2001 From: Nikolay Lunyak Date: Wed, 30 Mar 2022 13:58:10 +0300 Subject: [PATCH] [FIR JS] Add a FirJsTest runner Note: 763/1627 failed tests - 170 are multi-module tests which can be ignored for now --- .../generators/tests/GenerateJsTests.kt | 4 + .../kotlin/js/test/ir/AbstractJsIrTest.kt | 90 +++++++++++++++++++ 2 files changed, 94 insertions(+) diff --git a/js/js.tests/test/org/jetbrains/kotlin/generators/tests/GenerateJsTests.kt b/js/js.tests/test/org/jetbrains/kotlin/generators/tests/GenerateJsTests.kt index c03cdfe8901..f7ff7ba7ad7 100644 --- a/js/js.tests/test/org/jetbrains/kotlin/generators/tests/GenerateJsTests.kt +++ b/js/js.tests/test/org/jetbrains/kotlin/generators/tests/GenerateJsTests.kt @@ -113,6 +113,10 @@ fun main(args: Array) { testClass { model("lineNumbers/") } + + testClass { + model("box/", pattern = "^([^_](.+))\\.kt$") + } } testGroup("js/js.tests/tests-gen", "compiler/testData", testRunnerMethodName = "runTest0") { diff --git a/js/js.tests/test/org/jetbrains/kotlin/js/test/ir/AbstractJsIrTest.kt b/js/js.tests/test/org/jetbrains/kotlin/js/test/ir/AbstractJsIrTest.kt index 07c9f919c32..ac6a7c960de 100644 --- a/js/js.tests/test/org/jetbrains/kotlin/js/test/ir/AbstractJsIrTest.kt +++ b/js/js.tests/test/org/jetbrains/kotlin/js/test/ir/AbstractJsIrTest.kt @@ -6,22 +6,39 @@ package org.jetbrains.kotlin.js.test.ir import org.jetbrains.kotlin.js.test.AbstractJsBlackBoxCodegenTestBase +import org.jetbrains.kotlin.js.test.JsAdditionalSourceProvider import org.jetbrains.kotlin.js.test.converters.JsIrBackendFacade import org.jetbrains.kotlin.js.test.converters.JsKlibBackendFacade import org.jetbrains.kotlin.js.test.converters.incremental.RecompileModuleJsIrBackendFacade import org.jetbrains.kotlin.js.test.handlers.* import org.jetbrains.kotlin.parsing.parseBoolean +import org.jetbrains.kotlin.platform.js.JsPlatforms import org.jetbrains.kotlin.test.Constructor import org.jetbrains.kotlin.test.TargetBackend import org.jetbrains.kotlin.test.backend.ir.IrBackendInput import org.jetbrains.kotlin.test.builders.TestConfigurationBuilder +import org.jetbrains.kotlin.test.builders.classicFrontendHandlersStep import org.jetbrains.kotlin.test.builders.configureJsArtifactsHandlersStep +import org.jetbrains.kotlin.test.builders.firHandlersStep +import org.jetbrains.kotlin.test.directives.ConfigurationDirectives +import org.jetbrains.kotlin.test.directives.DiagnosticsDirectives import org.jetbrains.kotlin.test.directives.JsEnvironmentConfigurationDirectives +import org.jetbrains.kotlin.test.directives.LanguageSettingsDirectives import org.jetbrains.kotlin.test.frontend.classic.ClassicFrontend2IrConverter import org.jetbrains.kotlin.test.frontend.classic.ClassicFrontendFacade import org.jetbrains.kotlin.test.frontend.classic.ClassicFrontendOutputArtifact +import org.jetbrains.kotlin.test.frontend.classic.handlers.ClassicDiagnosticsHandler +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.frontend.fir.handlers.* import org.jetbrains.kotlin.test.model.* +import org.jetbrains.kotlin.test.runners.AbstractKotlinCompilerWithTargetBackendTest +import org.jetbrains.kotlin.test.runners.codegen.commonClassicFrontendHandlersForCodegenTest +import org.jetbrains.kotlin.test.services.JsLibraryProvider +import org.jetbrains.kotlin.test.services.configuration.CommonEnvironmentConfigurator import org.jetbrains.kotlin.test.services.configuration.JsEnvironmentConfigurator +import org.jetbrains.kotlin.test.services.sourceProviders.CoroutineHelpersSourceFilesProvider import java.lang.Boolean.getBoolean abstract class AbstractJsIrTest( @@ -140,3 +157,76 @@ open class AbstractIrCodegenWasmJsInteropJsTest : AbstractJsIrTest( pathToTestDir = "compiler/testData/codegen/wasmJsInterop", testGroupOutputDirPrefix = "codegen/wasmJsInteropJs" ) + +open class AbstractFirJsTest : AbstractKotlinCompilerWithTargetBackendTest(TargetBackend.JS_IR) { + private val pathToTestDir = "${JsEnvironmentConfigurator.TEST_DATA_DIR_PATH}/box/" + private val testGroupOutputDirPrefix = "box/" + + val targetFrontend = FrontendKinds.FIR + private val skipMinification: Boolean = getBoolean("kotlin.js.skipMinificationTest") + + val frontendFacade: Constructor> + get() = ::FirFrontendFacade + + private val frontendToBackendConverter: Constructor> + get() = ::Fir2IrResultsConverter + + override fun TestConfigurationBuilder.configuration() { + globalDefaults { + frontend = targetFrontend + targetPlatform = JsPlatforms.defaultJsPlatform + dependencyKind = DependencyKind.Binary + } + + 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 + +JsEnvironmentConfigurationDirectives.TYPED_ARRAYS + if (skipMinification) +JsEnvironmentConfigurationDirectives.SKIP_MINIFICATION + if (getBoolean("kotlin.js.ir.skipRegularMode")) +JsEnvironmentConfigurationDirectives.SKIP_REGULAR_MODE + +ConfigurationDirectives.WITH_STDLIB + +LanguageSettingsDirectives.ALLOW_KOTLIN_PACKAGE + } + + forTestsNotMatching("compiler/testData/codegen/box/diagnostics/functions/tailRecursion/*") { + defaultDirectives { + DiagnosticsDirectives.DIAGNOSTICS with "-warnings" + } + } + + forTestsNotMatching("compiler/testData/codegen/boxError/*") { + enableMetaInfoHandler() + } + + useConfigurators( + ::CommonEnvironmentConfigurator, + ::JsEnvironmentConfigurator, + ) + + useAdditionalSourceProviders( + ::JsAdditionalSourceProvider, + ::CoroutineHelpersSourceFilesProvider, + ) + + useAdditionalService(::JsLibraryProvider) + + facadeStep(frontendFacade) + + firHandlersStep { + useHandlers( + ::FirDiagnosticsHandler, + ::FirDumpHandler, + ::FirCfgDumpHandler, + ::FirCfgConsistencyHandler, + ::FirNoImplicitTypesHandler, + ) + } + + // There were some problems not covered by + // the FIR handlers above + facadeStep(frontendToBackendConverter) + } +}