Enabled tests with finally blocks on coroutines + added tests

This commit is contained in:
Igor Chevdar
2017-05-03 16:11:18 +05:00
parent 1d9ccb36f3
commit e600c93dfa
4 changed files with 179 additions and 7 deletions
+16 -7
View File
@@ -821,32 +821,41 @@ task coroutines_controlFlow_if2(type: RunKonanTest) {
source = "codegen/coroutines/controlFlow_if2.kt"
}
// Enable after finally blocks lowering.
task coroutines_controlFlow_finally1(type: RunKonanTest) {
disabled = true
goldValue = "f1\ns1\n117\n"
source = "codegen/coroutines/controlFlow_finally1.kt"
}
task coroutines_controlFlow_finally2(type: RunKonanTest) {
disabled = true
goldValue = "f1\ns1\n117\n"
source = "codegen/coroutines/controlFlow_finally2.kt"
}
task coroutines_controlFlow_finally3(type: RunKonanTest) {
disabled = true
goldValue = "f1\ns1\n117\n"
source = "codegen/coroutines/controlFlow_finally3.kt"
}
task coroutines_controlFlow_finally4(type: RunKonanTest) {
disabled = true
goldValue = "s1\nfinally\n117\n"
goldValue = "s1\nfinally\n42\n"
source = "codegen/coroutines/controlFlow_finally4.kt"
}
task coroutines_controlFlow_finally5(type: RunKonanTest) {
goldValue = "s1\nf2\nfinally\n1\n"
source = "codegen/coroutines/controlFlow_finally5.kt"
}
task coroutines_controlFlow_finally6(type: RunKonanTest) {
goldValue = "s1\nfinally\nerror\n0\n"
source = "codegen/coroutines/controlFlow_finally6.kt"
}
task coroutines_controlFlow_finally7(type: RunKonanTest) {
goldValue = "s1\nf2\nfinally1\ns2\nfinally2\n42\n"
source = "codegen/coroutines/controlFlow_finally7.kt"
}
task coroutines_controlFlow_inline1(type: RunKonanTest) {
goldValue = "42\n"
source = "codegen/coroutines/controlFlow_inline1.kt"
@@ -0,0 +1,49 @@
import kotlin.coroutines.experimental.*
import kotlin.coroutines.experimental.intrinsics.*
open class EmptyContinuation(override val context: CoroutineContext = EmptyCoroutineContext) : Continuation<Any?> {
companion object : EmptyContinuation()
override fun resume(value: Any?) {}
override fun resumeWithException(exception: Throwable) { throw exception }
}
suspend fun s1(): Int = suspendCoroutineOrReturn { x ->
println("s1")
x.resumeWithException(Error())
COROUTINE_SUSPENDED
}
fun f1(): Int {
println("f1")
return 117
}
fun f2(): Int {
println("f2")
return 1
}
fun f3(x: Int, y: Int): Int {
println("f3")
return x + y
}
fun builder(c: suspend () -> Unit) {
c.startCoroutine(EmptyContinuation)
}
fun main(args: Array<String>) {
var result = 0
builder {
try {
result = s1()
} catch (t: Throwable) {
result = f2()
} finally {
println("finally")
}
}
println(result)
}
@@ -0,0 +1,54 @@
import kotlin.coroutines.experimental.*
import kotlin.coroutines.experimental.intrinsics.*
open class EmptyContinuation(override val context: CoroutineContext = EmptyCoroutineContext) : Continuation<Any?> {
companion object : EmptyContinuation()
override fun resume(value: Any?) {}
override fun resumeWithException(exception: Throwable) { throw exception }
}
suspend fun s1(): Int = suspendCoroutineOrReturn { x ->
println("s1")
x.resumeWithException(Error("error"))
COROUTINE_SUSPENDED
}
fun f1(): Int {
println("f1")
return 117
}
fun f2(): Int {
println("f2")
return 1
}
fun f3(x: Int, y: Int): Int {
println("f3")
return x + y
}
fun builder(c: suspend () -> Unit) {
c.startCoroutine(EmptyContinuation)
}
fun main(args: Array<String>) {
var result = 0
builder {
try {
try {
result = s1()
} catch (t: ClassCastException) {
result = f2()
} finally {
println("finally")
}
}
catch(t: Error) {
println(t.message)
}
}
println(result)
}
@@ -0,0 +1,60 @@
import kotlin.coroutines.experimental.*
import kotlin.coroutines.experimental.intrinsics.*
open class EmptyContinuation(override val context: CoroutineContext = EmptyCoroutineContext) : Continuation<Any?> {
companion object : EmptyContinuation()
override fun resume(value: Any?) {}
override fun resumeWithException(exception: Throwable) { throw exception }
}
suspend fun s1(): Int = suspendCoroutineOrReturn { x ->
println("s1")
x.resumeWithException(Error())
COROUTINE_SUSPENDED
}
suspend fun s2(): Int = suspendCoroutineOrReturn { x ->
println("s2")
x.resume(42)
COROUTINE_SUSPENDED
}
fun f1(): Int {
println("f1")
return 117
}
fun f2(): Int {
println("f2")
return 1
}
fun f3(x: Int, y: Int): Int {
println("f3")
return x + y
}
fun builder(c: suspend () -> Unit) {
c.startCoroutine(EmptyContinuation)
}
fun main(args: Array<String>) {
var result = 0
builder {
try {
try {
result = s1()
} catch (t: Throwable) {
result = f2()
} finally {
println("finally1")
result = s2()
}
} finally {
println("finally2")
}
}
println(result)
}