JS: make coroutine tests cross-platform
This commit is contained in:
+3
-3
@@ -12,7 +12,7 @@ class Controller {
|
||||
fun builder(coroutine c: Controller.() -> Continuation<Unit>) {
|
||||
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")
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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")
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@ class Controller {
|
||||
fun builder(coroutine c: Controller.() -> Continuation<Unit>): 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"
|
||||
}
|
||||
|
||||
|
||||
@@ -12,7 +12,7 @@ class Controller {
|
||||
fun builder(coroutine c: Controller.() -> Continuation<Unit>) {
|
||||
val controller = Controller()
|
||||
c(controller).resume(Unit)
|
||||
if (!controller.isCompleted) throw java.lang.RuntimeException("fail")
|
||||
if (!controller.isCompleted) throw RuntimeException("fail")
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
// WITH_RUNTIME
|
||||
// TARGET_BACKEND: JVM
|
||||
class Controller {
|
||||
suspend fun suspendHere(x: Continuation<Unit>) {
|
||||
x.resume(Unit)
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
// WITH_RUNTIME
|
||||
// WITH_REFLECT
|
||||
class Controller {
|
||||
fun withValue(v: String, x: Continuation<String>) {
|
||||
x.resume(v)
|
||||
@@ -13,7 +14,7 @@ class Controller {
|
||||
}
|
||||
|
||||
suspend inline fun <reified T : Any> suspendInline(x: Continuation<String>) {
|
||||
suspendInline({ T::class.java.simpleName }, x)
|
||||
suspendInline({ T::class.simpleName!! }, x)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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<String>) {
|
||||
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()
|
||||
|
||||
+1
@@ -1,4 +1,5 @@
|
||||
// WITH_RUNTIME
|
||||
// TARGET_BACKEND: JVM
|
||||
class Controller {
|
||||
suspend fun suspendHere(x: Continuation<Unit>) {
|
||||
x.resume(Unit)
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
// WITH_RUNTIME
|
||||
// TARGET_BACKEND: JVM
|
||||
class Controller {
|
||||
suspend fun suspendHere(x: Continuation<Unit>) {
|
||||
x.resume(Unit)
|
||||
|
||||
@@ -14,7 +14,7 @@ class Controller {
|
||||
fun builder(coroutine c: Controller.() -> Continuation<Unit>): 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
|
||||
}
|
||||
|
||||
|
||||
@@ -13,7 +13,7 @@ fun builder(coroutine c: Controller.() -> Continuation<Unit>) {
|
||||
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
|
||||
}
|
||||
|
||||
@@ -13,12 +13,12 @@ fun builder(coroutine c: Controller.() -> Continuation<Unit>) {
|
||||
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"
|
||||
}
|
||||
|
||||
@@ -14,7 +14,7 @@ class Controller {
|
||||
fun builder(coroutine c: Controller.() -> Continuation<Unit>): 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
|
||||
}
|
||||
|
||||
|
||||
@@ -20,7 +20,7 @@ fun box(): String {
|
||||
}
|
||||
|
||||
if (data != "OK") {
|
||||
throw java.lang.RuntimeException("fail: $data")
|
||||
throw RuntimeException("fail: $data")
|
||||
}
|
||||
|
||||
result = "OK"
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
// TARGET_BACKEND: JVM
|
||||
|
||||
class Controller {
|
||||
var lastSuspension: Continuation<String>? = null
|
||||
var result = "fail"
|
||||
|
||||
+2
@@ -1,3 +1,5 @@
|
||||
// TARGET_BACKEND: JVM
|
||||
|
||||
class Controller {
|
||||
var lastSuspension: Continuation<String>? = null
|
||||
var result = "fail"
|
||||
|
||||
+2
@@ -1,3 +1,5 @@
|
||||
// TARGET_BACKEND: JVM
|
||||
|
||||
class Controller {
|
||||
var lastSuspension: Continuation<String>? = null
|
||||
var result = "fail"
|
||||
|
||||
+2
@@ -1,3 +1,5 @@
|
||||
// TARGET_BACKEND: JVM
|
||||
|
||||
class Controller {
|
||||
var lastSuspension: Continuation<String>? = null
|
||||
var result = "fail"
|
||||
|
||||
@@ -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")
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user