File tree 6 files changed +34
-6
lines changed
6 files changed +34
-6
lines changed Original file line number Diff line number Diff line change @@ -13,6 +13,13 @@ import kotlin.test.*
13
13
public expect val isStressTest: Boolean
14
14
public expect val stressTestMultiplier: Int
15
15
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
+
16
23
public expect open class TestBase constructor() {
17
24
/*
18
25
* In common tests we emulate parameterized tests
@@ -33,7 +40,7 @@ public expect open class TestBase constructor() {
33
40
expected : ((Throwable ) -> Boolean )? = null,
34
41
unhandled : List <(Throwable ) -> Boolean > = emptyList(),
35
42
block : suspend CoroutineScope .() -> Unit
36
- )
43
+ ): TestResult
37
44
}
38
45
39
46
public suspend inline fun hang (onCancellation : () -> Unit ) {
Original file line number Diff line number Diff line change @@ -90,5 +90,5 @@ abstract class FlatMapMergeBaseTest : FlatMapBaseTest() {
90
90
}
91
91
92
92
@Test
93
- abstract fun testFlatMapConcurrency ()
93
+ abstract fun testFlatMapConcurrency (): TestResult
94
94
}
Original file line number Diff line number Diff line change @@ -74,4 +74,16 @@ class PromiseTest : TestBase() {
74
74
assertSame(d2, deferred)
75
75
assertEquals(" OK" , d2.await())
76
76
}
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.*
9
9
public actual val isStressTest: Boolean = false
10
10
public actual val stressTestMultiplier: Int = 1
11
11
12
+ @Suppress(" ACTUAL_WITHOUT_EXPECT" , " ACTUAL_TYPE_ALIAS_TO_CLASS_WITH_DECLARATION_SITE_VARIANCE" )
13
+ public actual typealias TestResult = Promise <Unit >
14
+
12
15
public actual open class TestBase actual constructor() {
13
16
public actual val isBoundByJsTestTimeout = true
14
17
private var actionIndex = 0
@@ -77,7 +80,7 @@ public actual open class TestBase actual constructor() {
77
80
expected : ((Throwable ) -> Boolean )? = null,
78
81
unhandled : List <(Throwable ) -> Boolean > = emptyList(),
79
82
block : suspend CoroutineScope .() -> Unit
80
- ): dynamic {
83
+ ): TestResult {
81
84
var exCount = 0
82
85
var ex: Throwable ? = null
83
86
/*
Original file line number Diff line number Diff line change @@ -30,6 +30,9 @@ public actual val stressTestMultiplier = stressTestMultiplierSqrt * stressTestMu
30
30
31
31
public val stressTestMultiplierCbrt = cbrt(stressTestMultiplier.toDouble()).roundToInt()
32
32
33
+ @Suppress(" ACTUAL_WITHOUT_EXPECT" )
34
+ public actual typealias TestResult = Unit
35
+
33
36
/* *
34
37
* Base class for tests, so that tests for predictable scheduling of actions in multiple coroutines sharing a single
35
38
* thread can be written. Use it like this:
@@ -188,7 +191,7 @@ public actual open class TestBase actual constructor() {
188
191
expected : ((Throwable ) -> Boolean )? = null,
189
192
unhandled : List <(Throwable ) -> Boolean > = emptyList(),
190
193
block : suspend CoroutineScope .() -> Unit
191
- ) {
194
+ ): TestResult {
192
195
var exCount = 0
193
196
var ex: Throwable ? = null
194
197
try {
Original file line number Diff line number Diff line change @@ -7,6 +7,9 @@ package kotlinx.coroutines
7
7
public actual val isStressTest: Boolean = false
8
8
public actual val stressTestMultiplier: Int = 1
9
9
10
+ @Suppress(" ACTUAL_WITHOUT_EXPECT" )
11
+ public actual typealias TestResult = Unit
12
+
10
13
public actual open class TestBase actual constructor() {
11
14
public actual val isBoundByJsTestTimeout = false
12
15
private var actionIndex = 0
@@ -71,7 +74,7 @@ public actual open class TestBase actual constructor() {
71
74
expected : ((Throwable ) -> Boolean )? = null,
72
75
unhandled : List <(Throwable ) -> Boolean > = emptyList(),
73
76
block : suspend CoroutineScope .() -> Unit
74
- ) {
77
+ ): TestResult {
75
78
var exCount = 0
76
79
var ex: Throwable ? = null
77
80
try {
You can’t perform that action at this time.
0 commit comments