From 674e5df7f1a0b1b99fb32e8c9e65fec0de18b5b7 Mon Sep 17 00:00:00 2001 From: Alexey Andreev Date: Tue, 1 Nov 2016 14:15:36 +0300 Subject: [PATCH] JS: make coroutine tests cross-platform --- .../box/coroutines/controllerAccessFromInnerLambda.kt | 6 +++--- compiler/testData/codegen/box/coroutines/emptyClosure.kt | 2 +- .../codegen/box/coroutines/handleResultCallEmptyBody.kt | 2 +- .../box/coroutines/handleResultNonUnitExpression.kt | 2 +- compiler/testData/codegen/box/coroutines/illegalState.kt | 1 + .../codegen/box/coroutines/inlineSuspendFunction.kt | 3 ++- .../codegen/box/coroutines/inlinedTryCatchFinally.kt | 6 +++--- .../box/coroutines/intLikeVarSpilling/usedInArrayStore.kt | 1 + .../box/coroutines/intLikeVarSpilling/usedInPutfield.kt | 1 + .../codegen/box/coroutines/lastExpressionIsLoop.kt | 2 +- .../testData/codegen/box/coroutines/lastStatementInc.kt | 6 +++--- .../codegen/box/coroutines/lastStementAssignment.kt | 8 ++++---- .../testData/codegen/box/coroutines/lastUnitExpression.kt | 2 +- .../codegen/box/coroutines/manualContinuationImpl.kt | 2 +- .../codegen/box/coroutines/multipleInvokeCalls.kt | 2 ++ .../coroutines/multipleInvokeCallsInsideInlineLambda1.kt | 2 ++ .../coroutines/multipleInvokeCallsInsideInlineLambda2.kt | 2 ++ .../coroutines/multipleInvokeCallsInsideInlineLambda3.kt | 2 ++ .../testData/codegen/box/coroutines/suspendExtension.kt | 6 +++--- 19 files changed, 35 insertions(+), 23 deletions(-) diff --git a/compiler/testData/codegen/box/coroutines/controllerAccessFromInnerLambda.kt b/compiler/testData/codegen/box/coroutines/controllerAccessFromInnerLambda.kt index b40605fa74f..05d3b54165b 100644 --- a/compiler/testData/codegen/box/coroutines/controllerAccessFromInnerLambda.kt +++ b/compiler/testData/codegen/box/coroutines/controllerAccessFromInnerLambda.kt @@ -12,7 +12,7 @@ class Controller { fun builder(coroutine c: Controller.() -> Continuation) { val controller = Controller() c(controller).resume(Unit) - if (!controller.result) throw java.lang.RuntimeException("fail") + if (!controller.result) throw RuntimeException("fail") } fun noinlineRun(block: () -> Unit) { @@ -22,14 +22,14 @@ fun noinlineRun(block: () -> Unit) { fun box(): String { builder { if (suspendHere() != "OK") { - throw java.lang.RuntimeException("fail 1") + throw RuntimeException("fail 1") } noinlineRun { foo() } if (suspendHere() != "OK") { - throw java.lang.RuntimeException("fail 2") + throw RuntimeException("fail 2") } } diff --git a/compiler/testData/codegen/box/coroutines/emptyClosure.kt b/compiler/testData/codegen/box/coroutines/emptyClosure.kt index 409b9163d2a..9b816123909 100644 --- a/compiler/testData/codegen/box/coroutines/emptyClosure.kt +++ b/compiler/testData/codegen/box/coroutines/emptyClosure.kt @@ -16,7 +16,7 @@ fun box(): String { for (i in 1..3) { builder { - if (suspendHere() != "OK") throw java.lang.RuntimeException("fail 1") + if (suspendHere() != "OK") throw RuntimeException("fail 1") } } diff --git a/compiler/testData/codegen/box/coroutines/handleResultCallEmptyBody.kt b/compiler/testData/codegen/box/coroutines/handleResultCallEmptyBody.kt index a8f72899d7d..10bd07cfc9d 100644 --- a/compiler/testData/codegen/box/coroutines/handleResultCallEmptyBody.kt +++ b/compiler/testData/codegen/box/coroutines/handleResultCallEmptyBody.kt @@ -9,7 +9,7 @@ class Controller { fun builder(coroutine c: Controller.() -> Continuation): String { val controller = Controller() c(controller).resume(Unit) - if (!controller.ok) throw java.lang.RuntimeException("Was not called") + if (!controller.ok) throw RuntimeException("Was not called") return "OK" } diff --git a/compiler/testData/codegen/box/coroutines/handleResultNonUnitExpression.kt b/compiler/testData/codegen/box/coroutines/handleResultNonUnitExpression.kt index 9da50876350..d6ed8c55c99 100644 --- a/compiler/testData/codegen/box/coroutines/handleResultNonUnitExpression.kt +++ b/compiler/testData/codegen/box/coroutines/handleResultNonUnitExpression.kt @@ -12,7 +12,7 @@ class Controller { fun builder(coroutine c: Controller.() -> Continuation) { val controller = Controller() c(controller).resume(Unit) - if (!controller.isCompleted) throw java.lang.RuntimeException("fail") + if (!controller.isCompleted) throw RuntimeException("fail") } fun box(): String { diff --git a/compiler/testData/codegen/box/coroutines/illegalState.kt b/compiler/testData/codegen/box/coroutines/illegalState.kt index 74e22cf5c80..cc2df2cfeff 100644 --- a/compiler/testData/codegen/box/coroutines/illegalState.kt +++ b/compiler/testData/codegen/box/coroutines/illegalState.kt @@ -1,4 +1,5 @@ // WITH_RUNTIME +// TARGET_BACKEND: JVM class Controller { suspend fun suspendHere(x: Continuation) { x.resume(Unit) diff --git a/compiler/testData/codegen/box/coroutines/inlineSuspendFunction.kt b/compiler/testData/codegen/box/coroutines/inlineSuspendFunction.kt index e8d07ad7d16..460610909eb 100644 --- a/compiler/testData/codegen/box/coroutines/inlineSuspendFunction.kt +++ b/compiler/testData/codegen/box/coroutines/inlineSuspendFunction.kt @@ -1,4 +1,5 @@ // WITH_RUNTIME +// WITH_REFLECT class Controller { fun withValue(v: String, x: Continuation) { x.resume(v) @@ -13,7 +14,7 @@ class Controller { } suspend inline fun suspendInline(x: Continuation) { - suspendInline({ T::class.java.simpleName }, x) + suspendInline({ T::class.simpleName!! }, x) } } diff --git a/compiler/testData/codegen/box/coroutines/inlinedTryCatchFinally.kt b/compiler/testData/codegen/box/coroutines/inlinedTryCatchFinally.kt index 34234c06041..7d6dce2651a 100644 --- a/compiler/testData/codegen/box/coroutines/inlinedTryCatchFinally.kt +++ b/compiler/testData/codegen/box/coroutines/inlinedTryCatchFinally.kt @@ -2,7 +2,7 @@ var globalResult = "" var wasCalled = false class Controller { - val postponedActions = java.util.ArrayList<() -> Unit>() + val postponedActions = mutableListOf<() -> Unit>() suspend fun suspendWithValue(v: String, x: Continuation) { postponedActions.add { @@ -62,14 +62,14 @@ fun commonThrow(t: Throwable) { inline fun tryCatch(t: () -> String, onException: (Exception) -> String) = try { t() - } catch (e: java.lang.RuntimeException) { + } catch (e: RuntimeException) { onException(e) } inline fun tryCatchFinally(t: () -> String, onException: (Exception) -> String, f: () -> Unit) = try { t() - } catch (e: java.lang.RuntimeException) { + } catch (e: RuntimeException) { onException(e) } finally { f() diff --git a/compiler/testData/codegen/box/coroutines/intLikeVarSpilling/usedInArrayStore.kt b/compiler/testData/codegen/box/coroutines/intLikeVarSpilling/usedInArrayStore.kt index 866998b14c7..f2265c73a0e 100644 --- a/compiler/testData/codegen/box/coroutines/intLikeVarSpilling/usedInArrayStore.kt +++ b/compiler/testData/codegen/box/coroutines/intLikeVarSpilling/usedInArrayStore.kt @@ -1,4 +1,5 @@ // WITH_RUNTIME +// TARGET_BACKEND: JVM class Controller { suspend fun suspendHere(x: Continuation) { x.resume(Unit) diff --git a/compiler/testData/codegen/box/coroutines/intLikeVarSpilling/usedInPutfield.kt b/compiler/testData/codegen/box/coroutines/intLikeVarSpilling/usedInPutfield.kt index f3996b77b4e..5a996ade0da 100644 --- a/compiler/testData/codegen/box/coroutines/intLikeVarSpilling/usedInPutfield.kt +++ b/compiler/testData/codegen/box/coroutines/intLikeVarSpilling/usedInPutfield.kt @@ -1,4 +1,5 @@ // WITH_RUNTIME +// TARGET_BACKEND: JVM class Controller { suspend fun suspendHere(x: Continuation) { x.resume(Unit) diff --git a/compiler/testData/codegen/box/coroutines/lastExpressionIsLoop.kt b/compiler/testData/codegen/box/coroutines/lastExpressionIsLoop.kt index d5686ab6128..f1ba600cc15 100644 --- a/compiler/testData/codegen/box/coroutines/lastExpressionIsLoop.kt +++ b/compiler/testData/codegen/box/coroutines/lastExpressionIsLoop.kt @@ -14,7 +14,7 @@ class Controller { fun builder(coroutine c: Controller.() -> Continuation): String { val controller = Controller() c(controller).resume(Unit) - if (!controller.ok) throw java.lang.RuntimeException("Fail ok") + if (!controller.ok) throw RuntimeException("Fail ok") return controller.result } diff --git a/compiler/testData/codegen/box/coroutines/lastStatementInc.kt b/compiler/testData/codegen/box/coroutines/lastStatementInc.kt index be98bbc480d..6bbcca3969b 100644 --- a/compiler/testData/codegen/box/coroutines/lastStatementInc.kt +++ b/compiler/testData/codegen/box/coroutines/lastStatementInc.kt @@ -13,7 +13,7 @@ fun builder(coroutine c: Controller.() -> Continuation) { val controller = Controller() c(controller).resume(Unit) - if (!controller.wasHandleResultCalled) throw java.lang.RuntimeException("fail 1") + if (!controller.wasHandleResultCalled) throw RuntimeException("fail 1") } fun box(): String { @@ -22,7 +22,7 @@ fun box(): String { builder { result++ - if (suspendHere() != "OK") throw java.lang.RuntimeException("fail 2") + if (suspendHere() != "OK") throw RuntimeException("fail 2") result-- } @@ -32,7 +32,7 @@ fun box(): String { builder { --result - if (suspendHere() != "OK") throw java.lang.RuntimeException("fail 4") + if (suspendHere() != "OK") throw RuntimeException("fail 4") ++result } diff --git a/compiler/testData/codegen/box/coroutines/lastStementAssignment.kt b/compiler/testData/codegen/box/coroutines/lastStementAssignment.kt index 75e0f914a12..7e8e1388a8a 100644 --- a/compiler/testData/codegen/box/coroutines/lastStementAssignment.kt +++ b/compiler/testData/codegen/box/coroutines/lastStementAssignment.kt @@ -13,12 +13,12 @@ fun builder(coroutine c: Controller.() -> Continuation) { val controller = Controller() c(controller).resume(Unit) - if (!controller.wasHandleResultCalled) throw java.lang.RuntimeException("fail 1") + if (!controller.wasHandleResultCalled) throw RuntimeException("fail 1") } var varWithCustomSetter: String = "" set(value) { - if (field != "") throw java.lang.RuntimeException("fail 2") + if (field != "") throw RuntimeException("fail 2") field = value } @@ -28,7 +28,7 @@ fun box(): String { builder { result += "O" - if (suspendHere() != "OK") throw java.lang.RuntimeException("fail 3") + if (suspendHere() != "OK") throw RuntimeException("fail 3") result += "K" } @@ -36,7 +36,7 @@ fun box(): String { if (result != "OK") return "fail 4" builder { - if (suspendHere() != "OK") throw java.lang.RuntimeException("fail 5") + if (suspendHere() != "OK") throw RuntimeException("fail 5") varWithCustomSetter = "OK" } diff --git a/compiler/testData/codegen/box/coroutines/lastUnitExpression.kt b/compiler/testData/codegen/box/coroutines/lastUnitExpression.kt index fea95ccff0d..de544286406 100644 --- a/compiler/testData/codegen/box/coroutines/lastUnitExpression.kt +++ b/compiler/testData/codegen/box/coroutines/lastUnitExpression.kt @@ -14,7 +14,7 @@ class Controller { fun builder(coroutine c: Controller.() -> Continuation): String { val controller = Controller() c(controller).resume(Unit) - if (!controller.ok) throw java.lang.RuntimeException("Fail 1") + if (!controller.ok) throw RuntimeException("Fail 1") return controller.v } diff --git a/compiler/testData/codegen/box/coroutines/manualContinuationImpl.kt b/compiler/testData/codegen/box/coroutines/manualContinuationImpl.kt index 4709b25fd0e..56e64f70550 100644 --- a/compiler/testData/codegen/box/coroutines/manualContinuationImpl.kt +++ b/compiler/testData/codegen/box/coroutines/manualContinuationImpl.kt @@ -20,7 +20,7 @@ fun box(): String { } if (data != "OK") { - throw java.lang.RuntimeException("fail: $data") + throw RuntimeException("fail: $data") } result = "OK" diff --git a/compiler/testData/codegen/box/coroutines/multipleInvokeCalls.kt b/compiler/testData/codegen/box/coroutines/multipleInvokeCalls.kt index f9a28899110..f442d5e1842 100644 --- a/compiler/testData/codegen/box/coroutines/multipleInvokeCalls.kt +++ b/compiler/testData/codegen/box/coroutines/multipleInvokeCalls.kt @@ -1,3 +1,5 @@ +// TARGET_BACKEND: JVM + class Controller { var lastSuspension: Continuation? = null var result = "fail" diff --git a/compiler/testData/codegen/box/coroutines/multipleInvokeCallsInsideInlineLambda1.kt b/compiler/testData/codegen/box/coroutines/multipleInvokeCallsInsideInlineLambda1.kt index 75a2a71e1d1..90e5221db27 100644 --- a/compiler/testData/codegen/box/coroutines/multipleInvokeCallsInsideInlineLambda1.kt +++ b/compiler/testData/codegen/box/coroutines/multipleInvokeCallsInsideInlineLambda1.kt @@ -1,3 +1,5 @@ +// TARGET_BACKEND: JVM + class Controller { var lastSuspension: Continuation? = null var result = "fail" diff --git a/compiler/testData/codegen/box/coroutines/multipleInvokeCallsInsideInlineLambda2.kt b/compiler/testData/codegen/box/coroutines/multipleInvokeCallsInsideInlineLambda2.kt index d2e93661f23..c7433a098cb 100644 --- a/compiler/testData/codegen/box/coroutines/multipleInvokeCallsInsideInlineLambda2.kt +++ b/compiler/testData/codegen/box/coroutines/multipleInvokeCallsInsideInlineLambda2.kt @@ -1,3 +1,5 @@ +// TARGET_BACKEND: JVM + class Controller { var lastSuspension: Continuation? = null var result = "fail" diff --git a/compiler/testData/codegen/box/coroutines/multipleInvokeCallsInsideInlineLambda3.kt b/compiler/testData/codegen/box/coroutines/multipleInvokeCallsInsideInlineLambda3.kt index a54bf7ae7af..73fd6e2cb1d 100644 --- a/compiler/testData/codegen/box/coroutines/multipleInvokeCallsInsideInlineLambda3.kt +++ b/compiler/testData/codegen/box/coroutines/multipleInvokeCallsInsideInlineLambda3.kt @@ -1,3 +1,5 @@ +// TARGET_BACKEND: JVM + class Controller { var lastSuspension: Continuation? = null var result = "fail" diff --git a/compiler/testData/codegen/box/coroutines/suspendExtension.kt b/compiler/testData/codegen/box/coroutines/suspendExtension.kt index e46bef9323a..6293cfee91b 100644 --- a/compiler/testData/codegen/box/coroutines/suspendExtension.kt +++ b/compiler/testData/codegen/box/coroutines/suspendExtension.kt @@ -25,10 +25,10 @@ fun box(): String { var result = "" builder { - if ("56".suspendHere() != "56") throw java.lang.RuntimeException("fail 1") - if ("28".inlineSuspendHere() != "28") throw java.lang.RuntimeException("fail 2") + if ("56".suspendHere() != "56") throw RuntimeException("fail 1") + if ("28".inlineSuspendHere() != "28") throw RuntimeException("fail 2") - if (suspendExtension("123") != "123") throw java.lang.RuntimeException("fail 3") + if (suspendExtension("123") != "123") throw RuntimeException("fail 3") result = inlineSuspendExtension("OK") }