From 66aef3bf5aef107db0d12a54bb2d050fda7b94f8 Mon Sep 17 00:00:00 2001 From: Igor Chevdar Date: Mon, 24 Apr 2017 12:36:06 +0300 Subject: [PATCH] Handling of 'WITH_COROUTINES' in tests --- .../org/jetbrains/kotlin/KonanTest.groovy | 38 +++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/buildSrc/src/main/groovy/org/jetbrains/kotlin/KonanTest.groovy b/buildSrc/src/main/groovy/org/jetbrains/kotlin/KonanTest.groovy index 09c3ea22977..5859d20faec 100644 --- a/buildSrc/src/main/groovy/org/jetbrains/kotlin/KonanTest.groovy +++ b/buildSrc/src/main/groovy/org/jetbrains/kotlin/KonanTest.groovy @@ -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 { + companion object : EmptyContinuation() + override fun resume(value: Any?) {} + override fun resumeWithException(exception: Throwable) { throw exception } +} + +fun handleResultContinuation(x: (T) -> Unit): Continuation = object: Continuation { + override val context = EmptyCoroutineContext + override fun resumeWithException(exception: Throwable) { + throw exception + } + + override fun resume(data: T) = x(data) +} + +fun handleExceptionContinuation(x: (Throwable) -> Unit): Continuation = object: Continuation { + override val context = EmptyCoroutineContext + override fun resumeWithException(exception: Throwable) { + x(exception) + } + + override fun resume(data: Any?) { } +} +""" ) + createFile(file, text.toString()) + } + // TODO refactor List 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) {