[Tests] Suspend Codegen Tests Improvements
This commit enables the execution of suspend box tests in a separate test. It's a QoL improvement in the existing bb tests but, motivating these changes, enables the new debugger stepping tests to step coroutine code.
This commit is contained in:
@@ -16,35 +16,19 @@ fun createTextForCoroutineHelpers(isReleaseCoroutines: Boolean, checkStateMachin
|
||||
else
|
||||
StandardNames.COROUTINES_PACKAGE_FQ_NAME_EXPERIMENTAL.asString()
|
||||
|
||||
val emptyContinuationBody =
|
||||
fun continuationBody(t: String, useResult: (String) -> String) =
|
||||
if (isReleaseCoroutines)
|
||||
"""
|
||||
|override fun resumeWith(result: Result<Any?>) {
|
||||
| result.getOrThrow()
|
||||
|override fun resumeWith(result: Result<$t>) {
|
||||
| ${useResult("result.getOrThrow()")}
|
||||
|}
|
||||
""".trimMargin()
|
||||
else
|
||||
"""
|
||||
|override fun resume(data: Any?) {}
|
||||
|override fun resume(data: $t) { ${useResult("data")} }
|
||||
|override fun resumeWithException(exception: Throwable) { throw exception }
|
||||
""".trimMargin()
|
||||
|
||||
val handleResultContinuationBody =
|
||||
if (isReleaseCoroutines)
|
||||
"""
|
||||
|override fun resumeWith(result: Result<T>) {
|
||||
| x(result.getOrThrow())
|
||||
|}
|
||||
""".trimMargin()
|
||||
else
|
||||
"""
|
||||
|override fun resumeWithException(exception: Throwable) {
|
||||
| throw exception
|
||||
|}
|
||||
|
|
||||
|override fun resume(data: T) = x(data)
|
||||
""".trimMargin()
|
||||
|
||||
val handleExceptionContinuationBody =
|
||||
if (isReleaseCoroutines)
|
||||
"""
|
||||
@@ -167,10 +151,9 @@ fun createTextForCoroutineHelpers(isReleaseCoroutines: Boolean, checkStateMachin
|
||||
|
|
||||
|fun <T> handleResultContinuation(x: (T) -> Unit): Continuation<T> = object: Continuation<T> {
|
||||
| override val context = EmptyCoroutineContext
|
||||
| $handleResultContinuationBody
|
||||
| ${continuationBody("T") { "x($it)" }}
|
||||
|}
|
||||
|
|
||||
|
|
||||
|fun handleExceptionContinuation(x: (Throwable) -> Unit): Continuation<Any?> = object: Continuation<Any?> {
|
||||
| override val context = EmptyCoroutineContext
|
||||
| $handleExceptionContinuationBody
|
||||
@@ -178,7 +161,14 @@ fun createTextForCoroutineHelpers(isReleaseCoroutines: Boolean, checkStateMachin
|
||||
|
|
||||
|open class EmptyContinuation(override val context: CoroutineContext = EmptyCoroutineContext) : Continuation<Any?> {
|
||||
| companion object : EmptyContinuation()
|
||||
| $emptyContinuationBody
|
||||
| ${continuationBody("Any?") { it }}
|
||||
|}
|
||||
|
|
||||
|class ResultContinuation : Continuation<Any?> {
|
||||
| override val context = EmptyCoroutineContext
|
||||
| ${continuationBody("Any?") { "this.result = $it" }}
|
||||
|
|
||||
| var result: Any? = null
|
||||
|}
|
||||
|
|
||||
|abstract class ContinuationAdapter<in T> : Continuation<T> {
|
||||
|
||||
+7
-1
@@ -21,7 +21,13 @@ abstract class AbstractBytecodeListingTest : CodegenTestCase() {
|
||||
val actualTxt = BytecodeListingTextCollectingVisitor.getText(
|
||||
classFileFactory,
|
||||
withSignatures = isWithSignatures(wholeFile),
|
||||
withAnnotations = isWithAnnotations(wholeFile)
|
||||
withAnnotations = isWithAnnotations(wholeFile),
|
||||
filter = object : BytecodeListingTextCollectingVisitor.Filter {
|
||||
override fun shouldWriteClass(access: Int, name: String): Boolean = !name.startsWith("helpers/")
|
||||
override fun shouldWriteMethod(access: Int, name: String, desc: String): Boolean = true
|
||||
override fun shouldWriteField(access: Int, name: String, desc: String): Boolean = true
|
||||
override fun shouldWriteInnerClass(name: String): Boolean = true
|
||||
}
|
||||
)
|
||||
|
||||
val prefixes = when {
|
||||
|
||||
@@ -65,6 +65,7 @@ import static org.jetbrains.kotlin.codegen.TestUtilsKt.extractUrls;
|
||||
import static org.jetbrains.kotlin.test.KotlinTestUtils.getAnnotationsJar;
|
||||
import static org.jetbrains.kotlin.test.clientserver.TestProcessServerKt.getBoxMethodOrNull;
|
||||
import static org.jetbrains.kotlin.test.clientserver.TestProcessServerKt.getGeneratedClass;
|
||||
import static org.jetbrains.kotlin.test.clientserver.TestProcessServerKt.runBoxMethod;
|
||||
|
||||
public abstract class CodegenTestCase extends KotlinBaseTest<KotlinBaseTest.TestFile> {
|
||||
private static final String DEFAULT_TEST_FILE_NAME = "a_test";
|
||||
@@ -679,7 +680,7 @@ public abstract class CodegenTestCase extends KotlinBaseTest<KotlinBaseTest.Test
|
||||
Thread.currentThread().setContextClassLoader(classLoader);
|
||||
}
|
||||
try {
|
||||
result = (String) method.invoke(null);
|
||||
result = runBoxMethod(method);
|
||||
}
|
||||
finally {
|
||||
if (savedClassLoader != classLoader) {
|
||||
|
||||
Reference in New Issue
Block a user