Handling of 'WITH_COROUTINES' in tests

This commit is contained in:
Igor Chevdar
2017-04-24 12:36:06 +03:00
parent 4f22b4803a
commit 66aef3bf5a
@@ -133,6 +133,37 @@ abstract class KonanTest extends JavaExec {
return sourceFiles
}
void createCoroutineUtil(String file) {
StringBuilder text = new StringBuilder("import kotlin.coroutines.experimental.*\n")
text.append(
"""
open class EmptyContinuation(override val context: CoroutineContext = EmptyCoroutineContext) : Continuation<Any?> {
companion object : EmptyContinuation()
override fun resume(value: Any?) {}
override fun resumeWithException(exception: Throwable) { throw exception }
}
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)
}
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?) { }
}
""" )
createFile(file, text.toString())
}
// TODO refactor
List<String> buildCompileList() {
def result = []
@@ -141,6 +172,12 @@ abstract class KonanTest extends JavaExec {
def srcText = removeDiagnostics(srcFile.text)
def matcher = filePattern.matcher(srcText)
if (srcText.contains('// WITH_COROUTINES')) {
def coroutineUtilFileName = "$outputDirectory/CoroutineUtil.kt"
createCoroutineUtil(coroutineUtilFileName)
result.add(coroutineUtilFileName)
}
if (!matcher.find()) {
// There is only one file in the input
def filePath = "$outputDirectory/${srcFile.name}"
@@ -394,6 +431,7 @@ class RunExternalTestGroup extends RunKonanTest {
for (v in imports) {
text.append("import ").append(v).append('\n')
}
text.append(
"""
fun main(args : Array<String>) {