Support coroutines in Android box tests

This commit is contained in:
Mikhael Bogdanov
2018-10-24 11:07:16 +02:00
parent ae0b2405bc
commit 612ca87aa3
3 changed files with 17 additions and 7 deletions
@@ -199,11 +199,17 @@ class CodegenTestsOnAndroidGenerator private constructor(private val pathManager
continue continue
} }
val fullFileText = FileUtil.loadFile(file, true) val fullFileText = FileUtil.loadFile(file, true).let {
it.replace("COROUTINES_PACKAGE", "kotlin.coroutines")
}
if (fullFileText.contains("// WITH_COROUTINES")) {
if (fullFileText.contains("kotlin.coroutines.experimental")) continue
if (fullFileText.contains("// LANGUAGE_VERSION: 1.2")) continue
}
//TODO support JvmPackageName //TODO support JvmPackageName
if (fullFileText.contains("@file:JvmPackageName(")) continue if (fullFileText.contains("@file:JvmPackageName(")) continue
// TODO: Support coroutines tests
if (fullFileText.contains("// WITH_COROUTINES")) continue
// TODO: Support jvm assertions // TODO: Support jvm assertions
if (fullFileText.contains("// KOTLIN_CONFIGURATION_FLAGS: ASSERTIONS_MODE=jvm")) continue if (fullFileText.contains("// KOTLIN_CONFIGURATION_FLAGS: ASSERTIONS_MODE=jvm")) continue
// TODO: support JVM 8 test with D8 // TODO: support JVM 8 test with D8
@@ -248,7 +254,9 @@ class CodegenTestsOnAndroidGenerator private constructor(private val pathManager
override fun create(fileName: String, text: String, directives: Map<String, String>): CodegenTestCase.TestFile { override fun create(fileName: String, text: String, directives: Map<String, String>): CodegenTestCase.TestFile {
return CodegenTestCase.TestFile(fileName, text) return CodegenTestCase.TestFile(fileName, text)
} }
}) }, false,
"kotlin.coroutines"
)
private fun generateTestName(fileName: String): String { private fun generateTestName(fileName: String): String {
@@ -3,13 +3,14 @@
// IGNORE_BACKEND: JVM_IR // IGNORE_BACKEND: JVM_IR
// WITH_RUNTIME // WITH_RUNTIME
// WITH_COROUTINES // WITH_COROUTINES
import helpers.ContinuationAdapter
import kotlin.coroutines.* import kotlin.coroutines.*
import kotlin.coroutines.intrinsics.COROUTINE_SUSPENDED import kotlin.coroutines.intrinsics.COROUTINE_SUSPENDED
fun runCustomLambdaAsCoroutine(e: Throwable? = null, x: (Continuation<String>) -> Any?): String { fun runCustomLambdaAsCoroutine(e: Throwable? = null, x: (Continuation<String>) -> Any?): String {
var result = "fail" var result = "fail"
var wasIntercepted = false var wasIntercepted = false
val c = (x as suspend () -> String).createCoroutine(object: helpers.ContinuationAdapter<String>() { val c = (x as suspend () -> String).createCoroutine(object: ContinuationAdapter<String>() {
override fun resumeWithException(exception: Throwable) { override fun resumeWithException(exception: Throwable) {
throw exception throw exception
} }
@@ -27,7 +28,7 @@ fun runCustomLambdaAsCoroutine(e: Throwable? = null, x: (Continuation<String>) -
return null return null
} }
override fun <T> interceptContinuation(continuation: Continuation<T>) = object : helpers.ContinuationAdapter<T>() { override fun <T> interceptContinuation(continuation: Continuation<T>) = object : ContinuationAdapter<T>() {
override val context: CoroutineContext override val context: CoroutineContext
get() = continuation.context get() = continuation.context
@@ -12,11 +12,12 @@ inline suspend fun foo(x: suspend () -> String) = x()
// WITH_RUNTIME // WITH_RUNTIME
// WITH_COROUTINES // WITH_COROUTINES
import helpers.ContinuationAdapter
import kotlin.coroutines.* import kotlin.coroutines.*
import kotlin.coroutines.intrinsics.* import kotlin.coroutines.intrinsics.*
fun builder(c: suspend () -> Unit) { fun builder(c: suspend () -> Unit) {
c.startCoroutine(object: helpers.ContinuationAdapter<Unit>() { c.startCoroutine(object: ContinuationAdapter<Unit>() {
override fun resume(value: Unit) { override fun resume(value: Unit) {
} }