File tree Expand file tree Collapse file tree 1 file changed +49
-0
lines changed
kotlinx-coroutines-core/src/test/kotlin/kotlinx/coroutines/experimental Expand file tree Collapse file tree 1 file changed +49
-0
lines changed Original file line number Diff line number Diff line change @@ -187,4 +187,53 @@ class CoroutinesTest {
187
187
}
188
188
finish(5 )
189
189
}
190
+
191
+ @Test
192
+ fun testDeferSimple (): Unit = runBlocking {
193
+ expect(1 )
194
+ val d = defer(context) {
195
+ expect(2 )
196
+ 42
197
+ }
198
+ expect(3 )
199
+ check(d.await() == 42 )
200
+ finish(4 )
201
+ }
202
+
203
+ @Test
204
+ fun testDeferAndYield (): Unit = runBlocking {
205
+ expect(1 )
206
+ val d = defer(context) {
207
+ expect(2 )
208
+ yield ()
209
+ expect(4 )
210
+ 42
211
+ }
212
+ expect(3 )
213
+ check(d.await() == 42 )
214
+ finish(5 )
215
+ }
216
+
217
+ @Test(expected = IOException ::class )
218
+ fun testDeferSimpleException (): Unit = runBlocking {
219
+ expect(1 )
220
+ val d = defer(context) {
221
+ expect(2 )
222
+ throw IOException ()
223
+ }
224
+ finish(3 )
225
+ d.await() // will throw IOException
226
+ }
227
+
228
+ @Test(expected = IOException ::class )
229
+ fun testDeferAndYieldException (): Unit = runBlocking {
230
+ expect(1 )
231
+ val d = defer(context) {
232
+ expect(2 )
233
+ yield ()
234
+ throw IOException ()
235
+ }
236
+ finish(3 )
237
+ d.await() // will throw IOException
238
+ }
190
239
}
You can’t perform that action at this time.
0 commit comments