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>) {
|
fun builder(coroutine c: Controller.() -> Continuation<Unit>) {
|
||||||
val controller = Controller()
|
val controller = Controller()
|
||||||
c(controller).resume(Unit)
|
c(controller).resume(Unit)
|
||||||
if (!controller.result) throw java.lang.RuntimeException("fail")
|
if (!controller.result) throw RuntimeException("fail")
|
||||||
}
|
}
|
||||||
|
|
||||||
fun noinlineRun(block: () -> Unit) {
|
fun noinlineRun(block: () -> Unit) {
|
||||||
@@ -22,14 +22,14 @@ fun noinlineRun(block: () -> Unit) {
|
|||||||
fun box(): String {
|
fun box(): String {
|
||||||
builder {
|
builder {
|
||||||
if (suspendHere() != "OK") {
|
if (suspendHere() != "OK") {
|
||||||
throw java.lang.RuntimeException("fail 1")
|
throw RuntimeException("fail 1")
|
||||||
}
|
}
|
||||||
noinlineRun {
|
noinlineRun {
|
||||||
foo()
|
foo()
|
||||||
}
|
}
|
||||||
|
|
||||||
if (suspendHere() != "OK") {
|
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) {
|
for (i in 1..3) {
|
||||||
builder {
|
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 {
|
fun builder(coroutine c: Controller.() -> Continuation<Unit>): String {
|
||||||
val controller = Controller()
|
val controller = Controller()
|
||||||
c(controller).resume(Unit)
|
c(controller).resume(Unit)
|
||||||
if (!controller.ok) throw java.lang.RuntimeException("Was not called")
|
if (!controller.ok) throw RuntimeException("Was not called")
|
||||||
return "OK"
|
return "OK"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ class Controller {
|
|||||||
fun builder(coroutine c: Controller.() -> Continuation<Unit>) {
|
fun builder(coroutine c: Controller.() -> Continuation<Unit>) {
|
||||||
val controller = Controller()
|
val controller = Controller()
|
||||||
c(controller).resume(Unit)
|
c(controller).resume(Unit)
|
||||||
if (!controller.isCompleted) throw java.lang.RuntimeException("fail")
|
if (!controller.isCompleted) throw RuntimeException("fail")
|
||||||
}
|
}
|
||||||
|
|
||||||
fun box(): String {
|
fun box(): String {
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
// WITH_RUNTIME
|
// WITH_RUNTIME
|
||||||
|
// TARGET_BACKEND: JVM
|
||||||
class Controller {
|
class Controller {
|
||||||
suspend fun suspendHere(x: Continuation<Unit>) {
|
suspend fun suspendHere(x: Continuation<Unit>) {
|
||||||
x.resume(Unit)
|
x.resume(Unit)
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
// WITH_RUNTIME
|
// WITH_RUNTIME
|
||||||
|
// WITH_REFLECT
|
||||||
class Controller {
|
class Controller {
|
||||||
fun withValue(v: String, x: Continuation<String>) {
|
fun withValue(v: String, x: Continuation<String>) {
|
||||||
x.resume(v)
|
x.resume(v)
|
||||||
@@ -13,7 +14,7 @@ class Controller {
|
|||||||
}
|
}
|
||||||
|
|
||||||
suspend inline fun <reified T : Any> suspendInline(x: Continuation<String>) {
|
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 globalResult = ""
|
||||||
var wasCalled = false
|
var wasCalled = false
|
||||||
class Controller {
|
class Controller {
|
||||||
val postponedActions = java.util.ArrayList<() -> Unit>()
|
val postponedActions = mutableListOf<() -> Unit>()
|
||||||
|
|
||||||
suspend fun suspendWithValue(v: String, x: Continuation<String>) {
|
suspend fun suspendWithValue(v: String, x: Continuation<String>) {
|
||||||
postponedActions.add {
|
postponedActions.add {
|
||||||
@@ -62,14 +62,14 @@ fun commonThrow(t: Throwable) {
|
|||||||
inline fun tryCatch(t: () -> String, onException: (Exception) -> String) =
|
inline fun tryCatch(t: () -> String, onException: (Exception) -> String) =
|
||||||
try {
|
try {
|
||||||
t()
|
t()
|
||||||
} catch (e: java.lang.RuntimeException) {
|
} catch (e: RuntimeException) {
|
||||||
onException(e)
|
onException(e)
|
||||||
}
|
}
|
||||||
|
|
||||||
inline fun tryCatchFinally(t: () -> String, onException: (Exception) -> String, f: () -> Unit) =
|
inline fun tryCatchFinally(t: () -> String, onException: (Exception) -> String, f: () -> Unit) =
|
||||||
try {
|
try {
|
||||||
t()
|
t()
|
||||||
} catch (e: java.lang.RuntimeException) {
|
} catch (e: RuntimeException) {
|
||||||
onException(e)
|
onException(e)
|
||||||
} finally {
|
} finally {
|
||||||
f()
|
f()
|
||||||
|
|||||||
+1
@@ -1,4 +1,5 @@
|
|||||||
// WITH_RUNTIME
|
// WITH_RUNTIME
|
||||||
|
// TARGET_BACKEND: JVM
|
||||||
class Controller {
|
class Controller {
|
||||||
suspend fun suspendHere(x: Continuation<Unit>) {
|
suspend fun suspendHere(x: Continuation<Unit>) {
|
||||||
x.resume(Unit)
|
x.resume(Unit)
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
// WITH_RUNTIME
|
// WITH_RUNTIME
|
||||||
|
// TARGET_BACKEND: JVM
|
||||||
class Controller {
|
class Controller {
|
||||||
suspend fun suspendHere(x: Continuation<Unit>) {
|
suspend fun suspendHere(x: Continuation<Unit>) {
|
||||||
x.resume(Unit)
|
x.resume(Unit)
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ class Controller {
|
|||||||
fun builder(coroutine c: Controller.() -> Continuation<Unit>): String {
|
fun builder(coroutine c: Controller.() -> Continuation<Unit>): String {
|
||||||
val controller = Controller()
|
val controller = Controller()
|
||||||
c(controller).resume(Unit)
|
c(controller).resume(Unit)
|
||||||
if (!controller.ok) throw java.lang.RuntimeException("Fail ok")
|
if (!controller.ok) throw RuntimeException("Fail ok")
|
||||||
return controller.result
|
return controller.result
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ fun builder(coroutine c: Controller.() -> Continuation<Unit>) {
|
|||||||
val controller = Controller()
|
val controller = Controller()
|
||||||
c(controller).resume(Unit)
|
c(controller).resume(Unit)
|
||||||
|
|
||||||
if (!controller.wasHandleResultCalled) throw java.lang.RuntimeException("fail 1")
|
if (!controller.wasHandleResultCalled) throw RuntimeException("fail 1")
|
||||||
}
|
}
|
||||||
|
|
||||||
fun box(): String {
|
fun box(): String {
|
||||||
@@ -22,7 +22,7 @@ fun box(): String {
|
|||||||
builder {
|
builder {
|
||||||
result++
|
result++
|
||||||
|
|
||||||
if (suspendHere() != "OK") throw java.lang.RuntimeException("fail 2")
|
if (suspendHere() != "OK") throw RuntimeException("fail 2")
|
||||||
|
|
||||||
result--
|
result--
|
||||||
}
|
}
|
||||||
@@ -32,7 +32,7 @@ fun box(): String {
|
|||||||
builder {
|
builder {
|
||||||
--result
|
--result
|
||||||
|
|
||||||
if (suspendHere() != "OK") throw java.lang.RuntimeException("fail 4")
|
if (suspendHere() != "OK") throw RuntimeException("fail 4")
|
||||||
|
|
||||||
++result
|
++result
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,12 +13,12 @@ fun builder(coroutine c: Controller.() -> Continuation<Unit>) {
|
|||||||
val controller = Controller()
|
val controller = Controller()
|
||||||
c(controller).resume(Unit)
|
c(controller).resume(Unit)
|
||||||
|
|
||||||
if (!controller.wasHandleResultCalled) throw java.lang.RuntimeException("fail 1")
|
if (!controller.wasHandleResultCalled) throw RuntimeException("fail 1")
|
||||||
}
|
}
|
||||||
|
|
||||||
var varWithCustomSetter: String = ""
|
var varWithCustomSetter: String = ""
|
||||||
set(value) {
|
set(value) {
|
||||||
if (field != "") throw java.lang.RuntimeException("fail 2")
|
if (field != "") throw RuntimeException("fail 2")
|
||||||
field = value
|
field = value
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -28,7 +28,7 @@ fun box(): String {
|
|||||||
builder {
|
builder {
|
||||||
result += "O"
|
result += "O"
|
||||||
|
|
||||||
if (suspendHere() != "OK") throw java.lang.RuntimeException("fail 3")
|
if (suspendHere() != "OK") throw RuntimeException("fail 3")
|
||||||
|
|
||||||
result += "K"
|
result += "K"
|
||||||
}
|
}
|
||||||
@@ -36,7 +36,7 @@ fun box(): String {
|
|||||||
if (result != "OK") return "fail 4"
|
if (result != "OK") return "fail 4"
|
||||||
|
|
||||||
builder {
|
builder {
|
||||||
if (suspendHere() != "OK") throw java.lang.RuntimeException("fail 5")
|
if (suspendHere() != "OK") throw RuntimeException("fail 5")
|
||||||
|
|
||||||
varWithCustomSetter = "OK"
|
varWithCustomSetter = "OK"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ class Controller {
|
|||||||
fun builder(coroutine c: Controller.() -> Continuation<Unit>): String {
|
fun builder(coroutine c: Controller.() -> Continuation<Unit>): String {
|
||||||
val controller = Controller()
|
val controller = Controller()
|
||||||
c(controller).resume(Unit)
|
c(controller).resume(Unit)
|
||||||
if (!controller.ok) throw java.lang.RuntimeException("Fail 1")
|
if (!controller.ok) throw RuntimeException("Fail 1")
|
||||||
return controller.v
|
return controller.v
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ fun box(): String {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (data != "OK") {
|
if (data != "OK") {
|
||||||
throw java.lang.RuntimeException("fail: $data")
|
throw RuntimeException("fail: $data")
|
||||||
}
|
}
|
||||||
|
|
||||||
result = "OK"
|
result = "OK"
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
// TARGET_BACKEND: JVM
|
||||||
|
|
||||||
class Controller {
|
class Controller {
|
||||||
var lastSuspension: Continuation<String>? = null
|
var lastSuspension: Continuation<String>? = null
|
||||||
var result = "fail"
|
var result = "fail"
|
||||||
|
|||||||
+2
@@ -1,3 +1,5 @@
|
|||||||
|
// TARGET_BACKEND: JVM
|
||||||
|
|
||||||
class Controller {
|
class Controller {
|
||||||
var lastSuspension: Continuation<String>? = null
|
var lastSuspension: Continuation<String>? = null
|
||||||
var result = "fail"
|
var result = "fail"
|
||||||
|
|||||||
+2
@@ -1,3 +1,5 @@
|
|||||||
|
// TARGET_BACKEND: JVM
|
||||||
|
|
||||||
class Controller {
|
class Controller {
|
||||||
var lastSuspension: Continuation<String>? = null
|
var lastSuspension: Continuation<String>? = null
|
||||||
var result = "fail"
|
var result = "fail"
|
||||||
|
|||||||
+2
@@ -1,3 +1,5 @@
|
|||||||
|
// TARGET_BACKEND: JVM
|
||||||
|
|
||||||
class Controller {
|
class Controller {
|
||||||
var lastSuspension: Continuation<String>? = null
|
var lastSuspension: Continuation<String>? = null
|
||||||
var result = "fail"
|
var result = "fail"
|
||||||
|
|||||||
@@ -25,10 +25,10 @@ fun box(): String {
|
|||||||
var result = ""
|
var result = ""
|
||||||
|
|
||||||
builder {
|
builder {
|
||||||
if ("56".suspendHere() != "56") throw java.lang.RuntimeException("fail 1")
|
if ("56".suspendHere() != "56") throw RuntimeException("fail 1")
|
||||||
if ("28".inlineSuspendHere() != "28") throw java.lang.RuntimeException("fail 2")
|
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")
|
result = inlineSuspendExtension("OK")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user