mirror of
https://github.com/jlengrand/kotlin.git
synced 2026-05-08 15:53:19 +00:00
This patch mutes the following test categories:
* Tests with java dependencies (System class,
java stdlib, jvm-oriented annotations etc).
* Coroutines tests.
* Reflection tests.
* Tests with an inheritance from the standard
collections.
102 lines
2.2 KiB
Kotlin
Vendored
102 lines
2.2 KiB
Kotlin
Vendored
// IGNORE_BACKEND: NATIVE
|
|
// FILE: 1.kt
|
|
// WITH_RUNTIME
|
|
|
|
class My(val value: Int)
|
|
|
|
inline fun <T, R> T.performWithFinally(job: (T)-> R, finally: (T) -> R) : R {
|
|
try {
|
|
return job(this)
|
|
} finally {
|
|
return finally(this)
|
|
}
|
|
}
|
|
|
|
inline fun <T, R> T.performWithFailFinally(job: (T)-> R, failJob : (e: RuntimeException, T) -> R, finally: (T) -> R) : R {
|
|
try {
|
|
return job(this)
|
|
} catch (e: RuntimeException) {
|
|
return failJob(e, this)
|
|
} finally {
|
|
return finally(this)
|
|
}
|
|
}
|
|
|
|
inline fun String.toInt2() : Int = java.lang.Integer.parseInt(this)
|
|
|
|
// FILE: 2.kt
|
|
|
|
fun test1(): Int {
|
|
|
|
var res = My(111).performWithFinally<My, Int>(
|
|
{
|
|
1
|
|
}, {
|
|
it.value
|
|
})
|
|
return res
|
|
}
|
|
|
|
fun test11(): Int {
|
|
var result = -1;
|
|
val res = My(111).performWithFinally<My, Int>(
|
|
{
|
|
try {
|
|
result = it.value
|
|
throw RuntimeException("1")
|
|
} catch (e: RuntimeException) {
|
|
++result
|
|
throw RuntimeException("2")
|
|
}
|
|
},
|
|
{
|
|
++result
|
|
})
|
|
return res
|
|
}
|
|
|
|
fun test2(): Int {
|
|
var res = My(111).performWithFinally<My, Int>(
|
|
{
|
|
throw RuntimeException("1")
|
|
},
|
|
{
|
|
it.value
|
|
})
|
|
|
|
|
|
return res
|
|
}
|
|
|
|
fun test3(): Int {
|
|
try {
|
|
var result = -1;
|
|
val res = My(111).performWithFailFinally<My, Int>(
|
|
{
|
|
result = it.value;
|
|
throw RuntimeException("-1")
|
|
},
|
|
{ e, z ->
|
|
++result
|
|
throw RuntimeException("-2")
|
|
},
|
|
{
|
|
++result
|
|
})
|
|
return res
|
|
} catch (e: RuntimeException) {
|
|
return e.message?.toInt()!!
|
|
}
|
|
}
|
|
|
|
fun box(): String {
|
|
if (test1() != 111) return "test1: ${test1()}"
|
|
if (test11() != 113) return "test11: ${test11()}"
|
|
|
|
if (test2() != 111) return "test2: ${test2()}"
|
|
|
|
if (test3() != 113) return "test3: ${test3()}"
|
|
|
|
return "OK"
|
|
}
|