File tree Expand file tree Collapse file tree 6 files changed +34
-6
lines changed Expand file tree Collapse file tree 6 files changed +34
-6
lines changed Original file line number Diff line number Diff line change @@ -13,6 +13,13 @@ import kotlin.test.*
1313public expect val isStressTest: Boolean
1414public expect val stressTestMultiplier: Int
1515
16+ /* *
17+ * The result of a multiplatform asynchronous test.
18+ * Aliases into Unit on K/JVM and K/N, and into Promise on K/JS.
19+ */
20+ @Suppress(" NO_ACTUAL_FOR_EXPECT" )
21+ public expect class TestResult
22+
1623public expect open class TestBase constructor() {
1724 /*
1825 * In common tests we emulate parameterized tests
@@ -33,7 +40,7 @@ public expect open class TestBase constructor() {
3340 expected : ((Throwable ) -> Boolean )? = null,
3441 unhandled : List <(Throwable ) -> Boolean > = emptyList(),
3542 block : suspend CoroutineScope .() -> Unit
36- )
43+ ): TestResult
3744}
3845
3946public suspend inline fun hang (onCancellation : () -> Unit ) {
Original file line number Diff line number Diff line change @@ -90,5 +90,5 @@ abstract class FlatMapMergeBaseTest : FlatMapBaseTest() {
9090 }
9191
9292 @Test
93- abstract fun testFlatMapConcurrency ()
93+ abstract fun testFlatMapConcurrency (): TestResult
9494}
Original file line number Diff line number Diff line change @@ -74,4 +74,16 @@ class PromiseTest : TestBase() {
7474 assertSame(d2, deferred)
7575 assertEquals(" OK" , d2.await())
7676 }
77- }
77+
78+ @Test
79+ fun testLeverageTestResult (): TestResult {
80+ // Cannot use expect(..) here
81+ var seq = 0
82+ val result = runTest {
83+ ++ seq
84+ }
85+ return result.then {
86+ if (seq != 1 ) error(" Unexpected result: $seq " )
87+ }
88+ }
89+ }
Original file line number Diff line number Diff line change @@ -9,6 +9,9 @@ import kotlin.js.*
99public actual val isStressTest: Boolean = false
1010public actual val stressTestMultiplier: Int = 1
1111
12+ @Suppress(" ACTUAL_WITHOUT_EXPECT" , " ACTUAL_TYPE_ALIAS_TO_CLASS_WITH_DECLARATION_SITE_VARIANCE" )
13+ public actual typealias TestResult = Promise <Unit >
14+
1215public actual open class TestBase actual constructor() {
1316 public actual val isBoundByJsTestTimeout = true
1417 private var actionIndex = 0
@@ -77,7 +80,7 @@ public actual open class TestBase actual constructor() {
7780 expected : ((Throwable ) -> Boolean )? = null,
7881 unhandled : List <(Throwable ) -> Boolean > = emptyList(),
7982 block : suspend CoroutineScope .() -> Unit
80- ): dynamic {
83+ ): TestResult {
8184 var exCount = 0
8285 var ex: Throwable ? = null
8386 /*
Original file line number Diff line number Diff line change @@ -30,6 +30,9 @@ public actual val stressTestMultiplier = stressTestMultiplierSqrt * stressTestMu
3030
3131public val stressTestMultiplierCbrt = cbrt(stressTestMultiplier.toDouble()).roundToInt()
3232
33+ @Suppress(" ACTUAL_WITHOUT_EXPECT" )
34+ public actual typealias TestResult = Unit
35+
3336/* *
3437 * Base class for tests, so that tests for predictable scheduling of actions in multiple coroutines sharing a single
3538 * thread can be written. Use it like this:
@@ -188,7 +191,7 @@ public actual open class TestBase actual constructor() {
188191 expected : ((Throwable ) -> Boolean )? = null,
189192 unhandled : List <(Throwable ) -> Boolean > = emptyList(),
190193 block : suspend CoroutineScope .() -> Unit
191- ) {
194+ ): TestResult {
192195 var exCount = 0
193196 var ex: Throwable ? = null
194197 try {
Original file line number Diff line number Diff line change @@ -7,6 +7,9 @@ package kotlinx.coroutines
77public actual val isStressTest: Boolean = false
88public actual val stressTestMultiplier: Int = 1
99
10+ @Suppress(" ACTUAL_WITHOUT_EXPECT" )
11+ public actual typealias TestResult = Unit
12+
1013public actual open class TestBase actual constructor() {
1114 public actual val isBoundByJsTestTimeout = false
1215 private var actionIndex = 0
@@ -71,7 +74,7 @@ public actual open class TestBase actual constructor() {
7174 expected : ((Throwable ) -> Boolean )? = null,
7275 unhandled : List <(Throwable ) -> Boolean > = emptyList(),
7376 block : suspend CoroutineScope .() -> Unit
74- ) {
77+ ): TestResult {
7578 var exCount = 0
7679 var ex: Throwable ? = null
7780 try {
You can’t perform that action at this time.
0 commit comments