Add workaround for obsolete inline suspend integration test
Restore test data dropped in 7abd87d5, add specific output check KT-36240
This commit is contained in:
+31
@@ -0,0 +1,31 @@
|
||||
package library
|
||||
|
||||
import kotlin.coroutines.experimental.*
|
||||
|
||||
var continuation: Continuation<Unit>? = null
|
||||
val sb = java.lang.StringBuilder()
|
||||
|
||||
fun append(s: String) { sb.append(s) }
|
||||
|
||||
val libraryResult: String get() = sb.toString()
|
||||
|
||||
// this is an inline tail-suspend function that should work properly despite being compiler by
|
||||
// compiler before 1.1.4 version that did not include suspension marks into bytecode.
|
||||
// In order to test that it works properly it shall actually suspend during its execution
|
||||
inline suspend fun foo(block: () -> Unit) {
|
||||
append("(foo)")
|
||||
block()
|
||||
return suspendCoroutine<Unit> { continuation = it }
|
||||
}
|
||||
|
||||
suspend fun bar() {
|
||||
append("(bar)")
|
||||
return suspendCoroutine<Unit> { continuation = it }
|
||||
}
|
||||
|
||||
fun resumeLibrary() {
|
||||
continuation?.let {
|
||||
continuation = null
|
||||
it.resume(Unit)
|
||||
}
|
||||
}
|
||||
+2
@@ -0,0 +1,2 @@
|
||||
warning: language version 1.2 is deprecated and its support will be removed in a future version of Kotlin
|
||||
OK
|
||||
+36
@@ -0,0 +1,36 @@
|
||||
import library.*
|
||||
import kotlin.coroutines.experimental.*
|
||||
|
||||
suspend fun test() {
|
||||
append("[foo]")
|
||||
foo { // we are inlining foo here
|
||||
append("(block)")
|
||||
}
|
||||
append("[bar]")
|
||||
bar() // and invoking suspending function bar
|
||||
append("[test]")
|
||||
}
|
||||
|
||||
fun runBlockingLibrary(block: suspend () -> Unit): String {
|
||||
var done = false
|
||||
block.startCoroutine(object : Continuation<Unit> {
|
||||
override val context: CoroutineContext = EmptyCoroutineContext
|
||||
override fun resume(value: Unit) { done = true }
|
||||
override fun resumeWithException(exception: Throwable) { throw exception }
|
||||
})
|
||||
var resumeCounter = 0
|
||||
while (!done) {
|
||||
resumeCounter++
|
||||
resumeLibrary()
|
||||
}
|
||||
return "$libraryResult:resumes=$resumeCounter"
|
||||
}
|
||||
|
||||
// Retruns array of expected and received string
|
||||
fun run(): Array<String> {
|
||||
val result = runBlockingLibrary {
|
||||
test()
|
||||
}
|
||||
return arrayOf("[foo](foo)(block)[bar](bar)[test]:resumes=2", result)
|
||||
}
|
||||
|
||||
+12
-1
@@ -498,7 +498,18 @@ class CompileKotlinAgainstCustomBinariesTest : AbstractKotlinCompilerIntegration
|
||||
val version = intArrayOf(1, 0, 1) // legacy coroutines metadata
|
||||
val options = listOf("-language-version", "1.2", "-Xcoroutines=enable")
|
||||
val library = transformJar(
|
||||
compileLibrary("library", additionalOptions = options, extraClassPath = listOf(ForTestCompileRuntime.coroutinesCompatForTests())),
|
||||
compileLibrary(
|
||||
"library",
|
||||
additionalOptions = options,
|
||||
extraClassPath = listOf(ForTestCompileRuntime.coroutinesCompatForTests()),
|
||||
checkKotlinOutput = { actual ->
|
||||
// TODO KT-36240
|
||||
assertEquals(
|
||||
"warning: language version 1.2 is deprecated and its support will be removed in a future version of Kotlin\nOK\n",
|
||||
actual
|
||||
)
|
||||
}
|
||||
),
|
||||
{ _, bytes ->
|
||||
val (resultBytes, removedCounter) = stripSuspensionMarksToImitateLegacyCompiler(
|
||||
WrongBytecodeVersionTest.transformMetadataInClassFile(bytes) { name, _ ->
|
||||
|
||||
Reference in New Issue
Block a user