diff --git a/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/BoxJsTestGenerated.java b/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/BoxJsTestGenerated.java index 3afbfb60ba5..34e7c305b99 100644 --- a/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/BoxJsTestGenerated.java +++ b/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/BoxJsTestGenerated.java @@ -5924,6 +5924,12 @@ public class BoxJsTestGenerated extends AbstractBoxJsTest { doTest(fileName); } + @TestMetadata("returnTestResult.kt") + public void testReturnTestResult() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("js/js.translator/testData/box/kotlin.test/returnTestResult.kt"); + doTest(fileName); + } + @TestMetadata("simple.kt") public void testSimple() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("js/js.translator/testData/box/kotlin.test/simple.kt"); diff --git a/js/js.translator/src/org/jetbrains/kotlin/js/translate/test/JSTestGenerator.kt b/js/js.translator/src/org/jetbrains/kotlin/js/translate/test/JSTestGenerator.kt index 1bc51b58a01..ea6b6046e2d 100644 --- a/js/js.translator/src/org/jetbrains/kotlin/js/translate/test/JSTestGenerator.kt +++ b/js/js.translator/src/org/jetbrains/kotlin/js/translate/test/JSTestGenerator.kt @@ -104,15 +104,18 @@ class JSTestGenerator(val context: TranslationContext) { val classVal = innerContext.defineTemporary(classDescriptor.instance(innerContext)) - fun FunctionDescriptor.buildCall() = CallTranslator.buildCall(context, this, emptyList(), classVal).makeStmt() + fun FunctionDescriptor.buildCall() = CallTranslator.buildCall(context, this, emptyList(), classVal) - functionToTest.body.statements += beforeDescriptors.map { it.buildCall() } + functionToTest.body.statements += beforeDescriptors.map { it.buildCall().makeStmt() } - functionToTest.body.statements += if (afterDescriptors.isEmpty()) { - functionDescriptor.buildCall() + if (afterDescriptors.isEmpty()) { + functionToTest.body.statements += JsReturn(functionDescriptor.buildCall()) } else { - JsTry(JsBlock(functionDescriptor.buildCall()), listOf(), JsBlock(afterDescriptors.map { it.buildCall() })) + functionToTest.body.statements += JsTry( + JsBlock(JsReturn(functionDescriptor.buildCall())), + listOf(), + JsBlock(afterDescriptors.map { it.buildCall().makeStmt() })) } return functionToTest diff --git a/js/js.translator/testData/box/kotlin.test/_common.kt b/js/js.translator/testData/box/kotlin.test/_common.kt index 7afdeb98412..3aa9734f552 100644 --- a/js/js.translator/testData/box/kotlin.test/_common.kt +++ b/js/js.translator/testData/box/kotlin.test/_common.kt @@ -15,8 +15,8 @@ val underscore = kotlin.test.setAdapter(object : FrameworkAdapter { context.suite(name, ignored) { suiteFn() } } - override fun test(name: String, ignored: Boolean, testFn: () -> Unit) { - context.test(name, ignored) { testFn() } + override fun test(name: String, ignored: Boolean, testFn: () -> dynamic) { + context.test(name, ignored) { returned(testFn()) } } }) @@ -58,6 +58,10 @@ class TestContext { record("caught(\"$msg\")") } + fun returned(msg: dynamic) = indent { + if (msg is String) record("returned(\"$msg\")") + } + private fun (TestContext.() -> Unit).runSafely() { try { this() diff --git a/js/js.translator/testData/box/kotlin.test/returnTestResult.kt b/js/js.translator/testData/box/kotlin.test/returnTestResult.kt new file mode 100644 index 00000000000..98744eb8d88 --- /dev/null +++ b/js/js.translator/testData/box/kotlin.test/returnTestResult.kt @@ -0,0 +1,73 @@ +// EXPECTED_REACHABLE_NODES: 1178 +import kotlin.test.Test +import kotlin.test.BeforeTest +import kotlin.test.AfterTest + +open class A { + @Test fun foo(): String { + return "promise" + } + + @Test fun bar() = "future" +} + +interface WithBefore { + @BeforeTest fun before() { + call("before") + } +} + +interface WithAfter { + @AfterTest fun after() { + call("after") + } +} + +class B: A(), WithBefore + +class C: A(), WithAfter + +class D: A(), WithBefore, WithAfter + +fun box() = checkLog { + suite("A") { + test("foo") { + returned("promise") + } + test("bar") { + returned("future") + } + } + suite("B") { + test("foo") { + call("before") + returned("promise") + } + test("bar") { + call("before") + returned("future") + } + } + suite("C") { + test("foo") { + call("after") + returned("promise") + } + test("bar") { + call("after") + returned("future") + } + } + suite("D") { + test("foo") { + call("before") + call("after") + returned("promise") + } + test("bar") { + call("before") + call("after") + returned("future") + } + } +} \ No newline at end of file