8
8
package kotlinx.coroutines.test
9
9
10
10
import kotlinx.coroutines.*
11
- import kotlinx.coroutines.selects.*
12
11
import kotlin.coroutines.*
13
12
import kotlin.jvm.*
14
13
@@ -137,9 +136,9 @@ public fun runTestWithLegacyScope(
137
136
): TestResult {
138
137
if (context[RunningInRunTest ] != null )
139
138
throw IllegalStateException (" Calls to `runTest` can't be nested. Please read the docs on `TestResult` for details." )
140
- val testScope = TestBodyCoroutine < Unit > (createTestCoroutineScope(context + RunningInRunTest ))
139
+ val testScope = TestBodyCoroutine (createTestCoroutineScope(context + RunningInRunTest ))
141
140
return createTestResult {
142
- runTestCoroutine(testScope, dispatchTimeoutMs, testBody) {
141
+ runTestCoroutine(testScope, dispatchTimeoutMs, TestBodyCoroutine ::tryGetCompletionCause, testBody) {
143
142
try {
144
143
testScope.cleanup()
145
144
emptyList()
@@ -169,9 +168,9 @@ public fun TestCoroutineScope.runTest(
169
168
block : suspend TestCoroutineScope .() -> Unit
170
169
): TestResult = runTestWithLegacyScope(coroutineContext, dispatchTimeoutMs, block)
171
170
172
- private class TestBodyCoroutine < T > (
171
+ private class TestBodyCoroutine (
173
172
private val testScope : TestCoroutineScope ,
174
- ) : AbstractCoroutine<T >(testScope.coroutineContext, initParentJob = true , active = true ), TestCoroutineScope {
173
+ ) : AbstractCoroutine<Unit >(testScope.coroutineContext, initParentJob = true , active = true ), TestCoroutineScope {
175
174
176
175
override val testScheduler get() = testScope.testScheduler
177
176
@@ -187,4 +186,7 @@ private class TestBodyCoroutine<T>(
187
186
)
188
187
189
188
fun cleanup () = testScope.cleanupTestCoroutines()
189
+
190
+ /* * Throws an exception if the coroutine is not completing. */
191
+ fun tryGetCompletionCause (): Throwable ? = completionCause
190
192
}
0 commit comments