diff --git a/build.gradle.kts b/build.gradle.kts index c5f9a138c81..950bf12d824 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -699,10 +699,10 @@ tasks { ":kotlin-test:kotlin-test-js-ir:kotlin-test-js-ir-it".takeIf { !kotlinBuildProperties.isInJpsBuildIdeaSync }, ":kotlinx-metadata-jvm", ":tools:binary-compatibility-validator", - ":kotlin-stdlib-wasm", )).forEach { dependsOn("$it:check") } + dependsOn(":kotlin-stdlib-wasm:runWasmStdLibTestsWithD8") //Instead of :kotlin-stdlib-wasm:check } register("gradlePluginTest") { diff --git a/libraries/kotlin.test/wasm/src/main/kotlin/kotlin/test/TeamcityAdapter.kt b/libraries/kotlin.test/wasm/src/main/kotlin/kotlin/test/TeamcityAdapter.kt new file mode 100644 index 00000000000..5fce62dc80c --- /dev/null +++ b/libraries/kotlin.test/wasm/src/main/kotlin/kotlin/test/TeamcityAdapter.kt @@ -0,0 +1,70 @@ +/* + * Copyright 2010-2022 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 kotlin.test + +import kotlin.test.FrameworkAdapter + +internal class TeamcityAdapter : FrameworkAdapter { + private enum class MessageType(val type: String) { + Started("testStarted"), + Finished("testFinished"), + Failed("testFailed"), + Ignored("testIgnored"), + SuiteStarted("testSuiteStarted"), + SuiteFinished("testSuiteFinished"), + } + + private fun String?.tcEscape(): String = this + ?.substring(0, length.coerceAtMost(7000)) + ?.replace("|", "||") + ?.replace("\'", "|'") + ?.replace("\n", "|n") + ?.replace("\r", "|r") + ?.replace("\u0085", "|x") // next line + ?.replace("\u2028", "|l") // line separator + ?.replace("\u2029", "|p") // paragraph separator + ?.replace("[", "|[") + ?.replace("]", "|]") + ?: "" + + private fun MessageType.report(name: String) { + println("##teamcity[$type name='${name.tcEscape()}']") + } + + private fun MessageType.report(name: String, e: Throwable) { + if (this == MessageType.Failed) { + println("##teamcity[$type name='${name.tcEscape()}' message='${e.message.tcEscape()}' details='${e.stackTraceToString().tcEscape()}']") + } else { + println("##teamcity[$type name='${name.tcEscape()}' text='${e.message.tcEscape()}' errorDetails='${e.stackTraceToString().tcEscape()}' status='ERROR']") + } + } + + override fun suite(name: String, ignored: Boolean, suiteFn: () -> Unit) { + MessageType.SuiteStarted.report(name) + if (!ignored) { + try { + suiteFn() + MessageType.SuiteFinished.report(name) + } catch (e: Throwable) { + MessageType.SuiteFinished.report(name, e) + } + } + } + + override fun test(name: String, ignored: Boolean, testFn: () -> Any?) { + if (ignored) { + MessageType.Ignored.report(name) + } else { + try { + MessageType.Started.report(name) + testFn() + MessageType.Finished.report(name) + } catch (e: Throwable) { + MessageType.Failed.report(name, e) + } + } + } +} \ No newline at end of file diff --git a/libraries/kotlin.test/wasm/src/main/kotlin/kotlin/test/TestApi.kt b/libraries/kotlin.test/wasm/src/main/kotlin/kotlin/test/TestApi.kt index a6265e4d02d..816fb062e90 100644 --- a/libraries/kotlin.test/wasm/src/main/kotlin/kotlin/test/TestApi.kt +++ b/libraries/kotlin.test/wasm/src/main/kotlin/kotlin/test/TestApi.kt @@ -37,7 +37,7 @@ internal fun test(name: String, ignored: Boolean, testFn: () -> Any?) { currentAdapter.test(name, ignored, testFn) } -internal var currentAdapter: FrameworkAdapter = JasmineLikeAdapter() +internal var currentAdapter: FrameworkAdapter = TeamcityAdapter() // This is called from the js-launcher alongside wasm start function @JsExport diff --git a/libraries/stdlib/wasm/build.gradle.kts b/libraries/stdlib/wasm/build.gradle.kts index f05f9ecca71..e11677e3a59 100644 --- a/libraries/stdlib/wasm/build.gradle.kts +++ b/libraries/stdlib/wasm/build.gradle.kts @@ -142,8 +142,27 @@ val compileTestKotlinWasm by tasks.existing(KotlinCompile::class) { } } -tasks.named("compileTestDevelopmentExecutableKotlinWasm") { - (this as KotlinCompile<*>).kotlinOptions.freeCompilerArgs += listOf("-Xwasm-enable-array-range-checks", "-Xwasm-enable-asserts") +val compileTestDevelopmentExecutableKotlinWasm = tasks.named("compileTestDevelopmentExecutableKotlinWasm") { + (this as KotlinCompile<*>).kotlinOptions.freeCompilerArgs += listOf("-Xwasm-enable-array-range-checks", "-Xwasm-launcher=d8") +} + +val runWasmStdLibTestsWithD8 by tasks.registering(Exec::class) { + dependsOn(":js:js.tests:unzipV8") + dependsOn(compileTestDevelopmentExecutableKotlinWasm) + + val unzipV8Task = tasks.getByPath(":js:js.tests:unzipV8") + val d8Path = File(unzipV8Task.outputs.files.single(), "d8") + executable = d8Path.toString() + + val compiledFile = compileTestDevelopmentExecutableKotlinWasm + .get() + .kotlinOptions + .outputFile + ?.let { File(it) } + check(compiledFile != null) + + workingDir = compiledFile.parentFile + args = listOf("--experimental-wasm-gc", "--experimental-wasm-eh", "--module", compiledFile.name) } val runtimeElements by configurations.creating {}