[JS] Migrate web demo examples
This commit is contained in:
committed by
Space Team
parent
b5a7b9c661
commit
b6803b2400
+5
-2
@@ -173,8 +173,11 @@ class JsEnvironmentConfigurator(testServices: TestServices) : EnvironmentConfigu
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun getMainCallParametersForModule(module: TestModule): MainCallParameters {
|
fun getMainCallParametersForModule(module: TestModule): MainCallParameters {
|
||||||
return when (JsEnvironmentConfigurationDirectives.CALL_MAIN) {
|
return when {
|
||||||
in module.directives -> MainCallParameters.mainWithArguments(listOf())
|
JsEnvironmentConfigurationDirectives.CALL_MAIN in module.directives -> MainCallParameters.mainWithArguments(listOf())
|
||||||
|
JsEnvironmentConfigurationDirectives.MAIN_ARGS in module.directives -> {
|
||||||
|
MainCallParameters.mainWithArguments(module.directives[JsEnvironmentConfigurationDirectives.MAIN_ARGS].single())
|
||||||
|
}
|
||||||
else -> MainCallParameters.noCall()
|
else -> MainCallParameters.noCall()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,82 +0,0 @@
|
|||||||
/*
|
|
||||||
* 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.js.test
|
|
||||||
|
|
||||||
import org.jetbrains.kotlin.js.test.converters.ClassicJsBackendFacade
|
|
||||||
import org.jetbrains.kotlin.js.test.converters.incremental.RecompileModuleJsBackendFacade
|
|
||||||
import org.jetbrains.kotlin.js.test.handlers.*
|
|
||||||
import org.jetbrains.kotlin.js.test.ir.AbstractJsBlackBoxCodegenTestBase
|
|
||||||
import org.jetbrains.kotlin.js.test.ir.AbstractJsIrTest
|
|
||||||
import org.jetbrains.kotlin.js.test.utils.JsIncrementalEnvironmentConfigurator
|
|
||||||
import org.jetbrains.kotlin.test.Constructor
|
|
||||||
import org.jetbrains.kotlin.test.TargetBackend
|
|
||||||
import org.jetbrains.kotlin.test.backend.classic.ClassicBackendInput
|
|
||||||
import org.jetbrains.kotlin.test.builders.TestConfigurationBuilder
|
|
||||||
import org.jetbrains.kotlin.test.builders.configureJsArtifactsHandlersStep
|
|
||||||
import org.jetbrains.kotlin.test.directives.JsEnvironmentConfigurationDirectives
|
|
||||||
import org.jetbrains.kotlin.test.frontend.classic.ClassicFrontend2ClassicBackendConverter
|
|
||||||
import org.jetbrains.kotlin.test.frontend.classic.ClassicFrontendFacade
|
|
||||||
import org.jetbrains.kotlin.test.frontend.classic.ClassicFrontendOutputArtifact
|
|
||||||
import org.jetbrains.kotlin.test.model.*
|
|
||||||
import org.jetbrains.kotlin.test.services.configuration.JsEnvironmentConfigurator
|
|
||||||
|
|
||||||
abstract class AbstractJsTest(
|
|
||||||
pathToTestDir: String,
|
|
||||||
testGroupOutputDirPrefix: String,
|
|
||||||
) : AbstractJsBlackBoxCodegenTestBase<ClassicFrontendOutputArtifact, ClassicBackendInput, BinaryArtifacts.Js>(
|
|
||||||
FrontendKinds.ClassicFrontend, TargetBackend.JS, pathToTestDir, testGroupOutputDirPrefix
|
|
||||||
) {
|
|
||||||
override val frontendFacade: Constructor<FrontendFacade<ClassicFrontendOutputArtifact>>
|
|
||||||
get() = ::ClassicFrontendFacade
|
|
||||||
|
|
||||||
override val frontendToBackendConverter: Constructor<Frontend2BackendConverter<ClassicFrontendOutputArtifact, ClassicBackendInput>>
|
|
||||||
get() = ::ClassicFrontend2ClassicBackendConverter
|
|
||||||
|
|
||||||
override val backendFacade: Constructor<BackendFacade<ClassicBackendInput, BinaryArtifacts.Js>>
|
|
||||||
get() = ::ClassicJsBackendFacade
|
|
||||||
|
|
||||||
override val afterBackendFacade: Constructor<AbstractTestFacade<BinaryArtifacts.Js, BinaryArtifacts.Js>>?
|
|
||||||
get() = null
|
|
||||||
|
|
||||||
override val recompileFacade: Constructor<AbstractTestFacade<BinaryArtifacts.Js, BinaryArtifacts.Js>>
|
|
||||||
get() = { RecompileModuleJsBackendFacade(it, frontendFacade, frontendToBackendConverter) }
|
|
||||||
|
|
||||||
override fun configure(builder: TestConfigurationBuilder) {
|
|
||||||
super.configure(builder)
|
|
||||||
with(builder) {
|
|
||||||
useConfigurators(
|
|
||||||
::JsIncrementalEnvironmentConfigurator
|
|
||||||
)
|
|
||||||
|
|
||||||
configureJsArtifactsHandlersStep {
|
|
||||||
useHandlers(
|
|
||||||
::JsTranslationResultHandler,
|
|
||||||
::JsSourceMapHandler,
|
|
||||||
::JsRecompiledArtifactsIdentityHandler,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
open class AbstractWebDemoExamplesTest : AbstractJsTest(
|
|
||||||
pathToTestDir = "${JsEnvironmentConfigurator.TEST_DATA_DIR_PATH}/webDemoExamples/",
|
|
||||||
testGroupOutputDirPrefix = "webDemoExamples/"
|
|
||||||
) {
|
|
||||||
override fun configure(builder: TestConfigurationBuilder) {
|
|
||||||
super.configure(builder)
|
|
||||||
with(builder) {
|
|
||||||
defaultDirectives {
|
|
||||||
-JsEnvironmentConfigurationDirectives.GENERATE_NODE_JS_RUNNER
|
|
||||||
JsEnvironmentConfigurationDirectives.DONT_RUN_GENERATED_CODE.with("JS")
|
|
||||||
}
|
|
||||||
|
|
||||||
configureJsArtifactsHandlersStep {
|
|
||||||
useHandlers(::MainCallWithArgumentsHandler)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -5,7 +5,6 @@
|
|||||||
|
|
||||||
package org.jetbrains.kotlin.js.test.ir
|
package org.jetbrains.kotlin.js.test.ir
|
||||||
|
|
||||||
import org.jetbrains.kotlin.js.test.AbstractJsTest
|
|
||||||
import org.jetbrains.kotlin.js.test.JsSteppingTestAdditionalSourceProvider
|
import org.jetbrains.kotlin.js.test.JsSteppingTestAdditionalSourceProvider
|
||||||
import org.jetbrains.kotlin.js.test.converters.JsIrBackendFacade
|
import org.jetbrains.kotlin.js.test.converters.JsIrBackendFacade
|
||||||
import org.jetbrains.kotlin.js.test.converters.JsKlibBackendFacade
|
import org.jetbrains.kotlin.js.test.converters.JsKlibBackendFacade
|
||||||
@@ -163,6 +162,26 @@ open class AbstractMultiModuleOrderTest : AbstractJsIrTest(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
open class AbstractWebDemoExamplesTest : AbstractJsIrTest(
|
||||||
|
pathToTestDir = "${JsEnvironmentConfigurator.TEST_DATA_DIR_PATH}/webDemoExamples/",
|
||||||
|
testGroupOutputDirPrefix = "webDemoExamples/"
|
||||||
|
) {
|
||||||
|
override fun configure(builder: TestConfigurationBuilder) {
|
||||||
|
super.configure(builder)
|
||||||
|
with(builder) {
|
||||||
|
defaultDirectives {
|
||||||
|
+JsEnvironmentConfigurationDirectives.KJS_WITH_FULL_RUNTIME
|
||||||
|
-JsEnvironmentConfigurationDirectives.GENERATE_NODE_JS_RUNNER
|
||||||
|
JsEnvironmentConfigurationDirectives.DONT_RUN_GENERATED_CODE.with("JS_IR")
|
||||||
|
}
|
||||||
|
|
||||||
|
configureJsArtifactsHandlersStep {
|
||||||
|
useHandlers(::MainCallWithArgumentsHandler)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private fun configureJsIrLineNumberTest(builder: TestConfigurationBuilder) {
|
private fun configureJsIrLineNumberTest(builder: TestConfigurationBuilder) {
|
||||||
with(builder) {
|
with(builder) {
|
||||||
defaultDirectives {
|
defaultDirectives {
|
||||||
|
|||||||
@@ -10,7 +10,10 @@ import org.jetbrains.kotlin.js.engine.ScriptEngine
|
|||||||
import org.jetbrains.kotlin.js.engine.ScriptEngineNashorn
|
import org.jetbrains.kotlin.js.engine.ScriptEngineNashorn
|
||||||
import org.jetbrains.kotlin.js.engine.ScriptEngineV8
|
import org.jetbrains.kotlin.js.engine.ScriptEngineV8
|
||||||
import org.jetbrains.kotlin.js.engine.loadFiles
|
import org.jetbrains.kotlin.js.engine.loadFiles
|
||||||
|
import org.jetbrains.kotlin.test.utils.withExtension
|
||||||
|
import org.jetbrains.kotlin.test.utils.withSuffixAndExtension
|
||||||
import org.junit.Assert
|
import org.junit.Assert
|
||||||
|
import java.io.File
|
||||||
|
|
||||||
internal const val TEST_DATA_DIR_PATH = "js/js.translator/testData/"
|
internal const val TEST_DATA_DIR_PATH = "js/js.translator/testData/"
|
||||||
private const val DIST_DIR_JS_PATH = "dist/js/"
|
private const val DIST_DIR_JS_PATH = "dist/js/"
|
||||||
@@ -104,7 +107,20 @@ abstract class AbstractJsTestChecker {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun checkStdout(files: List<String>, expectedResult: String) {
|
fun checkStdout(files: List<String>, expectedResult: String) {
|
||||||
run(files) {
|
val newFiles = files
|
||||||
|
.mapIndexed { index, s ->
|
||||||
|
if (index == files.size - 1) {
|
||||||
|
val file = File(s)
|
||||||
|
val lines = file.readText().lines().toMutableList()
|
||||||
|
lines.add(lines.size - 6, JS_IR_OUTPUT_REWRITE)
|
||||||
|
val newFile = file.withSuffixAndExtension("_modified", "js")
|
||||||
|
newFile.writeText(lines.joinToString("\n"))
|
||||||
|
newFile.absolutePath
|
||||||
|
} else {
|
||||||
|
s
|
||||||
|
}
|
||||||
|
}
|
||||||
|
run(newFiles) {
|
||||||
val actualResult = eval(GET_KOTLIN_OUTPUT)
|
val actualResult = eval(GET_KOTLIN_OUTPUT)
|
||||||
Assert.assertEquals(expectedResult, actualResult.normalize())
|
Assert.assertEquals(expectedResult, actualResult.normalize())
|
||||||
""
|
""
|
||||||
@@ -165,7 +181,12 @@ abstract class AbstractNashornJsTestChecker : AbstractJsTestChecker() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const val SETUP_KOTLIN_OUTPUT = "kotlin.kotlin.io.output = new kotlin.kotlin.io.BufferedOutput();"
|
const val SETUP_KOTLIN_OUTPUT = "kotlin.kotlin.io.output = new kotlin.kotlin.io.BufferedOutput();"
|
||||||
const val GET_KOTLIN_OUTPUT = "kotlin.kotlin.io.output.buffer;"
|
const val GET_KOTLIN_OUTPUT = "main.get_output().buffer_1"
|
||||||
|
|
||||||
|
private val JS_IR_OUTPUT_REWRITE = """
|
||||||
|
set_output(new BufferedOutput())
|
||||||
|
_.get_output = get_output
|
||||||
|
""".trimIndent()
|
||||||
|
|
||||||
object NashornJsTestChecker : AbstractNashornJsTestChecker() {
|
object NashornJsTestChecker : AbstractNashornJsTestChecker() {
|
||||||
|
|
||||||
|
|||||||
+2
-2
@@ -3,7 +3,7 @@
|
|||||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
* 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;
|
package org.jetbrains.kotlin.js.test.ir;
|
||||||
|
|
||||||
import com.intellij.testFramework.TestDataPath;
|
import com.intellij.testFramework.TestDataPath;
|
||||||
import org.jetbrains.kotlin.test.util.KtTestUtil;
|
import org.jetbrains.kotlin.test.util.KtTestUtil;
|
||||||
@@ -22,7 +22,7 @@ import java.util.regex.Pattern;
|
|||||||
public class WebDemoExamplesTestGenerated extends AbstractWebDemoExamplesTest {
|
public class WebDemoExamplesTestGenerated extends AbstractWebDemoExamplesTest {
|
||||||
@Test
|
@Test
|
||||||
public void testAllFilesPresentInWebDemoExamples() throws Exception {
|
public void testAllFilesPresentInWebDemoExamples() throws Exception {
|
||||||
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("js/js.translator/testData/webDemoExamples"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JS, true);
|
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("js/js.translator/testData/webDemoExamples"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JS_IR, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
Reference in New Issue
Block a user