JS: enabled codegen box tests for release coroutines
This commit is contained in:
+3
-4
@@ -1,11 +1,10 @@
|
|||||||
|
// LANGUAGE_VERSION: 1.3
|
||||||
// IGNORE_BACKEND: JS_IR
|
// IGNORE_BACKEND: JS_IR
|
||||||
// IGNORE_BACKEND: JVM_IR
|
// IGNORE_BACKEND: JVM_IR
|
||||||
// WITH_RUNTIME
|
// WITH_RUNTIME
|
||||||
// WITH_COROUTINES
|
// WITH_COROUTINES
|
||||||
// IGNORE_BACKEND: JS
|
import kotlin.coroutines.*
|
||||||
// COMMON_COROUTINES_TEST
|
import kotlin.coroutines.intrinsics.COROUTINE_SUSPENDED
|
||||||
import COROUTINES_PACKAGE.*
|
|
||||||
import COROUTINES_PACKAGE.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"
|
||||||
|
|||||||
+95
@@ -0,0 +1,95 @@
|
|||||||
|
// IGNORE_BACKEND: JS_IR
|
||||||
|
// WITH_RUNTIME
|
||||||
|
// WITH_COROUTINES
|
||||||
|
// IGNORE_BACKEND: JS
|
||||||
|
import kotlin.coroutines.experimental.*
|
||||||
|
import kotlin.coroutines.experimental.intrinsics.COROUTINE_SUSPENDED
|
||||||
|
|
||||||
|
fun runCustomLambdaAsCoroutine(e: Throwable? = null, x: (Continuation<String>) -> Any?): String {
|
||||||
|
var result = "fail"
|
||||||
|
var wasIntercepted = false
|
||||||
|
val c = (x as suspend () -> String).createCoroutine(object: helpers.ContinuationAdapter<String>() {
|
||||||
|
override fun resumeWithException(exception: Throwable) {
|
||||||
|
throw exception
|
||||||
|
}
|
||||||
|
|
||||||
|
override val context: CoroutineContext
|
||||||
|
get() = object: ContinuationInterceptor {
|
||||||
|
override fun <R> fold(initial: R, operation: (R, CoroutineContext.Element) -> R): R {
|
||||||
|
throw IllegalStateException()
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun <E : CoroutineContext.Element> get(key: CoroutineContext.Key<E>): E? {
|
||||||
|
if (key == ContinuationInterceptor.Key) {
|
||||||
|
return this as E
|
||||||
|
}
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun <T> interceptContinuation(continuation: Continuation<T>) = object : helpers.ContinuationAdapter<T>() {
|
||||||
|
override val context: CoroutineContext
|
||||||
|
get() = continuation.context
|
||||||
|
|
||||||
|
override fun resume(value: T) {
|
||||||
|
wasIntercepted = true
|
||||||
|
continuation.resume(value)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun resumeWithException(exception: Throwable) {
|
||||||
|
wasIntercepted = true
|
||||||
|
continuation.resumeWithException(exception)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun minusKey(key: CoroutineContext.Key<*>): CoroutineContext {
|
||||||
|
throw IllegalStateException()
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun plus(context: CoroutineContext): CoroutineContext {
|
||||||
|
throw IllegalStateException()
|
||||||
|
}
|
||||||
|
|
||||||
|
override val key: CoroutineContext.Key<*>
|
||||||
|
get() = ContinuationInterceptor.Key
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun resume(value: String) {
|
||||||
|
result = value
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
if (e != null)
|
||||||
|
c.resumeWithException(e)
|
||||||
|
else
|
||||||
|
c.resume(Unit)
|
||||||
|
|
||||||
|
if (!wasIntercepted) return "was not intercepted"
|
||||||
|
|
||||||
|
return result
|
||||||
|
}
|
||||||
|
|
||||||
|
fun box(): String {
|
||||||
|
val x = runCustomLambdaAsCoroutine {
|
||||||
|
it.resume("OK")
|
||||||
|
COROUTINE_SUSPENDED
|
||||||
|
}
|
||||||
|
|
||||||
|
if (x != "OK") return "fail 1: $x"
|
||||||
|
|
||||||
|
val y = runCustomLambdaAsCoroutine {
|
||||||
|
"OK"
|
||||||
|
}
|
||||||
|
|
||||||
|
if (y != "OK") return "fail 2: $x"
|
||||||
|
|
||||||
|
|
||||||
|
try {
|
||||||
|
runCustomLambdaAsCoroutine(RuntimeException("OK")) {
|
||||||
|
throw RuntimeException("fail 3")
|
||||||
|
}
|
||||||
|
} catch(e: Exception) {
|
||||||
|
return e.message!!
|
||||||
|
}
|
||||||
|
|
||||||
|
return "fail 3"
|
||||||
|
}
|
||||||
Generated
+5
-5
@@ -5340,13 +5340,13 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
|
|||||||
}
|
}
|
||||||
|
|
||||||
@TestMetadata("createCoroutinesOnManualInstances.kt")
|
@TestMetadata("createCoroutinesOnManualInstances.kt")
|
||||||
public void testCreateCoroutinesOnManualInstances_1_2() throws Exception {
|
public void testCreateCoroutinesOnManualInstances() throws Exception {
|
||||||
runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/createCoroutinesOnManualInstances.kt", "kotlin.coroutines.experimental");
|
runTest("compiler/testData/codegen/box/coroutines/createCoroutinesOnManualInstances.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
@TestMetadata("createCoroutinesOnManualInstances.kt")
|
@TestMetadata("createCoroutinesOnManualInstances_1_2.kt")
|
||||||
public void testCreateCoroutinesOnManualInstances_1_3() throws Exception {
|
public void testCreateCoroutinesOnManualInstances_1_2() throws Exception {
|
||||||
runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/createCoroutinesOnManualInstances.kt", "kotlin.coroutines");
|
runTest("compiler/testData/codegen/box/coroutines/createCoroutinesOnManualInstances_1_2.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
@TestMetadata("crossInlineWithCapturedOuterReceiver.kt")
|
@TestMetadata("crossInlineWithCapturedOuterReceiver.kt")
|
||||||
|
|||||||
+5
-5
@@ -5340,13 +5340,13 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@TestMetadata("createCoroutinesOnManualInstances.kt")
|
@TestMetadata("createCoroutinesOnManualInstances.kt")
|
||||||
public void testCreateCoroutinesOnManualInstances_1_2() throws Exception {
|
public void testCreateCoroutinesOnManualInstances() throws Exception {
|
||||||
runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/createCoroutinesOnManualInstances.kt", "kotlin.coroutines.experimental");
|
runTest("compiler/testData/codegen/box/coroutines/createCoroutinesOnManualInstances.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
@TestMetadata("createCoroutinesOnManualInstances.kt")
|
@TestMetadata("createCoroutinesOnManualInstances_1_2.kt")
|
||||||
public void testCreateCoroutinesOnManualInstances_1_3() throws Exception {
|
public void testCreateCoroutinesOnManualInstances_1_2() throws Exception {
|
||||||
runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/createCoroutinesOnManualInstances.kt", "kotlin.coroutines");
|
runTest("compiler/testData/codegen/box/coroutines/createCoroutinesOnManualInstances_1_2.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
@TestMetadata("crossInlineWithCapturedOuterReceiver.kt")
|
@TestMetadata("crossInlineWithCapturedOuterReceiver.kt")
|
||||||
|
|||||||
+5
-5
@@ -5340,13 +5340,13 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes
|
|||||||
}
|
}
|
||||||
|
|
||||||
@TestMetadata("createCoroutinesOnManualInstances.kt")
|
@TestMetadata("createCoroutinesOnManualInstances.kt")
|
||||||
public void testCreateCoroutinesOnManualInstances_1_2() throws Exception {
|
public void testCreateCoroutinesOnManualInstances() throws Exception {
|
||||||
runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/createCoroutinesOnManualInstances.kt", "kotlin.coroutines.experimental");
|
runTest("compiler/testData/codegen/box/coroutines/createCoroutinesOnManualInstances.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
@TestMetadata("createCoroutinesOnManualInstances.kt")
|
@TestMetadata("createCoroutinesOnManualInstances_1_2.kt")
|
||||||
public void testCreateCoroutinesOnManualInstances_1_3() throws Exception {
|
public void testCreateCoroutinesOnManualInstances_1_2() throws Exception {
|
||||||
runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/createCoroutinesOnManualInstances.kt", "kotlin.coroutines");
|
runTest("compiler/testData/codegen/box/coroutines/createCoroutinesOnManualInstances_1_2.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
@TestMetadata("crossInlineWithCapturedOuterReceiver.kt")
|
@TestMetadata("crossInlineWithCapturedOuterReceiver.kt")
|
||||||
|
|||||||
@@ -54,7 +54,7 @@ fun createCommonCoroutinesTestMethodModels(
|
|||||||
targetBackend: TargetBackend,
|
targetBackend: TargetBackend,
|
||||||
skipIgnored: Boolean
|
skipIgnored: Boolean
|
||||||
): Collection<MethodModel> {
|
): Collection<MethodModel> {
|
||||||
return if (targetBackend == TargetBackend.JS || targetBackend == TargetBackend.JS_IR)
|
return if (targetBackend == TargetBackend.JS_IR)
|
||||||
listOf(
|
listOf(
|
||||||
CoroutinesTestModel(
|
CoroutinesTestModel(
|
||||||
rootDir,
|
rootDir,
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ import com.intellij.openapi.vfs.StandardFileSystems
|
|||||||
import com.intellij.openapi.vfs.VirtualFileManager
|
import com.intellij.openapi.vfs.VirtualFileManager
|
||||||
import com.intellij.psi.PsiManager
|
import com.intellij.psi.PsiManager
|
||||||
import junit.framework.TestCase
|
import junit.framework.TestCase
|
||||||
|
import org.jetbrains.kotlin.checkers.CompilerTestLanguageVersionSettings
|
||||||
import org.jetbrains.kotlin.checkers.parseLanguageVersionSettings
|
import org.jetbrains.kotlin.checkers.parseLanguageVersionSettings
|
||||||
import org.jetbrains.kotlin.cli.common.messages.AnalyzerWithCompilerReport
|
import org.jetbrains.kotlin.cli.common.messages.AnalyzerWithCompilerReport
|
||||||
import org.jetbrains.kotlin.cli.common.messages.MessageRenderer
|
import org.jetbrains.kotlin.cli.common.messages.MessageRenderer
|
||||||
@@ -19,10 +20,7 @@ import org.jetbrains.kotlin.cli.common.messages.PrintingMessageCollector
|
|||||||
import org.jetbrains.kotlin.cli.common.output.outputUtils.writeAllTo
|
import org.jetbrains.kotlin.cli.common.output.outputUtils.writeAllTo
|
||||||
import org.jetbrains.kotlin.cli.jvm.compiler.EnvironmentConfigFiles
|
import org.jetbrains.kotlin.cli.jvm.compiler.EnvironmentConfigFiles
|
||||||
import org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment
|
import org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment
|
||||||
import org.jetbrains.kotlin.config.CommonConfigurationKeys
|
import org.jetbrains.kotlin.config.*
|
||||||
import org.jetbrains.kotlin.config.CompilerConfiguration
|
|
||||||
import org.jetbrains.kotlin.config.LanguageVersionSettings
|
|
||||||
import org.jetbrains.kotlin.config.languageVersionSettings
|
|
||||||
import org.jetbrains.kotlin.idea.KotlinFileType
|
import org.jetbrains.kotlin.idea.KotlinFileType
|
||||||
import org.jetbrains.kotlin.incremental.js.IncrementalDataProviderImpl
|
import org.jetbrains.kotlin.incremental.js.IncrementalDataProviderImpl
|
||||||
import org.jetbrains.kotlin.incremental.js.IncrementalResultsConsumerImpl
|
import org.jetbrains.kotlin.incremental.js.IncrementalResultsConsumerImpl
|
||||||
@@ -90,24 +88,23 @@ abstract class BasicBoxTest(
|
|||||||
doTest(filePath, "OK", MainCallParameters.noCall())
|
doTest(filePath, "OK", MainCallParameters.noCall())
|
||||||
}
|
}
|
||||||
|
|
||||||
fun doTestWithCoroutinesPackageReplacement(filePath: String, packageName: String) {
|
fun doTestWithCoroutinesPackageReplacement(filePath: String, coroutinesPackage: String) {
|
||||||
if (packageName == "kotlin.coroutines") return // TODO: Support JS in kotlin-stdlib-coroutines
|
doTest(filePath, "OK", MainCallParameters.noCall(), coroutinesPackage)
|
||||||
doTest(filePath, "OK", MainCallParameters.noCall(), packageName)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun doTest(filePath: String, expectedResult: String, mainCallParameters: MainCallParameters, packageName: String = "") {
|
fun doTest(filePath: String, expectedResult: String, mainCallParameters: MainCallParameters, coroutinesPackage: String = "") {
|
||||||
val file = File(filePath)
|
val file = File(filePath)
|
||||||
val outputDir = getOutputDir(file)
|
val outputDir = getOutputDir(file)
|
||||||
var fileContent = KotlinTestUtils.doLoadFile(file)
|
var fileContent = KotlinTestUtils.doLoadFile(file)
|
||||||
if (packageName.isNotEmpty()) {
|
if (coroutinesPackage.isNotEmpty()) {
|
||||||
fileContent = fileContent.replace("COROUTINES_PACKAGE", packageName)
|
fileContent = fileContent.replace("COROUTINES_PACKAGE", coroutinesPackage)
|
||||||
}
|
}
|
||||||
|
|
||||||
val outputPrefixFile = getOutputPrefixFile(filePath)
|
val outputPrefixFile = getOutputPrefixFile(filePath)
|
||||||
val outputPostfixFile = getOutputPostfixFile(filePath)
|
val outputPostfixFile = getOutputPostfixFile(filePath)
|
||||||
|
|
||||||
TestFileFactoryImpl().use { testFactory ->
|
TestFileFactoryImpl(coroutinesPackage).use { testFactory ->
|
||||||
val inputFiles = KotlinTestUtils.createTestFiles(file.name, fileContent, testFactory, true, "")
|
val inputFiles = KotlinTestUtils.createTestFiles(file.name, fileContent, testFactory, true, coroutinesPackage)
|
||||||
val modules = inputFiles
|
val modules = inputFiles
|
||||||
.map { it.module }.distinct()
|
.map { it.module }.distinct()
|
||||||
.map { it.name to it }.toMap()
|
.map { it.name to it }.toMap()
|
||||||
@@ -637,10 +634,11 @@ abstract class BasicBoxTest(
|
|||||||
TestCase.assertEquals(expectedResult, result)
|
TestCase.assertEquals(expectedResult, result)
|
||||||
}
|
}
|
||||||
|
|
||||||
private inner class TestFileFactoryImpl : TestFileFactory<TestModule, TestFile>, Closeable {
|
private inner class TestFileFactoryImpl(val coroutinesPackage: String) : TestFileFactory<TestModule, TestFile>, Closeable {
|
||||||
var testPackage: String? = null
|
var testPackage: String? = null
|
||||||
val tmpDir = KotlinTestUtils.tmpDir("js-tests")
|
val tmpDir = KotlinTestUtils.tmpDir("js-tests")
|
||||||
val defaultModule = TestModule(TEST_MODULE, emptyList(), emptyList())
|
val defaultModule = TestModule(TEST_MODULE, emptyList(), emptyList())
|
||||||
|
var languageVersionSettings: LanguageVersionSettings? = null
|
||||||
|
|
||||||
override fun createFile(module: TestModule?, fileName: String, text: String, directives: Map<String, String>): TestFile? {
|
override fun createFile(module: TestModule?, fileName: String, text: String, directives: Map<String, String>): TestFile? {
|
||||||
val currentModule = module ?: defaultModule
|
val currentModule = module ?: defaultModule
|
||||||
@@ -667,10 +665,38 @@ abstract class BasicBoxTest(
|
|||||||
KotlinTestUtils.mkdirs(temporaryFile.parentFile)
|
KotlinTestUtils.mkdirs(temporaryFile.parentFile)
|
||||||
temporaryFile.writeText(text, Charsets.UTF_8)
|
temporaryFile.writeText(text, Charsets.UTF_8)
|
||||||
|
|
||||||
val old = currentModule.languageVersionSettings
|
// TODO Deduplicate logic copied from CodegenTestCase.updateConfigurationByDirectivesInTestFiles
|
||||||
val new = parseLanguageVersionSettings(directives)
|
fun LanguageVersion.toSettings() = CompilerTestLanguageVersionSettings(
|
||||||
assert(old == null || old == new) { "Should not specify language version settings twice:\n$old\n$new" }
|
emptyMap(),
|
||||||
currentModule.languageVersionSettings = new
|
ApiVersion.createByLanguageVersion(this),
|
||||||
|
this,
|
||||||
|
emptyMap()
|
||||||
|
)
|
||||||
|
|
||||||
|
fun LanguageVersionSettings.trySet() {
|
||||||
|
val old = languageVersionSettings
|
||||||
|
assert(old == null || old == this) { "Should not specify language version settings twice:\n$old\n$this" }
|
||||||
|
languageVersionSettings = this
|
||||||
|
}
|
||||||
|
InTextDirectivesUtils.findStringWithPrefixes(text, "// LANGUAGE_VERSION:")?.let {
|
||||||
|
LanguageVersion.fromVersionString(it)?.toSettings()?.trySet()
|
||||||
|
}
|
||||||
|
if (!InTextDirectivesUtils.findLinesWithPrefixesRemoved(text, "// COMMON_COROUTINES_TEST").isEmpty()) {
|
||||||
|
assert(!text.contains("COROUTINES_PACKAGE")) { "Must replace COROUTINES_PACKAGE prior to tests compilation" }
|
||||||
|
if (!coroutinesPackage.isEmpty()) {
|
||||||
|
if (coroutinesPackage == "kotlin.coroutines.experimental") {
|
||||||
|
LanguageVersion.KOTLIN_1_2.toSettings().trySet()
|
||||||
|
} else {
|
||||||
|
LanguageVersion.KOTLIN_1_3.toSettings().trySet()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
parseLanguageVersionSettings(directives)?.trySet()
|
||||||
|
|
||||||
|
// Relies on the order of module creation
|
||||||
|
// TODO is that ok?
|
||||||
|
currentModule.languageVersionSettings = languageVersionSettings
|
||||||
|
|
||||||
SOURCE_MAP_SOURCE_EMBEDDING.find(text)?.let { match ->
|
SOURCE_MAP_SOURCE_EMBEDDING.find(text)?.let { match ->
|
||||||
currentModule.sourceMapSourceEmbedding = SourceMapSourceEmbedding.valueOf(match.groupValues[1])
|
currentModule.sourceMapSourceEmbedding = SourceMapSourceEmbedding.valueOf(match.groupValues[1])
|
||||||
|
|||||||
+6
-1
@@ -5015,8 +5015,13 @@ public class IrJsCodegenBoxTestGenerated extends AbstractIrJsCodegenBoxTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@TestMetadata("createCoroutinesOnManualInstances.kt")
|
@TestMetadata("createCoroutinesOnManualInstances.kt")
|
||||||
|
public void testCreateCoroutinesOnManualInstances() throws Exception {
|
||||||
|
runTest("compiler/testData/codegen/box/coroutines/createCoroutinesOnManualInstances.kt");
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("createCoroutinesOnManualInstances_1_2.kt")
|
||||||
public void testCreateCoroutinesOnManualInstances_1_2() throws Exception {
|
public void testCreateCoroutinesOnManualInstances_1_2() throws Exception {
|
||||||
runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/createCoroutinesOnManualInstances.kt", "kotlin.coroutines.experimental");
|
runTest("compiler/testData/codegen/box/coroutines/createCoroutinesOnManualInstances_1_2.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
@TestMetadata("crossInlineWithCapturedOuterReceiver.kt")
|
@TestMetadata("crossInlineWithCapturedOuterReceiver.kt")
|
||||||
|
|||||||
+1012
-15
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user