[Wasm] Add box tests for kotlin.test

This commit is contained in:
Igor Laevsky
2021-09-23 21:11:26 +03:00
committed by TeamCityServer
parent 14eee7c539
commit dcdc7e4633
6 changed files with 109 additions and 9 deletions
+3
View File
@@ -346,5 +346,8 @@ projectTest("wasmTest", true) {
dependsOn(":kotlin-stdlib-wasm:compileKotlinJs")
systemProperty("kotlin.wasm.stdlib.path", "libraries/stdlib/wasm/build/classes/kotlin/js/main")
dependsOn(":kotlin-test:kotlin-test-wasm:compileKotlinJs")
systemProperty("kotlin.wasm.kotlin.test.path", "libraries/kotlin.test/wasm/build/classes/kotlin/js/main")
setUpBoxTests()
}
@@ -17,6 +17,7 @@ import org.jetbrains.kotlin.js.test.ir.semantics.*
import org.jetbrains.kotlin.js.test.semantics.*
import org.jetbrains.kotlin.js.test.wasm.semantics.AbstractIrCodegenBoxWasmTest
import org.jetbrains.kotlin.js.test.wasm.semantics.AbstractIrCodegenWasmJsInteropWasmTest
import org.jetbrains.kotlin.js.test.wasm.semantics.AbstractKotlinTestBoxWasmTest
import org.jetbrains.kotlin.test.TargetBackend
fun main(args: Array<String>) {
@@ -31,6 +32,10 @@ fun main(args: Array<String>) {
model("box/", pattern = "^([^_](.+))\\.kt$", targetBackend = TargetBackend.JS)
}
testClass<AbstractKotlinTestBoxWasmTest> {
model("box/kotlin.test/", pattern = "^([^_](.+))\\.kt$", targetBackend = TargetBackend.WASM)
}
testClass<AbstractIrBoxJsTest> {
model("box/", pattern = "^([^_](.+))\\.kt$", targetBackend = TargetBackend.JS_IR)
}
@@ -16,6 +16,7 @@ import org.jetbrains.kotlin.cli.common.messages.AnalyzerWithCompilerReport
import org.jetbrains.kotlin.cli.jvm.compiler.EnvironmentConfigFiles
import org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment
import org.jetbrains.kotlin.config.*
import org.jetbrains.kotlin.idea.KotlinFileType
import org.jetbrains.kotlin.ir.backend.js.loadKlib
import org.jetbrains.kotlin.ir.backend.js.prepareAnalyzedSourceModule
import org.jetbrains.kotlin.ir.backend.js.utils.sanitizeName
@@ -35,9 +36,6 @@ import org.jetbrains.kotlin.test.util.KtTestUtil
import java.io.Closeable
import java.io.File
private val wasmRuntimeKlib =
loadKlib(System.getProperty("kotlin.wasm.stdlib.path"))
abstract class BasicWasmBoxTest(
private val pathToTestDir: String,
testGroupOutputDirPrefix: String,
@@ -47,6 +45,13 @@ abstract class BasicWasmBoxTest(
private val spiderMonkey by lazy { SpiderMonkeyEngine() }
private val COMMON_FILES_NAME = "_common"
@Suppress("UNUSED_PARAMETER")
fun doTestWithCoroutinesPackageReplacement(filePath: String, coroutinesPackage: String) {
TODO("TestWithCoroutinesPackageReplacement are not supported")
}
fun doTest(filePath: String) {
val file = File(filePath)
@@ -81,7 +86,12 @@ abstract class BasicWasmBoxTest(
}
}
val psiFiles = createPsiFiles(kotlinFiles.map { File(it).canonicalPath }.sorted())
val localCommonFile = file.parent + "/" + COMMON_FILES_NAME + "." + KotlinFileType.EXTENSION
val localCommonFiles = if (File(localCommonFile).exists()) listOf(localCommonFile) else emptyList()
val allSourceFiles = kotlinFiles + localCommonFiles
val psiFiles = createPsiFiles(allSourceFiles.map { File(it).canonicalPath }.sorted())
val config = createConfig(languageVersionSettings)
translateFiles(
file,
@@ -159,7 +169,7 @@ abstract class BasicWasmBoxTest(
filesToCompile,
config.configuration,
// TODO: Bypass the resolver fow wasm.
listOf(System.getProperty("kotlin.wasm.stdlib.path")!!),
listOf(System.getProperty("kotlin.wasm.stdlib.path")!!, System.getProperty("kotlin.wasm.kotlin.test.path")!!),
emptyList(),
AnalyzerWithCompilerReport(config.configuration)
)
@@ -15,4 +15,9 @@ abstract class AbstractIrCodegenBoxWasmTest : BasicWasmBoxTest(
abstract class AbstractIrCodegenWasmJsInteropWasmTest : BasicWasmBoxTest(
"compiler/testData/codegen/wasmJsInterop",
"codegen/wasmJsInteropJs"
)
)
abstract class AbstractKotlinTestBoxWasmTest : BasicWasmBoxTest(
"js/js.translator/testData/box/kotlin.test",
"codegen/wasmBoxKotlinTest"
)
@@ -0,0 +1,77 @@
/*
* 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.wasm.semantics;
import com.intellij.testFramework.TestDataPath;
import org.jetbrains.kotlin.test.JUnit3RunnerWithInners;
import org.jetbrains.kotlin.test.KotlinTestUtils;
import org.jetbrains.kotlin.test.util.KtTestUtil;
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/box/kotlin.test")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
public class KotlinTestBoxWasmTestGenerated extends AbstractKotlinTestBoxWasmTest {
private void runTest(String testDataFilePath) throws Exception {
KotlinTestUtils.runTest0(this::doTest, TargetBackend.WASM, testDataFilePath);
}
public void testAllFilesPresentInKotlin_test() throws Exception {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("js/js.translator/testData/box/kotlin.test"), Pattern.compile("^([^_](.+))\\.kt$"), null, TargetBackend.WASM, true);
}
@TestMetadata("beforeAfter.kt")
public void testBeforeAfter() throws Exception {
runTest("js/js.translator/testData/box/kotlin.test/beforeAfter.kt");
}
@TestMetadata("ignore.kt")
public void testIgnore() throws Exception {
runTest("js/js.translator/testData/box/kotlin.test/ignore.kt");
}
@TestMetadata("illegalParameters.kt")
public void testIllegalParameters() throws Exception {
runTest("js/js.translator/testData/box/kotlin.test/illegalParameters.kt");
}
@TestMetadata("incremental.kt")
public void testIncremental() throws Exception {
runTest("js/js.translator/testData/box/kotlin.test/incremental.kt");
}
@TestMetadata("inherited.kt")
public void testInherited() throws Exception {
runTest("js/js.translator/testData/box/kotlin.test/inherited.kt");
}
@TestMetadata("mpp.kt")
public void testMpp() throws Exception {
runTest("js/js.translator/testData/box/kotlin.test/mpp.kt");
}
@TestMetadata("nested.kt")
public void testNested() throws Exception {
runTest("js/js.translator/testData/box/kotlin.test/nested.kt");
}
@TestMetadata("returnTestResult.kt")
public void testReturnTestResult() throws Exception {
runTest("js/js.translator/testData/box/kotlin.test/returnTestResult.kt");
}
@TestMetadata("simple.kt")
public void testSimple() throws Exception {
runTest("js/js.translator/testData/box/kotlin.test/simple.kt");
}
}
+3 -3
View File
@@ -23,7 +23,7 @@ private val underscore = kotlin.test.setAdapter(object : FrameworkAdapter {
sortingContext.suite(name, ignored) { suiteFn() }
}
override fun test(name: String, ignored: Boolean, testFn: () -> dynamic) {
override fun test(name: String, ignored: Boolean, testFn: () -> Any?) {
sortingContext.test(name, ignored) { returned(testFn()) }
}
})
@@ -42,7 +42,7 @@ interface TestBodyContext {
fun caught(msg: String)
fun returned(msg: dynamic)
fun returned(msg: Any?)
}
private sealed class Entity(val name: String,
@@ -126,7 +126,7 @@ private class LoggingContext : SuiteContext, TestBodyContext{
record("caught(\"$msg\")")
}
override fun returned(msg: dynamic) = indent {
override fun returned(msg: Any?) = indent {
if (msg is String) record("returned(\"$msg\")")
}