[K/N][Tests] Adjust moved codegen tests to new infra

^KT-61259
This commit is contained in:
Vladimir Sukharev
2023-12-12 17:06:31 +01:00
committed by Space Team
parent a5f3d5b737
commit e15068c62f
301 changed files with 2958 additions and 2382 deletions
@@ -3,8 +3,6 @@
* that can be found in the LICENSE file.
*/
package codegen.coroutines.anonymousObject
import kotlin.test.*
import kotlin.coroutines.*
@@ -41,10 +39,14 @@ fun create() = object: I {
}
}
@Test fun runTest() {
fun box(): String {
val sb = StringBuilder()
builder {
val z = create()
z.foo { suspendHere(); println(it) }
z.foo { suspendHere(); sb.append(it) }
z.bar("zzz")
}
assertEquals("zzz", sb.toString())
return "OK"
}
@@ -1 +0,0 @@
zzz
@@ -3,8 +3,6 @@
* that can be found in the LICENSE file.
*/
package codegen.coroutines.controlFlow_chain
import kotlin.test.*
import kotlin.coroutines.*
@@ -25,13 +23,14 @@ fun builder(c: suspend () -> Unit) {
}
// See https://github.com/JetBrains/kotlin-native/issues/3476
@Test fun runTest() {
fun box(): String {
var result = 0
builder {
foo().bar()
result = 1
}
assertEquals(1, result)
return "OK"
}
class Foo {
@@ -3,36 +3,36 @@
* that can be found in the LICENSE file.
*/
package codegen.coroutines.controlFlow_finally1
import kotlin.test.*
import kotlin.coroutines.*
import kotlin.coroutines.intrinsics.*
val sb = StringBuilder()
open class EmptyContinuation(override val context: CoroutineContext = EmptyCoroutineContext) : Continuation<Any?> {
companion object : EmptyContinuation()
override fun resumeWith(result: Result<Any?>) { result.getOrThrow() }
}
suspend fun s1(): Int = suspendCoroutineUninterceptedOrReturn { x ->
println("s1")
sb.appendLine("s1")
x.resume(42)
COROUTINE_SUSPENDED
}
fun f1(): Int {
println("f1")
sb.appendLine("f1")
return 117
}
fun f2(): Int {
println("f2")
sb.appendLine("f2")
return 1
}
fun f3(x: Int, y: Int): Int {
println("f3")
sb.appendLine("f3")
return x + y
}
@@ -40,7 +40,7 @@ fun builder(c: suspend () -> Unit) {
c.startCoroutine(EmptyContinuation)
}
@Test fun runTest() {
fun box(): String {
var result = 0
builder {
@@ -53,5 +53,12 @@ fun builder(c: suspend () -> Unit) {
}
}
println(result)
sb.appendLine(result)
assertEquals("""
f1
s1
117
""".trimIndent(), sb.toString())
return "OK"
}
@@ -1,3 +0,0 @@
f1
s1
117
@@ -3,36 +3,36 @@
* that can be found in the LICENSE file.
*/
package codegen.coroutines.controlFlow_finally2
import kotlin.test.*
import kotlin.coroutines.*
import kotlin.coroutines.intrinsics.*
val sb = StringBuilder()
open class EmptyContinuation(override val context: CoroutineContext = EmptyCoroutineContext) : Continuation<Any?> {
companion object : EmptyContinuation()
override fun resumeWith(result: Result<Any?>) { result.getOrThrow() }
}
suspend fun s1(): Int = suspendCoroutineUninterceptedOrReturn { x ->
println("s1")
sb.appendLine("s1")
x.resume(42)
COROUTINE_SUSPENDED
}
fun f1(): Int {
println("f1")
sb.appendLine("f1")
return 117
}
fun f2(): Int {
println("f2")
sb.appendLine("f2")
return 1
}
fun f3(x: Int, y: Int): Int {
println("f3")
sb.appendLine("f3")
return x + y
}
@@ -40,7 +40,7 @@ fun builder(c: suspend () -> Unit) {
c.startCoroutine(EmptyContinuation)
}
@Test fun runTest() {
fun box(): String {
var result = 0
builder {
@@ -54,5 +54,14 @@ fun builder(c: suspend () -> Unit) {
result = x
}
println(result)
sb.appendLine(result)
assertEquals("""
f1
s1
117
""".trimIndent(), sb.toString())
return "OK"
}
@@ -1,3 +0,0 @@
f1
s1
117
@@ -3,36 +3,36 @@
* that can be found in the LICENSE file.
*/
package codegen.coroutines.controlFlow_finally3
import kotlin.test.*
import kotlin.coroutines.*
import kotlin.coroutines.intrinsics.*
val sb = StringBuilder()
open class EmptyContinuation(override val context: CoroutineContext = EmptyCoroutineContext) : Continuation<Any?> {
companion object : EmptyContinuation()
override fun resumeWith(result: Result<Any?>) { result.getOrThrow() }
}
suspend fun s1(): Int = suspendCoroutineUninterceptedOrReturn { x ->
println("s1")
sb.appendLine("s1")
x.resume(42)
COROUTINE_SUSPENDED
}
fun f1(): Int {
println("f1")
sb.appendLine("f1")
return 117
}
fun f2(): Int {
println("f2")
sb.appendLine("f2")
return 1
}
fun f3(x: Int, y: Int): Int {
println("f3")
sb.appendLine("f3")
return x + y
}
@@ -40,7 +40,7 @@ fun builder(c: suspend () -> Unit) {
c.startCoroutine(EmptyContinuation)
}
@Test fun runTest() {
fun box(): String {
var result = 0
builder {
@@ -53,5 +53,14 @@ fun builder(c: suspend () -> Unit) {
}
}
println(result)
sb.appendLine(result)
assertEquals("""
f1
s1
117
""".trimIndent(), sb.toString())
return "OK"
}
@@ -1,3 +0,0 @@
f1
s1
117
@@ -3,36 +3,36 @@
* that can be found in the LICENSE file.
*/
package codegen.coroutines.controlFlow_finally4
import kotlin.test.*
import kotlin.coroutines.*
import kotlin.coroutines.intrinsics.*
val sb = StringBuilder()
open class EmptyContinuation(override val context: CoroutineContext = EmptyCoroutineContext) : Continuation<Any?> {
companion object : EmptyContinuation()
override fun resumeWith(result: Result<Any?>) { result.getOrThrow() }
}
suspend fun s1(): Int = suspendCoroutineUninterceptedOrReturn { x ->
println("s1")
sb.appendLine("s1")
x.resume(42)
COROUTINE_SUSPENDED
}
fun f1(): Int {
println("f1")
sb.appendLine("f1")
return 117
}
fun f2(): Int {
println("f2")
sb.appendLine("f2")
return 1
}
fun f3(x: Int, y: Int): Int {
println("f3")
sb.appendLine("f3")
return x + y
}
@@ -40,7 +40,7 @@ fun builder(c: suspend () -> Unit) {
c.startCoroutine(EmptyContinuation)
}
@Test fun runTest() {
fun box(): String {
var result = 0
builder {
@@ -49,9 +49,18 @@ fun builder(c: suspend () -> Unit) {
} catch (t: Throwable) {
result = f2()
} finally {
println("finally")
sb.appendLine("finally")
}
}
println(result)
sb.appendLine(result)
assertEquals("""
s1
finally
42
""".trimIndent(), sb.toString())
return "OK"
}
@@ -1,3 +0,0 @@
s1
finally
42
@@ -3,36 +3,36 @@
* that can be found in the LICENSE file.
*/
package codegen.coroutines.controlFlow_finally5
import kotlin.test.*
import kotlin.coroutines.*
import kotlin.coroutines.intrinsics.*
val sb = StringBuilder()
open class EmptyContinuation(override val context: CoroutineContext = EmptyCoroutineContext) : Continuation<Any?> {
companion object : EmptyContinuation()
override fun resumeWith(result: Result<Any?>) { result.getOrThrow() }
}
suspend fun s1(): Int = suspendCoroutineUninterceptedOrReturn { x ->
println("s1")
sb.appendLine("s1")
x.resumeWithException(Error())
COROUTINE_SUSPENDED
}
fun f1(): Int {
println("f1")
sb.appendLine("f1")
return 117
}
fun f2(): Int {
println("f2")
sb.appendLine("f2")
return 1
}
fun f3(x: Int, y: Int): Int {
println("f3")
sb.appendLine("f3")
return x + y
}
@@ -40,7 +40,7 @@ fun builder(c: suspend () -> Unit) {
c.startCoroutine(EmptyContinuation)
}
@Test fun runTest() {
fun box(): String {
var result = 0
builder {
@@ -49,9 +49,19 @@ fun builder(c: suspend () -> Unit) {
} catch (t: Throwable) {
result = f2()
} finally {
println("finally")
sb.appendLine("finally")
}
}
println(result)
sb.appendLine(result)
assertEquals("""
s1
f2
finally
1
""".trimIndent(), sb.toString())
return "OK"
}
@@ -1,4 +0,0 @@
s1
f2
finally
1
@@ -3,36 +3,36 @@
* that can be found in the LICENSE file.
*/
package codegen.coroutines.controlFlow_finally6
import kotlin.test.*
import kotlin.coroutines.*
import kotlin.coroutines.intrinsics.*
val sb = StringBuilder()
open class EmptyContinuation(override val context: CoroutineContext = EmptyCoroutineContext) : Continuation<Any?> {
companion object : EmptyContinuation()
override fun resumeWith(result: Result<Any?>) { result.getOrThrow() }
}
suspend fun s1(): Int = suspendCoroutineUninterceptedOrReturn { x ->
println("s1")
sb.appendLine("s1")
x.resumeWithException(Error("error"))
COROUTINE_SUSPENDED
}
fun f1(): Int {
println("f1")
sb.appendLine("f1")
return 117
}
fun f2(): Int {
println("f2")
sb.appendLine("f2")
return 1
}
fun f3(x: Int, y: Int): Int {
println("f3")
sb.appendLine("f3")
return x + y
}
@@ -40,7 +40,7 @@ fun builder(c: suspend () -> Unit) {
c.startCoroutine(EmptyContinuation)
}
@Test fun runTest() {
fun box(): String {
var result = 0
builder {
@@ -50,13 +50,23 @@ fun builder(c: suspend () -> Unit) {
} catch (t: ClassCastException) {
result = f2()
} finally {
println("finally")
sb.appendLine("finally")
}
}
catch(t: Error) {
println(t.message)
sb.appendLine(t.message)
}
}
println(result)
sb.appendLine(result)
assertEquals("""
s1
finally
error
0
""".trimIndent(), sb.toString())
return "OK"
}
@@ -1,4 +0,0 @@
s1
finally
error
0
@@ -3,42 +3,42 @@
* that can be found in the LICENSE file.
*/
package codegen.coroutines.controlFlow_finally7
import kotlin.test.*
import kotlin.coroutines.*
import kotlin.coroutines.intrinsics.*
val sb = StringBuilder()
open class EmptyContinuation(override val context: CoroutineContext = EmptyCoroutineContext) : Continuation<Any?> {
companion object : EmptyContinuation()
override fun resumeWith(result: Result<Any?>) { result.getOrThrow() }
}
suspend fun s1(): Int = suspendCoroutineUninterceptedOrReturn { x ->
println("s1")
sb.appendLine("s1")
x.resumeWithException(Error())
COROUTINE_SUSPENDED
}
suspend fun s2(): Int = suspendCoroutineUninterceptedOrReturn { x ->
println("s2")
sb.appendLine("s2")
x.resume(42)
COROUTINE_SUSPENDED
}
fun f1(): Int {
println("f1")
sb.appendLine("f1")
return 117
}
fun f2(): Int {
println("f2")
sb.appendLine("f2")
return 1
}
fun f3(x: Int, y: Int): Int {
println("f3")
sb.appendLine("f3")
return x + y
}
@@ -46,7 +46,7 @@ fun builder(c: suspend () -> Unit) {
c.startCoroutine(EmptyContinuation)
}
@Test fun runTest() {
fun box(): String {
var result = 0
builder {
@@ -56,13 +56,25 @@ fun builder(c: suspend () -> Unit) {
} catch (t: Throwable) {
result = f2()
} finally {
println("finally1")
sb.appendLine("finally1")
result = s2()
}
} finally {
println("finally2")
sb.appendLine("finally2")
}
}
println(result)
sb.appendLine(result)
assertEquals("""
s1
f2
finally1
s2
finally2
42
""".trimIndent(), sb.toString())
return "OK"
}
@@ -1,6 +0,0 @@
s1
f2
finally1
s2
finally2
42
@@ -3,36 +3,36 @@
* that can be found in the LICENSE file.
*/
package codegen.coroutines.controlFlow_if1
import kotlin.test.*
import kotlin.coroutines.*
import kotlin.coroutines.intrinsics.*
val sb = StringBuilder()
open class EmptyContinuation(override val context: CoroutineContext = EmptyCoroutineContext) : Continuation<Any?> {
companion object : EmptyContinuation()
override fun resumeWith(result: Result<Any?>) { result.getOrThrow() }
}
suspend fun s1(): Int = suspendCoroutineUninterceptedOrReturn { x ->
println("s1")
sb.appendLine("s1")
x.resume(42)
COROUTINE_SUSPENDED
}
fun f1(): Int {
println("f1")
sb.appendLine("f1")
return 117
}
fun f2(): Int {
println("f2")
sb.appendLine("f2")
return 1
}
fun f3(x: Int, y: Int): Int {
println("f3")
sb.appendLine("f3")
return x + y
}
@@ -40,12 +40,22 @@ fun builder(c: suspend () -> Unit) {
c.startCoroutine(EmptyContinuation)
}
@Test fun runTest() {
fun box(): String {
var result = 0
builder {
result = f3(if (f1() > 100) s1() else f2(), 42)
}
println(result)
sb.appendLine(result)
assertEquals("""
f1
s1
f3
84
""".trimIndent(), sb.toString())
return "OK"
}
@@ -1,4 +0,0 @@
f1
s1
f3
84
@@ -3,36 +3,36 @@
* that can be found in the LICENSE file.
*/
package codegen.coroutines.controlFlow_if2
import kotlin.test.*
import kotlin.coroutines.*
import kotlin.coroutines.intrinsics.*
val sb = StringBuilder()
open class EmptyContinuation(override val context: CoroutineContext = EmptyCoroutineContext) : Continuation<Any?> {
companion object : EmptyContinuation()
override fun resumeWith(result: Result<Any?>) { result.getOrThrow() }
}
suspend fun s1(): Int = suspendCoroutineUninterceptedOrReturn { x ->
println("s1")
sb.appendLine("s1")
x.resume(42)
COROUTINE_SUSPENDED
}
fun f1(): Int {
println("f1")
sb.appendLine("f1")
return 117
}
fun f2(): Int {
println("f2")
sb.appendLine("f2")
return 1
}
fun f3(x: Int, y: Int): Int {
println("f3")
sb.appendLine("f3")
return x + y
}
@@ -40,7 +40,7 @@ fun builder(c: suspend () -> Unit) {
c.startCoroutine(EmptyContinuation)
}
@Test fun runTest() {
fun box(): String {
var result = 0
builder {
@@ -50,5 +50,15 @@ fun builder(c: suspend () -> Unit) {
result = 42
}
println(result)
sb.appendLine(result)
assertEquals("""
f1
s1
f2
43
""".trimIndent(), sb.toString())
return "OK"
}
@@ -1,4 +0,0 @@
f1
s1
f2
43
@@ -3,20 +3,20 @@
* that can be found in the LICENSE file.
*/
package codegen.coroutines.controlFlow_inline1
import kotlin.test.*
import kotlin.coroutines.*
import kotlin.coroutines.intrinsics.*
val sb = StringBuilder()
open class EmptyContinuation(override val context: CoroutineContext = EmptyCoroutineContext) : Continuation<Any?> {
companion object : EmptyContinuation()
override fun resumeWith(result: Result<Any?>) { result.getOrThrow() }
}
suspend fun s1(): Int = suspendCoroutineUninterceptedOrReturn { x ->
println("s1")
sb.appendLine("s1")
x.resume(42)
COROUTINE_SUSPENDED
}
@@ -29,12 +29,15 @@ inline suspend fun inline_s2(): Int {
return 42
}
@Test fun runTest() {
fun box(): String {
var result = 0
builder {
result = inline_s2()
}
println(result)
sb.appendLine(result)
assertEquals("42\n", sb.toString())
return "OK"
}
@@ -1 +0,0 @@
42
@@ -3,20 +3,20 @@
* that can be found in the LICENSE file.
*/
package codegen.coroutines.controlFlow_inline2
import kotlin.test.*
import kotlin.coroutines.*
import kotlin.coroutines.intrinsics.*
val sb = StringBuilder()
open class EmptyContinuation(override val context: CoroutineContext = EmptyCoroutineContext) : Continuation<Any?> {
companion object : EmptyContinuation()
override fun resumeWith(result: Result<Any?>) { result.getOrThrow() }
}
suspend fun s1(): Int = suspendCoroutineUninterceptedOrReturn { x ->
println("s1")
sb.appendLine("s1")
x.resume(42)
COROUTINE_SUSPENDED
}
@@ -30,12 +30,19 @@ inline suspend fun inline_s2(): Int {
return x
}
@Test fun runTest() {
fun box(): String {
var result = 0
builder {
result = inline_s2()
}
println(result)
sb.appendLine(result)
assertEquals("""
s1
42
""".trimIndent(), sb.toString())
return "OK"
}
@@ -1,2 +0,0 @@
s1
42
@@ -3,20 +3,20 @@
* that can be found in the LICENSE file.
*/
package codegen.coroutines.controlFlow_inline3
import kotlin.test.*
import kotlin.coroutines.*
import kotlin.coroutines.intrinsics.*
val sb = StringBuilder()
open class EmptyContinuation(override val context: CoroutineContext = EmptyCoroutineContext) : Continuation<Any?> {
companion object : EmptyContinuation()
override fun resumeWith(result: Result<Any?>) { result.getOrThrow() }
}
suspend fun s1(): Int = suspendCoroutineUninterceptedOrReturn { x ->
println("s1")
sb.appendLine("s1")
x.resume(42)
COROUTINE_SUSPENDED
}
@@ -26,12 +26,12 @@ fun builder(c: suspend () -> Unit) {
}
fun f1(): Int {
println("f1")
sb.appendLine("f1")
return 117
}
fun f2(): Int {
println("f2")
sb.appendLine("f2")
return 1
}
@@ -43,12 +43,20 @@ inline suspend fun inline_s2(): Int {
return x
}
@Test fun runTest() {
fun box(): String {
var result = 0
builder {
result = inline_s2()
}
println(result)
sb.appendLine(result)
assertEquals("""
f1
s1
42
""".trimIndent(), sb.toString())
return "OK"
}
@@ -1,3 +0,0 @@
f1
s1
42
@@ -3,36 +3,36 @@
* that can be found in the LICENSE file.
*/
package codegen.coroutines.controlFlow_tryCatch1
import kotlin.test.*
import kotlin.coroutines.*
import kotlin.coroutines.intrinsics.*
val sb = StringBuilder()
open class EmptyContinuation(override val context: CoroutineContext = EmptyCoroutineContext) : Continuation<Any?> {
companion object : EmptyContinuation()
override fun resumeWith(result: Result<Any?>) { result.getOrThrow() }
}
suspend fun s1(): Int = suspendCoroutineUninterceptedOrReturn { x ->
println("s1")
sb.appendLine("s1")
x.resume(42)
COROUTINE_SUSPENDED
}
fun f1(): Int {
println("f1")
sb.appendLine("f1")
return 117
}
fun f2(): Int {
println("f2")
sb.appendLine("f2")
return 1
}
fun f3(x: Int, y: Int): Int {
println("f3")
sb.appendLine("f3")
return x + y
}
@@ -40,7 +40,7 @@ fun builder(c: suspend () -> Unit) {
c.startCoroutine(EmptyContinuation)
}
@Test fun runTest() {
fun box(): String {
var result = 0
builder {
@@ -52,5 +52,12 @@ fun builder(c: suspend () -> Unit) {
result = x
}
println(result)
sb.appendLine(result)
assertEquals("""
s1
42
""".trimIndent(), sb.toString())
return "OK"
}
@@ -1,2 +0,0 @@
s1
42
@@ -3,36 +3,36 @@
* that can be found in the LICENSE file.
*/
package codegen.coroutines.controlFlow_tryCatch2
import kotlin.test.*
import kotlin.coroutines.*
import kotlin.coroutines.intrinsics.*
val sb = StringBuilder()
open class EmptyContinuation(override val context: CoroutineContext = EmptyCoroutineContext) : Continuation<Any?> {
companion object : EmptyContinuation()
override fun resumeWith(result: Result<Any?>) { result.getOrThrow() }
}
suspend fun s1(): Int = suspendCoroutineUninterceptedOrReturn { x ->
println("s1")
sb.appendLine("s1")
x.resume(42)
COROUTINE_SUSPENDED
}
fun f1(): Int {
println("f1")
sb.appendLine("f1")
return 117
}
fun f2(): Int {
println("f2")
sb.appendLine("f2")
return 1
}
fun f3(x: Int, y: Int): Int {
println("f3")
sb.appendLine("f3")
return x + y
}
@@ -40,7 +40,7 @@ fun builder(c: suspend () -> Unit) {
c.startCoroutine(EmptyContinuation)
}
@Test fun runTest() {
fun box(): String {
var result = 0
builder {
@@ -51,5 +51,12 @@ fun builder(c: suspend () -> Unit) {
}
}
println(result)
sb.appendLine(result)
assertEquals("""
s1
42
""".trimIndent(), sb.toString())
return "OK"
}
@@ -1,2 +0,0 @@
s1
42
@@ -3,42 +3,42 @@
* that can be found in the LICENSE file.
*/
package codegen.coroutines.controlFlow_tryCatch3
import kotlin.test.*
import kotlin.coroutines.*
import kotlin.coroutines.intrinsics.*
val sb = StringBuilder()
open class EmptyContinuation(override val context: CoroutineContext = EmptyCoroutineContext) : Continuation<Any?> {
companion object : EmptyContinuation()
override fun resumeWith(result: Result<Any?>) { result.getOrThrow() }
}
suspend fun s1(): Int = suspendCoroutineUninterceptedOrReturn { x ->
println("s1")
sb.appendLine("s1")
x.resume(42)
COROUTINE_SUSPENDED
}
suspend fun s2(): Int = suspendCoroutineUninterceptedOrReturn { x ->
println("s2")
sb.appendLine("s2")
x.resumeWithException(Error())
COROUTINE_SUSPENDED
}
fun f1(): Int {
println("f1")
sb.appendLine("f1")
return 117
}
fun f2(): Int {
println("f2")
sb.appendLine("f2")
return 1
}
fun f3(x: Int, y: Int): Int {
println("f3")
sb.appendLine("f3")
return x + y
}
@@ -46,7 +46,7 @@ fun builder(c: suspend () -> Unit) {
c.startCoroutine(EmptyContinuation)
}
@Test fun runTest() {
fun box(): String {
var result = 0
builder {
@@ -57,5 +57,13 @@ fun builder(c: suspend () -> Unit) {
}
}
println(result)
sb.appendLine(result)
assertEquals("""
s2
f2
1
""".trimIndent(), sb.toString())
return "OK"
}
@@ -1,3 +0,0 @@
s2
f2
1
@@ -3,42 +3,42 @@
* that can be found in the LICENSE file.
*/
package codegen.coroutines.controlFlow_tryCatch4
import kotlin.test.*
import kotlin.coroutines.*
import kotlin.coroutines.intrinsics.*
val sb = StringBuilder()
open class EmptyContinuation(override val context: CoroutineContext = EmptyCoroutineContext) : Continuation<Any?> {
companion object : EmptyContinuation()
override fun resumeWith(result: Result<Any?>) { result.getOrThrow() }
}
suspend fun s1(): Int = suspendCoroutineUninterceptedOrReturn { x ->
println("s1")
sb.appendLine("s1")
x.resume(42)
COROUTINE_SUSPENDED
}
suspend fun s2(): Int = suspendCoroutineUninterceptedOrReturn { x ->
println("s2")
sb.appendLine("s2")
x.resumeWithException(Error())
COROUTINE_SUSPENDED
}
fun f1(): Int {
println("f1")
sb.appendLine("f1")
return 117
}
fun f2(): Int {
println("f2")
sb.appendLine("f2")
return 1
}
fun f3(x: Int, y: Int): Int {
println("f3")
sb.appendLine("f3")
return x + y
}
@@ -46,7 +46,7 @@ fun builder(c: suspend () -> Unit) {
c.startCoroutine(EmptyContinuation)
}
@Test fun runTest() {
fun box(): String {
var result = 0
builder {
@@ -58,5 +58,13 @@ fun builder(c: suspend () -> Unit) {
result = x
}
println(result)
sb.appendLine(result)
assertEquals("""
s2
f2
1
""".trimIndent(), sb.toString())
return "OK"
}
@@ -1,3 +0,0 @@
s2
f2
1
@@ -3,42 +3,42 @@
* that can be found in the LICENSE file.
*/
package codegen.coroutines.controlFlow_tryCatch5
import kotlin.test.*
import kotlin.coroutines.*
import kotlin.coroutines.intrinsics.*
val sb = StringBuilder()
open class EmptyContinuation(override val context: CoroutineContext = EmptyCoroutineContext) : Continuation<Any?> {
companion object : EmptyContinuation()
override fun resumeWith(result: Result<Any?>) { result.getOrThrow() }
}
suspend fun s1(): Int = suspendCoroutineUninterceptedOrReturn { x ->
println("s1")
sb.appendLine("s1")
x.resume(42)
COROUTINE_SUSPENDED
}
suspend fun s2(): Int = suspendCoroutineUninterceptedOrReturn { x ->
println("s2")
sb.appendLine("s2")
x.resumeWithException(Error("Error"))
COROUTINE_SUSPENDED
}
fun f1(): Int {
println("f1")
sb.appendLine("f1")
return 117
}
fun f2(): Int {
println("f2")
sb.appendLine("f2")
return 1
}
fun f3(x: Int, y: Int): Int {
println("f3")
sb.appendLine("f3")
return x + y
}
@@ -46,7 +46,7 @@ fun builder(c: suspend () -> Unit) {
c.startCoroutine(EmptyContinuation)
}
@Test fun runTest() {
fun box(): String {
var result = 0
builder {
@@ -54,10 +54,19 @@ fun builder(c: suspend () -> Unit) {
s2()
} catch (t: Throwable) {
val x = s1()
println(t.message)
sb.appendLine(t.message)
x
}
}
println(result)
sb.appendLine(result)
assertEquals("""
s2
s1
Error
42
""".trimIndent(), sb.toString())
return "OK"
}
@@ -1,4 +0,0 @@
s2
s1
Error
42
@@ -3,48 +3,48 @@
* that can be found in the LICENSE file.
*/
package codegen.coroutines.controlFlow_while1
import kotlin.test.*
import kotlin.coroutines.*
import kotlin.coroutines.intrinsics.*
val sb = StringBuilder()
open class EmptyContinuation(override val context: CoroutineContext = EmptyCoroutineContext) : Continuation<Any?> {
companion object : EmptyContinuation()
override fun resumeWith(result: Result<Any?>) { result.getOrThrow() }
}
suspend fun s1(): Int = suspendCoroutineUninterceptedOrReturn { x ->
println("s1")
sb.appendLine("s1")
x.resume(42)
COROUTINE_SUSPENDED
}
suspend fun s2(): Int = suspendCoroutineUninterceptedOrReturn { x ->
println("s2")
sb.appendLine("s2")
x.resumeWithException(Error("Error"))
COROUTINE_SUSPENDED
}
suspend fun s3(value: Int): Int = suspendCoroutineUninterceptedOrReturn { x ->
println("s3")
sb.appendLine("s3")
x.resume(value)
COROUTINE_SUSPENDED
}
fun f1(): Int {
println("f1")
sb.appendLine("f1")
return 117
}
fun f2(): Int {
println("f2")
sb.appendLine("f2")
return 1
}
fun f3(x: Int, y: Int): Int {
println("f3")
sb.appendLine("f3")
return x + y
}
@@ -52,7 +52,7 @@ fun builder(c: suspend () -> Unit) {
c.startCoroutine(EmptyContinuation)
}
@Test fun runTest() {
fun box(): String {
var result = 0
builder {
@@ -60,5 +60,15 @@ fun builder(c: suspend () -> Unit) {
++result
}
println(result)
sb.appendLine(result)
assertEquals("""
s3
s3
s3
s3
3
""".trimIndent(), sb.toString())
return "OK"
}
@@ -1,5 +0,0 @@
s3
s3
s3
s3
3
@@ -3,48 +3,48 @@
* that can be found in the LICENSE file.
*/
package codegen.coroutines.controlFlow_while2
import kotlin.test.*
import kotlin.coroutines.*
import kotlin.coroutines.intrinsics.*
val sb = StringBuilder()
open class EmptyContinuation(override val context: CoroutineContext = EmptyCoroutineContext) : Continuation<Any?> {
companion object : EmptyContinuation()
override fun resumeWith(result: Result<Any?>) { result.getOrThrow() }
}
suspend fun s1(): Int = suspendCoroutineUninterceptedOrReturn { x ->
println("s1")
sb.appendLine("s1")
x.resume(42)
COROUTINE_SUSPENDED
}
suspend fun s2(): Int = suspendCoroutineUninterceptedOrReturn { x ->
println("s2")
sb.appendLine("s2")
x.resumeWithException(Error("Error"))
COROUTINE_SUSPENDED
}
suspend fun s3(value: Int): Int = suspendCoroutineUninterceptedOrReturn { x ->
println("s3")
sb.appendLine("s3")
x.resume(value)
COROUTINE_SUSPENDED
}
fun f1(): Int {
println("f1")
sb.appendLine("f1")
return 117
}
fun f2(): Int {
println("f2")
sb.appendLine("f2")
return 1
}
fun f3(x: Int, y: Int): Int {
println("f3")
sb.appendLine("f3")
return x + y
}
@@ -52,7 +52,7 @@ fun builder(c: suspend () -> Unit) {
c.startCoroutine(EmptyContinuation)
}
@Test fun runTest() {
fun box(): String {
var result = 0
builder {
@@ -60,5 +60,14 @@ fun builder(c: suspend () -> Unit) {
result = s3(result) + 1
}
println(result)
sb.appendLine(result)
assertEquals("""
s3
s3
s3
3
""".trimIndent(), sb.toString())
return "OK"
}
@@ -1,4 +0,0 @@
s3
s3
s3
3
@@ -3,13 +3,13 @@
* that can be found in the LICENSE file.
*/
package codegen.coroutines.coroutineContext1
import kotlin.test.*
import kotlin.coroutines.*
import kotlin.coroutines.intrinsics.*
val sb = StringBuilder()
open class EmptyContinuation(override val context: CoroutineContext = EmptyCoroutineContext) : Continuation<Any?> {
companion object : EmptyContinuation()
override fun resumeWith(result: Result<Any?>) { result.getOrThrow() }
@@ -19,6 +19,12 @@ fun builder(c: suspend () -> Unit) {
c.startCoroutine(EmptyContinuation)
}
@Test fun runTest() {
builder { println(coroutineContext) }
fun box(): String {
builder { sb.appendLine(coroutineContext) }
assertEquals("""
EmptyCoroutineContext
""".trimIndent(), sb.toString())
return "OK"
}
@@ -1 +0,0 @@
EmptyCoroutineContext
@@ -3,13 +3,13 @@
* that can be found in the LICENSE file.
*/
package codegen.coroutines.coroutineContext2
import kotlin.test.*
import kotlin.coroutines.*
import kotlin.coroutines.intrinsics.*
val sb = StringBuilder()
open class EmptyContinuation(override val context: CoroutineContext = EmptyCoroutineContext) : Continuation<Any?> {
companion object : EmptyContinuation()
override fun resumeWith(result: Result<Any?>) { result.getOrThrow() }
@@ -21,6 +21,12 @@ fun builder(c: suspend () -> Unit) {
suspend fun foo() = coroutineContext
@Test fun runTest() {
builder { println(foo()) }
fun box(): String {
builder { sb.appendLine(foo()) }
assertEquals("""
EmptyCoroutineContext
""".trimIndent(), sb.toString())
return "OK"
}
@@ -1 +0,0 @@
EmptyCoroutineContext
@@ -3,31 +3,31 @@
* that can be found in the LICENSE file.
*/
package codegen.coroutines.correctOrder1
import kotlin.test.*
import kotlin.coroutines.*
import kotlin.coroutines.intrinsics.*
val sb = StringBuilder()
open class EmptyContinuation(override val context: CoroutineContext = EmptyCoroutineContext) : Continuation<Any?> {
companion object : EmptyContinuation()
override fun resumeWith(result: Result<Any?>) { result.getOrThrow() }
}
suspend fun s1(): Int = suspendCoroutineUninterceptedOrReturn { x ->
println("s1")
sb.appendLine("s1")
x.resume(42)
COROUTINE_SUSPENDED
}
fun f1(): Int {
println("f1")
sb.appendLine("f1")
return 117
}
fun f2(): Int {
println("f2")
sb.appendLine("f2")
return 1
}
@@ -35,12 +35,21 @@ fun builder(c: suspend () -> Unit) {
c.startCoroutine(EmptyContinuation)
}
@Test fun runTest() {
fun box(): String {
var result = 0
builder {
result = f1() + s1() + f2()
}
println(result)
sb.appendLine(result)
assertEquals("""
f1
s1
f2
160
""".trimIndent(), sb.toString())
return "OK"
}
@@ -1,4 +0,0 @@
f1
s1
f2
160
@@ -3,28 +3,34 @@
* that can be found in the LICENSE file.
*/
package codegen.coroutines.degenerate1
import kotlin.test.*
import kotlin.coroutines.*
import kotlin.coroutines.intrinsics.*
val sb = StringBuilder()
open class EmptyContinuation(override val context: CoroutineContext = EmptyCoroutineContext) : Continuation<Any?> {
companion object : EmptyContinuation()
override fun resumeWith(result: Result<Any?>) { result.getOrThrow() }
}
suspend fun s1() {
println("s1")
sb.appendLine("s1")
}
fun builder(c: suspend () -> Unit) {
c.startCoroutine(EmptyContinuation)
}
@Test fun runTest() {
fun box(): String {
builder {
s1()
}
assertEquals("""
s1
""".trimIndent(), sb.toString())
return "OK"
}
@@ -1 +0,0 @@
s1
@@ -3,26 +3,26 @@
* that can be found in the LICENSE file.
*/
package codegen.coroutines.degenerate2
import kotlin.test.*
import kotlin.coroutines.*
import kotlin.coroutines.intrinsics.*
val sb = StringBuilder()
open class EmptyContinuation(override val context: CoroutineContext = EmptyCoroutineContext) : Continuation<Any?> {
companion object : EmptyContinuation()
override fun resumeWith(result: Result<Any?>) { result.getOrThrow() }
}
suspend fun s1(): Unit = suspendCoroutineUninterceptedOrReturn { x ->
println("s1")
sb.appendLine("s1")
x.resume(Unit)
COROUTINE_SUSPENDED
}
suspend fun s2() {
println("s2")
sb.appendLine("s2")
s1()
}
@@ -30,8 +30,15 @@ fun builder(c: suspend () -> Unit) {
c.startCoroutine(EmptyContinuation)
}
@Test fun runTest() {
fun box(): String {
builder {
s2()
}
assertEquals("""
s2
s1
""".trimIndent(), sb.toString())
return "OK"
}
@@ -1,2 +0,0 @@
s2
s1
@@ -3,17 +3,17 @@
* that can be found in the LICENSE file.
*/
package codegen.coroutines.functionReference_eqeq_name
import kotlin.test.*
val sb = StringBuilder()
suspend fun foo(x: Int) = x
class Foo(val x: Int) {
suspend fun bar() = x
}
@Test fun runTest() {
fun box(): String {
val ref1 = ::foo
val rec = Foo(42)
val ref2 = rec::bar
@@ -29,4 +29,6 @@ class Foo(val x: Int) {
assertFalse(ref2 == ref4)
assertTrue(ref2 == ref5)
assertFalse(ref6 == ref2)
return "OK"
}
@@ -3,13 +3,13 @@
* that can be found in the LICENSE file.
*/
package codegen.coroutines.functionReference_invokeAsFunction
import kotlin.test.*
import kotlin.coroutines.*
import kotlin.coroutines.intrinsics.*
val sb = StringBuilder()
open class EmptyContinuation(override val context: CoroutineContext = EmptyCoroutineContext) : Continuation<Any?> {
companion object : EmptyContinuation()
override fun resumeWith(result: Result<Any?>) { result.getOrThrow() }
@@ -21,8 +21,14 @@ class Foo(val x: Int) {
suspend fun foo(x: Int) = x
@Test fun runTest() {
fun box(): String {
val ref = Foo(42)::bar
println((ref as Function2<Int, Continuation<Int>, Any?>)(117, EmptyContinuation))
sb.appendLine((ref as Function2<Int, Continuation<Int>, Any?>)(117, EmptyContinuation))
assertEquals("""
159
""".trimIndent(), sb.toString())
return "OK"
}
@@ -3,8 +3,6 @@
* that can be found in the LICENSE file.
*/
package codegen.coroutines.functionReference_lambdaAsSuspendLambda
import kotlin.test.*
import kotlin.coroutines.*
@@ -14,6 +12,8 @@ fun foo(block: (Continuation<Unit>) -> Any?) {
block as (suspend () -> Unit)
}
@Test fun runTest() {
fun box(): String {
foo {}
return "OK"
}
@@ -3,8 +3,6 @@
* that can be found in the LICENSE file.
*/
package codegen.coroutines.functionReference_simple
import kotlin.test.*
import kotlin.coroutines.*
@@ -26,7 +24,7 @@ fun builder(c: suspend () -> Unit) {
c.startCoroutine(EmptyContinuation)
}
@Test fun runTest() {
fun box(): String {
var result = 0
val ref = ::suspendHere
@@ -35,5 +33,6 @@ fun builder(c: suspend () -> Unit) {
result = foo(ref)
}
println(result)
assertEquals(42, result)
return "OK"
}
@@ -1 +0,0 @@
42
@@ -3,8 +3,6 @@
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
package codegen.coroutines.inheritance
import kotlin.test.*
import kotlin.coroutines.*
@@ -35,15 +33,16 @@ fun builder(c: suspend () -> Unit) {
c.startCoroutine(EmptyContinuation)
}
@Test fun runTest() {
fun box(): String {
var result = 0
builder {
result = SuspendHere()()
}
println(result)
assertEquals(42, result)
builder {
result = SuspendHereLegacy()()
}
println(result)
assertEquals(43, result)
return "OK"
}
@@ -1,2 +0,0 @@
42
43
+3 -3
View File
@@ -3,8 +3,6 @@
* that can be found in the LICENSE file.
*/
package codegen.coroutines.kt41394
import kotlin.test.*
import kotlin.coroutines.*
@@ -29,7 +27,7 @@ fun builder(c: suspend () -> Unit) {
c.startCoroutine(EmptyContinuation)
}
@Test fun runTest() {
fun box(): String {
var result = ""
builder {
@@ -37,4 +35,6 @@ fun builder(c: suspend () -> Unit) {
}
assertEquals("zzz42", result)
return "OK"
}
@@ -3,8 +3,6 @@
* that can be found in the LICENSE file.
*/
package codegen.coroutines.returnsNothing1
import kotlin.test.*
import kotlin.coroutines.*
@@ -32,9 +30,9 @@ fun builder(c: suspend () -> Unit) {
c.startCoroutine(EmptyContinuation)
}
@Test fun runTest() {
fun box(): String {
builder {
bar()
}
println("OK")
return "OK"
}
@@ -1 +0,0 @@
OK
@@ -3,20 +3,20 @@
* that can be found in the LICENSE file.
*/
package codegen.coroutines.returnsUnit1
import kotlin.test.*
import kotlin.coroutines.*
import kotlin.coroutines.intrinsics.*
val sb = StringBuilder()
open class EmptyContinuation(override val context: CoroutineContext = EmptyCoroutineContext) : Continuation<Any?> {
companion object : EmptyContinuation()
override fun resumeWith(result: Result<Any?>) { result.getOrThrow() }
}
suspend fun s1(): Unit = suspendCoroutineUninterceptedOrReturn { x ->
println("s1")
sb.appendLine("s1")
x.resume(Unit)
COROUTINE_SUSPENDED
}
@@ -26,7 +26,7 @@ fun builder(c: suspend () -> Unit) {
}
inline suspend fun inline_s2(x: Int): Unit {
println(x)
sb.appendLine(x)
s1()
}
@@ -34,12 +34,20 @@ suspend fun s3(x: Int) {
inline_s2(x)
}
@Test fun runTest() {
fun box(): String {
var result = 0
builder {
s3(117)
}
println(result)
sb.appendLine(result)
assertEquals("""
117
s1
0
""".trimIndent(), sb.toString())
return "OK"
}
@@ -1,3 +0,0 @@
117
s1
0
+3 -4
View File
@@ -3,8 +3,6 @@
* that can be found in the LICENSE file.
*/
package codegen.coroutines.simple
import kotlin.test.*
import kotlin.coroutines.*
@@ -24,12 +22,13 @@ fun builder(c: suspend () -> Unit) {
c.startCoroutine(EmptyContinuation)
}
@Test fun runTest() {
fun box(): String {
var result = 0
builder {
result = suspendHere()
}
println(result)
assertEquals(42, result)
return "OK"
}
@@ -1 +0,0 @@
42
@@ -17,11 +17,13 @@ fun builder(c: suspend () -> Unit) {
c.startCoroutine(EmptyContinuation)
}
fun main() {
fun box(): String {
var result = 0
val f: () -> Unit = { result = 42 }
builder(f)
assertEquals(42, result)
return "OK"
}
@@ -3,8 +3,6 @@
* that can be found in the LICENSE file.
*/
package codegen.coroutines.withReceiver
import kotlin.test.*
import kotlin.coroutines.*
@@ -26,12 +24,13 @@ fun builder(c: suspend Controller.() -> Unit) {
c.startCoroutine(Controller(), EmptyContinuation)
}
@Test fun runTest() {
fun box(): String {
var result = 0
builder {
result = suspendHere()
}
println(result)
assertEquals(42, result)
return "OK"
}
@@ -1 +0,0 @@
42