Skip to content

Commit f066fe9

Browse files
committed
Actual workaround for missing suspend tests (see KT-22228)
1 parent 9da9e35 commit f066fe9

File tree

3 files changed

+16
-7
lines changed
  • common/kotlinx-coroutines-core-common/src/test/kotlin/kotlinx/coroutines/experimental
  • core/kotlinx-coroutines-core/src/test/kotlin/kotlinx/coroutines/experimental
  • js/kotlinx-coroutines-core-js/src/test/kotlin/kotlinx/coroutines/experimental

3 files changed

+16
-7
lines changed

common/kotlinx-coroutines-core-common/src/test/kotlin/kotlinx/coroutines/experimental/CommonTestBase.kt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,5 +31,9 @@ public expect open class TestBase constructor() {
3131
expected: ((Throwable) -> Boolean)? = null,
3232
unhandled: List<(Throwable) -> Boolean> = emptyList(),
3333
block: suspend CoroutineScope.() -> Unit
34-
)
34+
): TestResult
3535
}
36+
37+
// todo: This is a work-around for missing suspend tests, see KT-22228
38+
@Suppress("NO_ACTUAL_FOR_EXPECT")
39+
expect class TestResult

core/kotlinx-coroutines-core/src/test/kotlin/kotlinx/coroutines/experimental/TestBase.kt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ public actual open class TestBase actual constructor() {
117117
checkTestThreads(threadsBefore)
118118
}
119119

120+
@Suppress("ACTUAL_WITHOUT_EXPECT")
120121
public actual fun runTest(
121122
expected: ((Throwable) -> Boolean)? = null,
122123
unhandled: List<(Throwable) -> Boolean> = emptyList(),
@@ -147,4 +148,7 @@ public actual open class TestBase actual constructor() {
147148
if (exCount < unhandled.size)
148149
error("Too few unhandled exceptions $exCount, expected ${unhandled.size}")
149150
}
150-
}
151+
}
152+
153+
@Suppress("ACTUAL_WITHOUT_EXPECT")
154+
actual typealias TestResult = Unit

js/kotlinx-coroutines-core-js/src/test/kotlin/kotlinx/coroutines/experimental/TestBase.kt

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,10 @@ public actual open class TestBase actual constructor() {
6565
expected: ((Throwable) -> Boolean)? = null,
6666
unhandled: List<(Throwable) -> Boolean> = emptyList(),
6767
block: suspend CoroutineScope.() -> Unit
68-
) {
68+
): TestResult {
6969
var exCount = 0
7070
var ex: Throwable? = null
71-
val promise = promise(block = block, context = CoroutineExceptionHandler { context, e ->
71+
return promise(block = block, context = CoroutineExceptionHandler { context, e ->
7272
if (e is CancellationException) return@CoroutineExceptionHandler // are ignored
7373
exCount++
7474
if (exCount > unhandled.size)
@@ -90,11 +90,12 @@ public actual open class TestBase actual constructor() {
9090
error?.let { throw it }
9191
check(actionIndex == 0 || finished) { "Expecting that 'finish(...)' was invoked, but it was not" }
9292
}
93-
// todo: This is a work-around for missing suspend tests, see KT-22228
94-
@Suppress("UnsafeCastFromDynamic")
95-
return promise.asDynamic()
9693
}
9794
}
9895

9996
private fun <T> Promise<T>.finally(block: () -> Unit): Promise<T> =
10097
then(onFulfilled = { value -> block(); value }, onRejected = { ex -> block(); throw ex })
98+
99+
// todo: This is a work-around for missing suspend tests, see KT-22228
100+
@Suppress("ACTUAL_TYPE_ALIAS_TO_CLASS_WITH_DECLARATION_SITE_VARIANCE", "ACTUAL_WITHOUT_EXPECT")
101+
actual typealias TestResult = Promise<Any?>

0 commit comments

Comments
 (0)