[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:
-68
@@ -36,71 +36,3 @@ public final class BooleanParameterKt {
|
||||
public final static @org.jetbrains.annotations.NotNull method box(): java.lang.String
|
||||
public final static method builder(@org.jetbrains.annotations.NotNull p0: kotlin.jvm.functions.Function1): void
|
||||
}
|
||||
|
||||
@kotlin.Metadata
|
||||
public abstract class helpers/ContinuationAdapter {
|
||||
// source: 'CoroutineUtil.kt'
|
||||
private final @org.jetbrains.annotations.NotNull field context: kotlin.coroutines.CoroutineContext
|
||||
public method <init>(): void
|
||||
public @org.jetbrains.annotations.NotNull method getContext(): kotlin.coroutines.CoroutineContext
|
||||
public abstract method resume(p0: java.lang.Object): void
|
||||
public method resumeWith(@org.jetbrains.annotations.NotNull p0: java.lang.Object): void
|
||||
public abstract method resumeWithException(@org.jetbrains.annotations.NotNull p0: java.lang.Throwable): void
|
||||
}
|
||||
|
||||
@kotlin.Metadata
|
||||
public final class helpers/CoroutineUtilKt$handleExceptionContinuation$1 {
|
||||
// source: 'CoroutineUtil.kt'
|
||||
enclosing method helpers/CoroutineUtilKt.handleExceptionContinuation(Lkotlin/jvm/functions/Function1;)Lkotlin/coroutines/Continuation;
|
||||
synthetic final field $x: kotlin.jvm.functions.Function1
|
||||
private final @org.jetbrains.annotations.NotNull field context: kotlin.coroutines.EmptyCoroutineContext
|
||||
inner (anonymous) class helpers/CoroutineUtilKt$handleExceptionContinuation$1
|
||||
method <init>(p0: kotlin.jvm.functions.Function1): void
|
||||
public synthetic bridge method getContext(): kotlin.coroutines.CoroutineContext
|
||||
public @org.jetbrains.annotations.NotNull method getContext(): kotlin.coroutines.EmptyCoroutineContext
|
||||
public method resumeWith(@org.jetbrains.annotations.NotNull p0: java.lang.Object): void
|
||||
}
|
||||
|
||||
@kotlin.Metadata
|
||||
public final class helpers/CoroutineUtilKt$handleResultContinuation$1 {
|
||||
// source: 'CoroutineUtil.kt'
|
||||
enclosing method helpers/CoroutineUtilKt.handleResultContinuation(Lkotlin/jvm/functions/Function1;)Lkotlin/coroutines/Continuation;
|
||||
synthetic final field $x: kotlin.jvm.functions.Function1
|
||||
private final @org.jetbrains.annotations.NotNull field context: kotlin.coroutines.EmptyCoroutineContext
|
||||
inner (anonymous) class helpers/CoroutineUtilKt$handleResultContinuation$1
|
||||
method <init>(p0: kotlin.jvm.functions.Function1): void
|
||||
public synthetic bridge method getContext(): kotlin.coroutines.CoroutineContext
|
||||
public @org.jetbrains.annotations.NotNull method getContext(): kotlin.coroutines.EmptyCoroutineContext
|
||||
public method resumeWith(@org.jetbrains.annotations.NotNull p0: java.lang.Object): void
|
||||
}
|
||||
|
||||
@kotlin.Metadata
|
||||
public final class helpers/CoroutineUtilKt {
|
||||
// source: 'CoroutineUtil.kt'
|
||||
inner (anonymous) class helpers/CoroutineUtilKt$handleExceptionContinuation$1
|
||||
inner (anonymous) class helpers/CoroutineUtilKt$handleResultContinuation$1
|
||||
public final static @org.jetbrains.annotations.NotNull method handleExceptionContinuation(@org.jetbrains.annotations.NotNull p0: kotlin.jvm.functions.Function1): kotlin.coroutines.Continuation
|
||||
public final static @org.jetbrains.annotations.NotNull method handleResultContinuation(@org.jetbrains.annotations.NotNull p0: kotlin.jvm.functions.Function1): kotlin.coroutines.Continuation
|
||||
}
|
||||
|
||||
@kotlin.Metadata
|
||||
public final class helpers/EmptyContinuation$Companion {
|
||||
// source: 'CoroutineUtil.kt'
|
||||
private method <init>(): void
|
||||
public synthetic method <init>(p0: kotlin.jvm.internal.DefaultConstructorMarker): void
|
||||
public final inner class helpers/EmptyContinuation$Companion
|
||||
}
|
||||
|
||||
@kotlin.Metadata
|
||||
public class helpers/EmptyContinuation {
|
||||
// source: 'CoroutineUtil.kt'
|
||||
public final static @org.jetbrains.annotations.NotNull field Companion: helpers.EmptyContinuation$Companion
|
||||
private final @org.jetbrains.annotations.NotNull field context: kotlin.coroutines.CoroutineContext
|
||||
static method <clinit>(): void
|
||||
public method <init>(): void
|
||||
public method <init>(@org.jetbrains.annotations.NotNull p0: kotlin.coroutines.CoroutineContext): void
|
||||
public synthetic method <init>(p0: kotlin.coroutines.CoroutineContext, p1: int, p2: kotlin.jvm.internal.DefaultConstructorMarker): void
|
||||
public @org.jetbrains.annotations.NotNull method getContext(): kotlin.coroutines.CoroutineContext
|
||||
public method resumeWith(@org.jetbrains.annotations.NotNull p0: java.lang.Object): void
|
||||
public final inner class helpers/EmptyContinuation$Companion
|
||||
}
|
||||
|
||||
-68
@@ -36,71 +36,3 @@ public final class BooleanParameterKt {
|
||||
public final static @org.jetbrains.annotations.NotNull method box(): java.lang.String
|
||||
public final static method builder(@org.jetbrains.annotations.NotNull p0: kotlin.jvm.functions.Function1): void
|
||||
}
|
||||
|
||||
@kotlin.Metadata
|
||||
public abstract class helpers/ContinuationAdapter {
|
||||
// source: 'CoroutineUtil.kt'
|
||||
private final @org.jetbrains.annotations.NotNull field context: kotlin.coroutines.CoroutineContext
|
||||
public method <init>(): void
|
||||
public @org.jetbrains.annotations.NotNull method getContext(): kotlin.coroutines.CoroutineContext
|
||||
public abstract method resume(p0: java.lang.Object): void
|
||||
public method resumeWith(@org.jetbrains.annotations.NotNull p0: java.lang.Object): void
|
||||
public abstract method resumeWithException(@org.jetbrains.annotations.NotNull p0: java.lang.Throwable): void
|
||||
}
|
||||
|
||||
@kotlin.Metadata
|
||||
public final class helpers/CoroutineUtilKt$handleExceptionContinuation$1 {
|
||||
// source: 'CoroutineUtil.kt'
|
||||
enclosing method helpers/CoroutineUtilKt.handleExceptionContinuation(Lkotlin/jvm/functions/Function1;)Lkotlin/coroutines/Continuation;
|
||||
synthetic final field $x: kotlin.jvm.functions.Function1
|
||||
private final @org.jetbrains.annotations.NotNull field context: kotlin.coroutines.EmptyCoroutineContext
|
||||
inner (anonymous) class helpers/CoroutineUtilKt$handleExceptionContinuation$1
|
||||
method <init>(p0: kotlin.jvm.functions.Function1): void
|
||||
public synthetic bridge method getContext(): kotlin.coroutines.CoroutineContext
|
||||
public @org.jetbrains.annotations.NotNull method getContext(): kotlin.coroutines.EmptyCoroutineContext
|
||||
public method resumeWith(@org.jetbrains.annotations.NotNull p0: java.lang.Object): void
|
||||
}
|
||||
|
||||
@kotlin.Metadata
|
||||
public final class helpers/CoroutineUtilKt$handleResultContinuation$1 {
|
||||
// source: 'CoroutineUtil.kt'
|
||||
enclosing method helpers/CoroutineUtilKt.handleResultContinuation(Lkotlin/jvm/functions/Function1;)Lkotlin/coroutines/Continuation;
|
||||
synthetic final field $x: kotlin.jvm.functions.Function1
|
||||
private final @org.jetbrains.annotations.NotNull field context: kotlin.coroutines.EmptyCoroutineContext
|
||||
inner (anonymous) class helpers/CoroutineUtilKt$handleResultContinuation$1
|
||||
method <init>(p0: kotlin.jvm.functions.Function1): void
|
||||
public synthetic bridge method getContext(): kotlin.coroutines.CoroutineContext
|
||||
public @org.jetbrains.annotations.NotNull method getContext(): kotlin.coroutines.EmptyCoroutineContext
|
||||
public method resumeWith(@org.jetbrains.annotations.NotNull p0: java.lang.Object): void
|
||||
}
|
||||
|
||||
@kotlin.Metadata
|
||||
public final class helpers/CoroutineUtilKt {
|
||||
// source: 'CoroutineUtil.kt'
|
||||
inner (anonymous) class helpers/CoroutineUtilKt$handleExceptionContinuation$1
|
||||
inner (anonymous) class helpers/CoroutineUtilKt$handleResultContinuation$1
|
||||
public final static @org.jetbrains.annotations.NotNull method handleExceptionContinuation(@org.jetbrains.annotations.NotNull p0: kotlin.jvm.functions.Function1): kotlin.coroutines.Continuation
|
||||
public final static @org.jetbrains.annotations.NotNull method handleResultContinuation(@org.jetbrains.annotations.NotNull p0: kotlin.jvm.functions.Function1): kotlin.coroutines.Continuation
|
||||
}
|
||||
|
||||
@kotlin.Metadata
|
||||
public final class helpers/EmptyContinuation$Companion {
|
||||
// source: 'CoroutineUtil.kt'
|
||||
private method <init>(): void
|
||||
public synthetic method <init>(p0: kotlin.jvm.internal.DefaultConstructorMarker): void
|
||||
public final inner class helpers/EmptyContinuation$Companion
|
||||
}
|
||||
|
||||
@kotlin.Metadata
|
||||
public class helpers/EmptyContinuation {
|
||||
// source: 'CoroutineUtil.kt'
|
||||
public final static @org.jetbrains.annotations.NotNull field Companion: helpers.EmptyContinuation$Companion
|
||||
private final @org.jetbrains.annotations.NotNull field context: kotlin.coroutines.CoroutineContext
|
||||
static method <clinit>(): void
|
||||
public method <init>(): void
|
||||
public method <init>(@org.jetbrains.annotations.NotNull p0: kotlin.coroutines.CoroutineContext): void
|
||||
public synthetic method <init>(p0: kotlin.coroutines.CoroutineContext, p1: int, p2: kotlin.jvm.internal.DefaultConstructorMarker): void
|
||||
public @org.jetbrains.annotations.NotNull method getContext(): kotlin.coroutines.CoroutineContext
|
||||
public method resumeWith(@org.jetbrains.annotations.NotNull p0: java.lang.Object): void
|
||||
public final inner class helpers/EmptyContinuation$Companion
|
||||
}
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
// WITH_COROUTINES
|
||||
// FILE: test.kt
|
||||
|
||||
suspend fun box() {
|
||||
var x = 1
|
||||
}
|
||||
|
||||
// LOCAL VARIABLES
|
||||
// TestKt:5: $completion:kotlin.coroutines.Continuation=helpers.ResultContinuation
|
||||
// TestKt:6: $completion:kotlin.coroutines.Continuation=helpers.ResultContinuation, x:int=1:int
|
||||
+26
-11
@@ -28,22 +28,37 @@ import java.util.concurrent.Executors
|
||||
import java.util.concurrent.ScheduledFuture
|
||||
import java.util.concurrent.TimeUnit
|
||||
|
||||
fun getGeneratedClass(classLoader: ClassLoader, className: String): Class<*> {
|
||||
private fun ClassLoader.loadClassOrNull(name: String): Class<*>? =
|
||||
try {
|
||||
return classLoader.loadClass(className)
|
||||
loadClass(name)
|
||||
} catch (e: ClassNotFoundException) {
|
||||
null
|
||||
}
|
||||
catch (e: ClassNotFoundException) {
|
||||
error("No class file was generated for: " + className)
|
||||
}
|
||||
}
|
||||
|
||||
fun getBoxMethodOrNull(aClass: Class<*>): Method? {
|
||||
private fun Class<*>.getMethodOrNull(name: String, vararg parameterTypes: Class<*>): Method? =
|
||||
try {
|
||||
return aClass.getMethod("box")
|
||||
getMethod(name, *parameterTypes)
|
||||
} catch (e: NoSuchMethodException) {
|
||||
null
|
||||
}
|
||||
catch (e: NoSuchMethodException) {
|
||||
return null
|
||||
|
||||
fun getGeneratedClass(classLoader: ClassLoader, className: String): Class<*> =
|
||||
classLoader.loadClassOrNull(className) ?: error("No class file was generated for: $className")
|
||||
|
||||
fun getBoxMethodOrNull(aClass: Class<*>): Method? =
|
||||
aClass.getMethodOrNull("box")
|
||||
?: aClass.classLoader.loadClassOrNull("kotlin.coroutines.Continuation")?.let { aClass.getMethodOrNull("box", it) }
|
||||
?: aClass.classLoader.loadClassOrNull("kotlin.coroutines.experimental.Continuation")?.let { aClass.getMethodOrNull("box", it) }
|
||||
|
||||
fun runBoxMethod(method: Method): String? {
|
||||
if (method.parameterTypes.isEmpty()) {
|
||||
return method.invoke(null) as? String
|
||||
}
|
||||
val emptyContinuationClass = method.declaringClass.classLoader.loadClass("helpers.ResultContinuation")
|
||||
val emptyContinuation = emptyContinuationClass.declaredConstructors.single().newInstance()
|
||||
val result = method.invoke(null, emptyContinuation)
|
||||
val resultAfterSuspend = emptyContinuationClass.getField("result").get(emptyContinuation)
|
||||
return (resultAfterSuspend ?: result) as? String
|
||||
}
|
||||
|
||||
//Use only JDK 1.6 compatible api
|
||||
@@ -149,7 +164,7 @@ private class ServerTest(val clientSocket: Socket, val suppressOutput: Boolean)
|
||||
|
||||
fun executeTest(classLoader: ClassLoader): String {
|
||||
val clazz = getGeneratedClass(classLoader, className)
|
||||
return getBoxMethodOrNull(clazz)!!.invoke(null) as String
|
||||
return runBoxMethod(getBoxMethodOrNull(clazz)!!) as String
|
||||
}
|
||||
|
||||
companion object {
|
||||
|
||||
@@ -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) {
|
||||
|
||||
Generated
+20
@@ -84,4 +84,24 @@ public class IrLocalVariableTestGenerated extends AbstractIrLocalVariableTest {
|
||||
public void testUnderscoreNames() throws Exception {
|
||||
runTest("compiler/testData/debug/localVariables/underscoreNames.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("compiler/testData/debug/localVariables/suspend")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
@RunWith(BlockJUnit4ClassRunner.class)
|
||||
public static class Suspend extends AbstractIrLocalVariableTest {
|
||||
private void runTest(String testDataFilePath) throws Exception {
|
||||
KotlinTestUtils.runTest(this::doTest, TargetBackend.JVM_IR, testDataFilePath);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAllFilesPresentInSuspend() throws Exception {
|
||||
KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/debug/localVariables/suspend"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JVM_IR, true);
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("simple.kt")
|
||||
public void testSimple() throws Exception {
|
||||
runTest("compiler/testData/debug/localVariables/suspend/simple.kt");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Generated
+20
@@ -84,4 +84,24 @@ public class LocalVariableTestGenerated extends AbstractLocalVariableTest {
|
||||
public void testUnderscoreNames() throws Exception {
|
||||
runTest("compiler/testData/debug/localVariables/underscoreNames.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("compiler/testData/debug/localVariables/suspend")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
@RunWith(BlockJUnit4ClassRunner.class)
|
||||
public static class Suspend extends AbstractLocalVariableTest {
|
||||
private void runTest(String testDataFilePath) throws Exception {
|
||||
KotlinTestUtils.runTest(this::doTest, TargetBackend.JVM, testDataFilePath);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAllFilesPresentInSuspend() throws Exception {
|
||||
KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/debug/localVariables/suspend"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JVM, true);
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("simple.kt")
|
||||
public void testSimple() throws Exception {
|
||||
runTest("compiler/testData/debug/localVariables/suspend/simple.kt");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user