Replace a couple of usages of suspendCoroutineOrReturn in tests
This commit is contained in:
+13
-6
@@ -8,17 +8,22 @@ import COROUTINES_PACKAGE.*
|
|||||||
import COROUTINES_PACKAGE.intrinsics.*
|
import COROUTINES_PACKAGE.intrinsics.*
|
||||||
import kotlin.test.assertEquals
|
import kotlin.test.assertEquals
|
||||||
|
|
||||||
suspend fun suspendHere(): String = suspendCoroutineOrReturn { x ->
|
var callback: () -> Unit = {}
|
||||||
x.resume("OK")
|
|
||||||
COROUTINE_SUSPENDED
|
suspend fun suspendHere(): String = suspendCoroutine { x ->
|
||||||
|
callback = {
|
||||||
|
x.resume("OK")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
suspend fun suspendWithException(): String = suspendCoroutineOrReturn { x ->
|
suspend fun suspendWithException(): String = suspendCoroutine { x ->
|
||||||
x.resumeWithException(RuntimeException("OK"))
|
callback = {
|
||||||
COROUTINE_SUSPENDED
|
x.resumeWithException(RuntimeException("OK"))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun builder(shouldSuspend: Boolean, expectedCount: Int, c: suspend () -> String): String {
|
fun builder(shouldSuspend: Boolean, expectedCount: Int, c: suspend () -> String): String {
|
||||||
|
callback = {}
|
||||||
var fromSuspension: String? = null
|
var fromSuspension: String? = null
|
||||||
var counter = 0
|
var counter = 0
|
||||||
|
|
||||||
@@ -39,6 +44,8 @@ fun builder(shouldSuspend: Boolean, expectedCount: Int, c: suspend () -> String)
|
|||||||
"Exception: ${e.message}"
|
"Exception: ${e.message}"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
callback()
|
||||||
|
|
||||||
if (counter != expectedCount) throw RuntimeException("fail 0")
|
if (counter != expectedCount) throw RuntimeException("fail 0")
|
||||||
|
|
||||||
if (shouldSuspend) {
|
if (shouldSuspend) {
|
||||||
|
|||||||
@@ -9,19 +9,24 @@ import COROUTINES_PACKAGE.*
|
|||||||
import COROUTINES_PACKAGE.intrinsics.*
|
import COROUTINES_PACKAGE.intrinsics.*
|
||||||
|
|
||||||
class Controller {
|
class Controller {
|
||||||
suspend fun suspendHere() = suspendCoroutineOrReturn<String> { x ->
|
var callback: () -> Unit = {}
|
||||||
x.resume("OK")
|
suspend fun suspendHere() = suspendCoroutine<String> { x ->
|
||||||
COROUTINE_SUSPENDED
|
callback = {
|
||||||
|
x.resume("OK")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun builder(c: suspend Controller.() -> Unit) {
|
fun builder(c: suspend Controller.() -> Unit) {
|
||||||
c.startCoroutine(Controller(), object : helpers.ContinuationAdapter<Unit>() {
|
val controller = Controller()
|
||||||
|
c.startCoroutine(controller, object : helpers.ContinuationAdapter<Unit>() {
|
||||||
override val context: CoroutineContext = EmptyCoroutineContext
|
override val context: CoroutineContext = EmptyCoroutineContext
|
||||||
override fun resume(value: Unit) {}
|
override fun resume(value: Unit) {}
|
||||||
|
|
||||||
override fun resumeWithException(exception: Throwable) {}
|
override fun resumeWithException(exception: Throwable) {}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
controller.callback()
|
||||||
}
|
}
|
||||||
|
|
||||||
// FILE: B.kt
|
// FILE: B.kt
|
||||||
|
|||||||
Reference in New Issue
Block a user