Fix tests after new Continuation API support
#KT-24863 Fixed
This commit is contained in:
+6
-1
@@ -54,7 +54,12 @@ public abstract class AbstractBlackBoxCodegenTest extends CodegenTestCase {
|
||||
private void doBytecodeListingTest(@NotNull File wholeFile) throws Exception {
|
||||
if (!InTextDirectivesUtils.isDirectiveDefined(FileUtil.loadFile(wholeFile), "CHECK_BYTECODE_LISTING")) return;
|
||||
|
||||
File expectedFile = new File(wholeFile.getParent(), FilesKt.getNameWithoutExtension(wholeFile) + ".txt");
|
||||
String suffix =
|
||||
(coroutinesPackage.contains("experimental") || coroutinesPackage.isEmpty())
|
||||
&& InTextDirectivesUtils.isDirectiveDefined(FileUtil.loadFile(wholeFile), "COMMON_COROUTINES_TEST")
|
||||
? "_1_2" : "";
|
||||
File expectedFile = new File(wholeFile.getParent(), FilesKt.getNameWithoutExtension(wholeFile) + suffix + ".txt");
|
||||
|
||||
String text =
|
||||
BytecodeListingTextCollectingVisitor.Companion.getText(
|
||||
classFileFactory,
|
||||
|
||||
+14
-1
@@ -5,16 +5,29 @@
|
||||
|
||||
package org.jetbrains.kotlin.codegen
|
||||
|
||||
import org.jetbrains.kotlin.resolve.DescriptorUtils
|
||||
import org.jetbrains.kotlin.test.KotlinTestUtils
|
||||
import org.jetbrains.kotlin.utils.addToStdlib.firstNotNullResult
|
||||
import org.jetbrains.kotlin.utils.sure
|
||||
import org.jetbrains.org.objectweb.asm.*
|
||||
import org.jetbrains.org.objectweb.asm.Opcodes.*
|
||||
import java.io.File
|
||||
|
||||
abstract class AbstractBytecodeListingTest : CodegenTestCase() {
|
||||
override fun doMultiFileTest(wholeFile: File, files: List<TestFile>, javaFilesDir: File?) {
|
||||
val txtFile = File(wholeFile.parentFile, wholeFile.nameWithoutExtension + ".txt")
|
||||
|
||||
compile(files, javaFilesDir)
|
||||
val actualTxt = BytecodeListingTextCollectingVisitor.getText(classFileFactory, withSignatures = isWithSignatures(wholeFile))
|
||||
|
||||
val prefixes =
|
||||
if (coroutinesPackage == DescriptorUtils.COROUTINES_PACKAGE_FQ_NAME_RELEASE.asString()) {
|
||||
listOf("_1_3", "")
|
||||
} else listOf("")
|
||||
|
||||
val txtFile =
|
||||
prefixes.firstNotNullResult { File(wholeFile.parentFile, wholeFile.nameWithoutExtension + "$it.txt").takeIf(File::exists) }
|
||||
.sure { "No testData file exists: ${wholeFile.nameWithoutExtension}.txt" }
|
||||
|
||||
KotlinTestUtils.assertEqualsToFile(txtFile, actualTxt) {
|
||||
it.replace("COROUTINES_PACKAGE", coroutinesPackage)
|
||||
}
|
||||
|
||||
@@ -712,7 +712,9 @@ public abstract class CodegenTestCase extends KtUsefulTestCase {
|
||||
boolean addCoroutines = false;
|
||||
boolean addUnsignedTypes = false;
|
||||
for (TestFile file : files) {
|
||||
if (InTextDirectivesUtils.isDirectiveDefined(file.content, "COMMON_COROUTINES_TEST")) {
|
||||
if (InTextDirectivesUtils.isDirectiveDefined(file.content, "COMMON_COROUTINES_TEST") ||
|
||||
InTextDirectivesUtils.isDirectiveDefined(file.content, "!LANGUAGE: +ReleaseCoroutines") ||
|
||||
InTextDirectivesUtils.isDirectiveDefined(file.content, "LANGUAGE_VERSION: 1.3")) {
|
||||
addCoroutines = true;
|
||||
}
|
||||
if (InTextDirectivesUtils.isDirectiveDefined(file.content, "WITH_RUNTIME")) {
|
||||
|
||||
@@ -5,38 +5,100 @@
|
||||
|
||||
package org.jetbrains.kotlin
|
||||
|
||||
fun createTextForHelpers(coroutinesPackage: String): String {
|
||||
import org.jetbrains.kotlin.resolve.DescriptorUtils
|
||||
|
||||
fun createTextForHelpers(isReleaseCoroutines: Boolean): String {
|
||||
val coroutinesPackage =
|
||||
if (isReleaseCoroutines)
|
||||
DescriptorUtils.COROUTINES_PACKAGE_FQ_NAME_RELEASE.asString()
|
||||
else
|
||||
DescriptorUtils.COROUTINES_PACKAGE_FQ_NAME_EXPERIMENTAL.asString()
|
||||
|
||||
val emptyContinuationBody =
|
||||
if (isReleaseCoroutines)
|
||||
"""
|
||||
|override fun resumeWith(result: SuccessOrFailure<Any?>) {
|
||||
| result.getOrThrow()
|
||||
|}
|
||||
""".trimMargin()
|
||||
else
|
||||
"""
|
||||
|override fun resume(data: Any?) {}
|
||||
|override fun resumeWithException(exception: Throwable) { throw exception }
|
||||
""".trimMargin()
|
||||
|
||||
val handleResultContinuationBody =
|
||||
if (isReleaseCoroutines)
|
||||
"""
|
||||
|override fun resumeWith(result: SuccessOrFailure<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)
|
||||
"""
|
||||
|override fun resumeWith(result: SuccessOrFailure<Any?>) {
|
||||
| result.exceptionOrNull()?.let(x)
|
||||
|}
|
||||
""".trimMargin()
|
||||
else
|
||||
"""
|
||||
|override fun resumeWithException(exception: Throwable) {
|
||||
| x(exception)
|
||||
|}
|
||||
|
|
||||
|override fun resume(data: Any?) {}
|
||||
""".trimMargin()
|
||||
|
||||
val continuationAdapterBody =
|
||||
if (isReleaseCoroutines)
|
||||
"""
|
||||
|override fun resumeWith(result: SuccessOrFailure<T>) {
|
||||
| if (result.isSuccess) {
|
||||
| resume(result.getOrThrow())
|
||||
| } else {
|
||||
| resumeWithException(result.exceptionOrNull()!!)
|
||||
| }
|
||||
|}
|
||||
|
|
||||
|abstract fun resumeWithException(exception: Throwable)
|
||||
|abstract fun resume(value: T)
|
||||
""".trimMargin()
|
||||
else
|
||||
""
|
||||
|
||||
return """
|
||||
|package helpers
|
||||
|import $coroutinesPackage.*
|
||||
|
|
||||
|fun <T> handleResultContinuation(x: (T) -> Unit): Continuation<T> = object: Continuation<T> {
|
||||
| override val context = EmptyCoroutineContext
|
||||
| override fun resumeWithException(exception: Throwable) {
|
||||
| throw exception
|
||||
| }
|
||||
|
|
||||
| override fun resume(data: T) = x(data)
|
||||
| $handleResultContinuationBody
|
||||
|}
|
||||
|
|
||||
|
|
||||
|fun handleExceptionContinuation(x: (Throwable) -> Unit): Continuation<Any?> = object: Continuation<Any?> {
|
||||
| override val context = EmptyCoroutineContext
|
||||
| override fun resumeWithException(exception: Throwable) {
|
||||
| x(exception)
|
||||
| }
|
||||
|
|
||||
| override fun resume(data: Any?) { }
|
||||
| $handleExceptionContinuationBody
|
||||
|}
|
||||
|
|
||||
|open class EmptyContinuation(override val context: CoroutineContext = EmptyCoroutineContext) : Continuation<Any?> {
|
||||
| companion object : EmptyContinuation()
|
||||
| override fun resume(data: Any?) {}
|
||||
| override fun resumeWithException(exception: Throwable) { throw exception }
|
||||
| $emptyContinuationBody
|
||||
|}
|
||||
|
|
||||
|abstract class ContinuationAdapter<in T> : Continuation<T> {
|
||||
| override val context: CoroutineContext = EmptyCoroutineContext
|
||||
| $continuationAdapterBody
|
||||
|}
|
||||
""".trimMargin()
|
||||
}
|
||||
|
||||
@@ -786,9 +786,14 @@ public class KotlinTestUtils {
|
||||
if (coroutinesPackage.isEmpty()) {
|
||||
coroutinesPackage = "kotlin.coroutines.experimental";
|
||||
}
|
||||
|
||||
boolean isReleaseCoroutines =
|
||||
!coroutinesPackage.contains("experimental") ||
|
||||
isDirectiveDefined(expectedText, "LANGUAGE_VERSION: 1.3");
|
||||
|
||||
testFiles.add(factory.createFile(supportModule,
|
||||
"CoroutineUtil.kt",
|
||||
CoroutineTestUtilKt.createTextForHelpers(coroutinesPackage),
|
||||
CoroutineTestUtilKt.createTextForHelpers(isReleaseCoroutines),
|
||||
directives
|
||||
));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user