From dcdc7e4633c4a1a25eda400767ca9f3861d9ccd2 Mon Sep 17 00:00:00 2001 From: Igor Laevsky Date: Thu, 23 Sep 2021 21:11:26 +0300 Subject: [PATCH] [Wasm] Add box tests for kotlin.test --- js/js.tests/build.gradle.kts | 3 + .../generators/tests/GenerateJsTests.kt | 5 ++ .../kotlin/js/test/BasicWasmBoxTest.kt | 20 +++-- .../abstractClassesForGeneratedWasmTests.kt | 7 +- .../KotlinTestBoxWasmTestGenerated.java | 77 +++++++++++++++++++ .../testData/box/kotlin.test/_common.kt | 6 +- 6 files changed, 109 insertions(+), 9 deletions(-) create mode 100644 js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/wasm/semantics/KotlinTestBoxWasmTestGenerated.java diff --git a/js/js.tests/build.gradle.kts b/js/js.tests/build.gradle.kts index 53e57202138..9022562b59d 100644 --- a/js/js.tests/build.gradle.kts +++ b/js/js.tests/build.gradle.kts @@ -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() } 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 6e6c9f1e18d..c6b0e85a1ef 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 @@ -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) { @@ -31,6 +32,10 @@ fun main(args: Array) { model("box/", pattern = "^([^_](.+))\\.kt$", targetBackend = TargetBackend.JS) } + testClass { + model("box/kotlin.test/", pattern = "^([^_](.+))\\.kt$", targetBackend = TargetBackend.WASM) + } + testClass { model("box/", pattern = "^([^_](.+))\\.kt$", targetBackend = TargetBackend.JS_IR) } diff --git a/js/js.tests/test/org/jetbrains/kotlin/js/test/BasicWasmBoxTest.kt b/js/js.tests/test/org/jetbrains/kotlin/js/test/BasicWasmBoxTest.kt index cefc44179e5..ce8717bacbe 100644 --- a/js/js.tests/test/org/jetbrains/kotlin/js/test/BasicWasmBoxTest.kt +++ b/js/js.tests/test/org/jetbrains/kotlin/js/test/BasicWasmBoxTest.kt @@ -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) ) diff --git a/js/js.tests/test/org/jetbrains/kotlin/js/test/wasm/semantics/abstractClassesForGeneratedWasmTests.kt b/js/js.tests/test/org/jetbrains/kotlin/js/test/wasm/semantics/abstractClassesForGeneratedWasmTests.kt index d1c16d1f632..9e61c9ee80f 100644 --- a/js/js.tests/test/org/jetbrains/kotlin/js/test/wasm/semantics/abstractClassesForGeneratedWasmTests.kt +++ b/js/js.tests/test/org/jetbrains/kotlin/js/test/wasm/semantics/abstractClassesForGeneratedWasmTests.kt @@ -15,4 +15,9 @@ abstract class AbstractIrCodegenBoxWasmTest : BasicWasmBoxTest( abstract class AbstractIrCodegenWasmJsInteropWasmTest : BasicWasmBoxTest( "compiler/testData/codegen/wasmJsInterop", "codegen/wasmJsInteropJs" -) \ No newline at end of file +) + +abstract class AbstractKotlinTestBoxWasmTest : BasicWasmBoxTest( + "js/js.translator/testData/box/kotlin.test", + "codegen/wasmBoxKotlinTest" +) diff --git a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/wasm/semantics/KotlinTestBoxWasmTestGenerated.java b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/wasm/semantics/KotlinTestBoxWasmTestGenerated.java new file mode 100644 index 00000000000..09f19cf067f --- /dev/null +++ b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/wasm/semantics/KotlinTestBoxWasmTestGenerated.java @@ -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"); + } +} diff --git a/js/js.translator/testData/box/kotlin.test/_common.kt b/js/js.translator/testData/box/kotlin.test/_common.kt index cec5ded2b45..088a15f37ce 100644 --- a/js/js.translator/testData/box/kotlin.test/_common.kt +++ b/js/js.translator/testData/box/kotlin.test/_common.kt @@ -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\")") }