[JS BE] add es6 BE and relevant generated tests

This commit is contained in:
Vitaly
2020-05-23 13:52:11 +03:00
committed by romanart
parent a231b21c69
commit fe65045615
12 changed files with 37011 additions and 11 deletions
@@ -15,6 +15,7 @@ enum class TargetBackend(
JVM_IR(true, JVM),
JS(false),
JS_IR(true, JS),
JS_IR_ES6(true, JS_IR),
WASM(true),
ANDROID(false, JVM);
+23
View File
@@ -112,6 +112,7 @@ fun Test.setUpJsBoxTests(jsEnabled: Boolean, jsIrEnabled: Boolean) {
}
exclude("org/jetbrains/kotlin/js/test/wasm/semantics/*")
exclude("org/jetbrains/kotlin/js/test/es6/semantics/*")
if (jsEnabled && !jsIrEnabled) exclude("org/jetbrains/kotlin/js/test/ir/semantics/*")
if (!jsEnabled && jsIrEnabled) include("org/jetbrains/kotlin/js/test/ir/semantics/*")
@@ -148,6 +149,28 @@ projectTest("jsIrTest", true) {
setUpJsBoxTests(jsEnabled = false, jsIrEnabled = true)
}
projectTest("jsEs6IrTest", true) {
systemProperty("kotlin.js.ir.pir", "false")
systemProperty("kotlin.js.ir.es6", "true")
dependsOn(":dist")
dependsOn(":kotlin-stdlib-js-ir:compileKotlinJs")
systemProperty("kotlin.js.full.stdlib.path", "libraries/stdlib/js-ir/build/classes/kotlin/js/main")
dependsOn(":kotlin-stdlib-js-ir-minimal-for-test:compileKotlinJs")
systemProperty("kotlin.js.reduced.stdlib.path", "libraries/stdlib/js-ir-minimal-for-test/build/classes/kotlin/js/main")
dependsOn(":kotlin-test:kotlin-test-js-ir:compileKotlinJs")
systemProperty("kotlin.js.kotlin.test.path", "libraries/kotlin.test/js-ir/build/classes/kotlin/js/main")
exclude("org/jetbrains/kotlin/js/test/wasm/semantics/*")
exclude("org/jetbrains/kotlin/js/test/ir/semantics/*")
exclude("org/jetbrains/kotlin/js/test/semantics/*")
include("org/jetbrains/kotlin/js/test/es6/semantics/*")
jvmArgs("-da:jdk.nashorn.internal.runtime.RecompilableScriptFunctionData") // Disable assertion which fails due to a bug in nashorn (KT-23637)
setUpBoxTests()
}
projectTest("jsPirTest", true) {
systemProperty("kotlin.js.ir.skipRegularMode", "true")
setUpJsBoxTests(jsEnabled = false, jsIrEnabled = true)
@@ -8,6 +8,7 @@ package org.jetbrains.kotlin.generators.tests
import org.jetbrains.kotlin.generators.tests.generator.testGroup
import org.jetbrains.kotlin.js.test.AbstractDceTest
import org.jetbrains.kotlin.js.test.AbstractJsLineNumberTest
import org.jetbrains.kotlin.js.test.es6.semantics.*
import org.jetbrains.kotlin.js.test.ir.semantics.*
import org.jetbrains.kotlin.js.test.semantics.*
import org.jetbrains.kotlin.js.test.wasm.semantics.AbstractIrWasmBoxWasmTest
@@ -28,10 +29,18 @@ fun main(args: Array<String>) {
model("box/", pattern = "^([^_](.+))\\.kt$", targetBackend = TargetBackend.JS_IR)
}
testClass<AbstractIrBoxJsES6Test> {
model("box/", pattern = "^([^_](.+))\\.kt$", targetBackend = TargetBackend.JS_IR_ES6)
}
testClass<AbstractIrJsTypeScriptExportTest> {
model("typescript-export/", pattern = "^([^_](.+))\\.kt$", targetBackend = TargetBackend.JS_IR)
}
testClass<AbstractIrJsTypeScriptExportES6Test> {
model("typescript-export/", pattern = "^([^_](.+))\\.kt$", targetBackend = TargetBackend.JS_IR_ES6)
}
testClass<AbstractLegacyJsTypeScriptExportTest> {
model("typescript-export/", pattern = "^([^_](.+))\\.kt$", targetBackend = TargetBackend.JS)
}
@@ -71,6 +80,10 @@ fun main(args: Array<String>) {
model("codegen/box", targetBackend = TargetBackend.JS_IR)
}
testClass<AbstractIrJsCodegenBoxES6Test> {
model("codegen/box", targetBackend = TargetBackend.JS_IR_ES6)
}
testClass<AbstractJsCodegenInlineTest> {
model("codegen/boxInline/", targetBackend = TargetBackend.JS)
}
@@ -79,6 +92,10 @@ fun main(args: Array<String>) {
model("codegen/boxInline/", targetBackend = TargetBackend.JS_IR)
}
testClass<AbstractIrJsCodegenInlineES6Test> {
model("codegen/boxInline/", targetBackend = TargetBackend.JS_IR_ES6)
}
testClass<AbstractJsLegacyPrimitiveArraysBoxTest> {
model("codegen/box/arrays", targetBackend = TargetBackend.JS)
}
@@ -178,7 +178,7 @@ abstract class BasicBoxTest(
module.name.endsWith(OLD_MODULE_SUFFIX) -> null
// JS_IR generates single js file for all modules (apart from runtime).
// TODO: Split and refactor test runner for JS_IR
targetBackend == TargetBackend.JS_IR && !isMainModule -> null
targetBackend in listOf(TargetBackend.JS_IR, TargetBackend.JS_IR_ES6) && !isMainModule -> null
else -> Pair(outputFileName, module)
}
}
@@ -680,6 +680,7 @@ abstract class BasicBoxTest(
}
val libraries = when (targetBackend) {
TargetBackend.JS_IR_ES6 -> dependencies
TargetBackend.JS_IR -> dependencies
TargetBackend.JS -> JsConfig.JS_STDLIB + JsConfig.JS_KOTLIN_TEST + dependencies
else -> error("Unsupported target backend: $targetBackend")
@@ -0,0 +1,17 @@
/*
* 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.js.test
import org.jetbrains.kotlin.test.TargetBackend
abstract class BasicIrBoxES6Test(
pathToTestDir: String,
testGroupOutputDirPrefix: String
) : BasicIrBoxTest(
pathToTestDir,
testGroupOutputDirPrefix,
targetBackend = TargetBackend.JS_IR_ES6
)
@@ -16,6 +16,7 @@ import org.jetbrains.kotlin.js.config.JsConfig
import org.jetbrains.kotlin.js.facade.MainCallParameters
import org.jetbrains.kotlin.js.facade.TranslationUnit
import org.jetbrains.kotlin.name.FqName
import org.jetbrains.kotlin.parsing.parseBoolean
import org.jetbrains.kotlin.test.TargetBackend
import org.jetbrains.kotlin.utils.fileUtils.withReplacedExtensionOrNull
import java.io.File
@@ -30,7 +31,8 @@ abstract class BasicIrBoxTest(
testGroupOutputDirPrefix: String,
pathToRootOutputDir: String = TEST_DATA_DIR_PATH,
generateSourceMap: Boolean = false,
generateNodeJsRunner: Boolean = false
generateNodeJsRunner: Boolean = false,
targetBackend: TargetBackend = TargetBackend.JS_IR
) : BasicBoxTest(
pathToTestDir,
testGroupOutputDirPrefix,
@@ -38,13 +40,13 @@ abstract class BasicIrBoxTest(
typedArraysEnabled = true,
generateSourceMap = generateSourceMap,
generateNodeJsRunner = generateNodeJsRunner,
targetBackend = TargetBackend.JS_IR
targetBackend = targetBackend
) {
open val generateDts = false
override val skipMinification = true
private fun getBoolean(s: String, default: Boolean) = System.getProperty(s)?.let { getBoolean(it) } ?: default
private fun getBoolean(s: String, default: Boolean) = System.getProperty(s)?.let { parseBoolean(it) } ?: default
override val skipRegularMode: Boolean = getBoolean("kotlin.js.ir.skipRegularMode")
@@ -52,6 +54,8 @@ abstract class BasicIrBoxTest(
override val runIrPir: Boolean = getBoolean("kotlin.js.ir.pir", true)
val runEs6Mode: Boolean = getBoolean("kotlin.js.ir.es6", false)
// TODO Design incremental compilation for IR and add test support
override val incrementalCompilationChecksEnabled = false
@@ -104,19 +108,20 @@ abstract class BasicIrBoxTest(
if (isMainModule) {
val debugMode = getBoolean("kotlin.js.debugMode")
val phases = if (runEs6Mode) jsEs6Phases else jsPhases
val phaseConfig = if (debugMode) {
val allPhasesSet = jsPhases.toPhaseMap().values.toSet()
val allPhasesSet = phases.toPhaseMap().values.toSet()
val dumpOutputDir = File(outputFile.parent, outputFile.nameWithoutExtension + "-irdump")
println("\n ------ Dumping phases to file://$dumpOutputDir")
PhaseConfig(
jsPhases,
phases,
dumpToDirectory = dumpOutputDir.path,
toDumpStateAfter = allPhasesSet,
toValidateStateAfter = allPhasesSet,
dumpOnlyFqName = null
)
} else {
PhaseConfig(jsPhases)
PhaseConfig(phases)
}
if (!skipRegularMode) {
@@ -131,7 +136,8 @@ abstract class BasicIrBoxTest(
mainArguments = mainCallParameters.run { if (shouldBeGenerated()) arguments() else null },
exportedDeclarations = setOf(FqName.fromSegments(listOfNotNull(testPackage, testFunction))),
generateFullJs = true,
generateDceJs = runIrDce
generateDceJs = runIrDce,
es6mode = runEs6Mode
)
val wrappedCode =
@@ -161,7 +167,8 @@ abstract class BasicIrBoxTest(
friendDependencies = emptyList(),
mainArguments = mainCallParameters.run { if (shouldBeGenerated()) arguments() else null },
exportedDeclarations = setOf(FqName.fromSegments(listOfNotNull(testPackage, testFunction))),
dceDriven = true
dceDriven = true,
es6mode = runEs6Mode
).jsCode!!.let { pirCode ->
val pirWrappedCode = wrapWithModuleEmulationMarkers(pirCode, moduleId = config.moduleId, moduleKind = config.moduleKind)
pirOutputFile.write(pirWrappedCode)
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,139 @@
/*
* 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.js.test.es6.semantics;
import com.intellij.testFramework.TestDataPath;
import org.jetbrains.kotlin.test.JUnit3RunnerWithInners;
import org.jetbrains.kotlin.test.KotlinTestUtils;
import org.jetbrains.kotlin.test.TargetBackend;
import org.jetbrains.kotlin.test.TestMetadata;
import org.junit.runner.RunWith;
import java.io.File;
import java.util.regex.Pattern;
/** This class is generated by {@link org.jetbrains.kotlin.generators.tests.TestsPackage}. DO NOT MODIFY MANUALLY */
@SuppressWarnings("all")
@TestMetadata("js/js.translator/testData/typescript-export")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
public class IrJsTypeScriptExportES6TestGenerated extends AbstractIrJsTypeScriptExportES6Test {
private void runTest(String testDataFilePath) throws Exception {
KotlinTestUtils.runTest0(this::doTest, TargetBackend.JS_IR_ES6, testDataFilePath);
}
public void testAllFilesPresentInTypescript_export() throws Exception {
KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("js/js.translator/testData/typescript-export"), Pattern.compile("^([^_](.+))\\.kt$"), null, TargetBackend.JS_IR_ES6, true);
}
@TestMetadata("js/js.translator/testData/typescript-export/declarations")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
public static class Declarations extends AbstractIrJsTypeScriptExportES6Test {
private void runTest(String testDataFilePath) throws Exception {
KotlinTestUtils.runTest0(this::doTest, TargetBackend.JS_IR_ES6, testDataFilePath);
}
public void testAllFilesPresentInDeclarations() throws Exception {
KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("js/js.translator/testData/typescript-export/declarations"), Pattern.compile("^([^_](.+))\\.kt$"), null, TargetBackend.JS_IR_ES6, true);
}
@TestMetadata("declarations.kt")
public void testDeclarations() throws Exception {
runTest("js/js.translator/testData/typescript-export/declarations/declarations.kt");
}
}
@TestMetadata("js/js.translator/testData/typescript-export/inheritance")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
public static class Inheritance extends AbstractIrJsTypeScriptExportES6Test {
private void runTest(String testDataFilePath) throws Exception {
KotlinTestUtils.runTest0(this::doTest, TargetBackend.JS_IR_ES6, testDataFilePath);
}
public void testAllFilesPresentInInheritance() throws Exception {
KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("js/js.translator/testData/typescript-export/inheritance"), Pattern.compile("^([^_](.+))\\.kt$"), null, TargetBackend.JS_IR_ES6, true);
}
@TestMetadata("inheritance.kt")
public void testInheritance() throws Exception {
runTest("js/js.translator/testData/typescript-export/inheritance/inheritance.kt");
}
}
@TestMetadata("js/js.translator/testData/typescript-export/namespaces")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
public static class Namespaces extends AbstractIrJsTypeScriptExportES6Test {
private void runTest(String testDataFilePath) throws Exception {
KotlinTestUtils.runTest0(this::doTest, TargetBackend.JS_IR_ES6, testDataFilePath);
}
public void testAllFilesPresentInNamespaces() throws Exception {
KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("js/js.translator/testData/typescript-export/namespaces"), Pattern.compile("^([^_](.+))\\.kt$"), null, TargetBackend.JS_IR_ES6, true);
}
@TestMetadata("namespaces.kt")
public void testNamespaces() throws Exception {
runTest("js/js.translator/testData/typescript-export/namespaces/namespaces.kt");
}
}
@TestMetadata("js/js.translator/testData/typescript-export/primitives")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
public static class Primitives extends AbstractIrJsTypeScriptExportES6Test {
private void runTest(String testDataFilePath) throws Exception {
KotlinTestUtils.runTest0(this::doTest, TargetBackend.JS_IR_ES6, testDataFilePath);
}
public void testAllFilesPresentInPrimitives() throws Exception {
KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("js/js.translator/testData/typescript-export/primitives"), Pattern.compile("^([^_](.+))\\.kt$"), null, TargetBackend.JS_IR_ES6, true);
}
@TestMetadata("primitives.kt")
public void testPrimitives() throws Exception {
runTest("js/js.translator/testData/typescript-export/primitives/primitives.kt");
}
}
@TestMetadata("js/js.translator/testData/typescript-export/selectiveExport")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
public static class SelectiveExport extends AbstractIrJsTypeScriptExportES6Test {
private void runTest(String testDataFilePath) throws Exception {
KotlinTestUtils.runTest0(this::doTest, TargetBackend.JS_IR_ES6, testDataFilePath);
}
public void testAllFilesPresentInSelectiveExport() throws Exception {
KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("js/js.translator/testData/typescript-export/selectiveExport"), Pattern.compile("^([^_](.+))\\.kt$"), null, TargetBackend.JS_IR_ES6, true);
}
@TestMetadata("selectiveExport.kt")
public void testSelectiveExport() throws Exception {
runTest("js/js.translator/testData/typescript-export/selectiveExport/selectiveExport.kt");
}
}
@TestMetadata("js/js.translator/testData/typescript-export/visibility")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
public static class Visibility extends AbstractIrJsTypeScriptExportES6Test {
private void runTest(String testDataFilePath) throws Exception {
KotlinTestUtils.runTest0(this::doTest, TargetBackend.JS_IR_ES6, testDataFilePath);
}
public void testAllFilesPresentInVisibility() throws Exception {
KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("js/js.translator/testData/typescript-export/visibility"), Pattern.compile("^([^_](.+))\\.kt$"), null, TargetBackend.JS_IR_ES6, true);
}
@TestMetadata("visibility.kt")
public void testVisibility() throws Exception {
runTest("js/js.translator/testData/typescript-export/visibility/visibility.kt");
}
}
}
@@ -0,0 +1,26 @@
/*
* 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.js.test.es6.semantics
import org.jetbrains.kotlin.js.test.BasicIrBoxES6Test
import org.jetbrains.kotlin.js.test.ir.semantics.AbstractIrJsTypeScriptExportTest
import org.jetbrains.kotlin.test.TargetBackend
abstract class AbstractIrBoxJsES6Test : BasicIrBoxES6Test(TEST_DATA_DIR_PATH + "box/", "irBox/")
abstract class AbstractIrJsCodegenBoxES6Test : BasicIrBoxES6Test(
"compiler/testData/codegen/box/",
"codegen/irBox/"
)
abstract class AbstractIrJsCodegenInlineES6Test : BasicIrBoxES6Test(
"compiler/testData/codegen/boxInline/",
"codegen/irBoxInline/"
)
abstract class AbstractIrJsTypeScriptExportES6Test : AbstractIrJsTypeScriptExportTest(
targetBackend = TargetBackend.JS_IR_ES6
)
@@ -7,15 +7,19 @@ package org.jetbrains.kotlin.js.test.ir.semantics
import org.jetbrains.kotlin.js.test.BasicIrBoxTest
import org.jetbrains.kotlin.test.KotlinTestUtils
import org.jetbrains.kotlin.test.TargetBackend
import org.jetbrains.kotlin.utils.fileUtils.withReplacedExtensionOrNull
import java.io.File
import java.lang.Boolean.getBoolean
@Suppress("ConstantConditionIf")
abstract class AbstractIrJsTypeScriptExportTest : BasicIrBoxTest(
abstract class AbstractIrJsTypeScriptExportTest(
targetBackend: TargetBackend = TargetBackend.JS_IR
) : BasicIrBoxTest(
pathToTestDir = TEST_DATA_DIR_PATH + "typescript-export/",
testGroupOutputDirPrefix = "typescript-export/",
pathToRootOutputDir = TEST_DATA_DIR_PATH
pathToRootOutputDir = TEST_DATA_DIR_PATH,
targetBackend = targetBackend
) {
override val generateDts = true
private val updateReferenceDtsFiles = getBoolean("kotlin.js.updateReferenceDtsFiles")