From 1ced127660e347a62ba0a030f08b9969dc08c1a5 Mon Sep 17 00:00:00 2001 From: Denis Zharkov Date: Fri, 22 Jun 2018 12:33:12 +0300 Subject: [PATCH] Minor. Move helpers for coroutines tests to kt-file --- .../org/jetbrains/kotlin/coroutineTestUtil.kt | 38 +++++++++++++++++++ .../kotlin/test/KotlinTestUtils.java | 27 +------------ 2 files changed, 40 insertions(+), 25 deletions(-) create mode 100644 compiler/tests-common/tests/org/jetbrains/kotlin/coroutineTestUtil.kt diff --git a/compiler/tests-common/tests/org/jetbrains/kotlin/coroutineTestUtil.kt b/compiler/tests-common/tests/org/jetbrains/kotlin/coroutineTestUtil.kt new file mode 100644 index 00000000000..e38a718bc16 --- /dev/null +++ b/compiler/tests-common/tests/org/jetbrains/kotlin/coroutineTestUtil.kt @@ -0,0 +1,38 @@ +/* + * Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license + * that can be found in the license/LICENSE.txt file. + */ + +package org.jetbrains.kotlin + +fun createTextForHelpers(coroutinesPackage: String): String { + return """ + |package helpers + |import $coroutinesPackage.* + | + |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?) { } + |} + | + |open class EmptyContinuation(override val context: CoroutineContext = EmptyCoroutineContext) : Continuation { + | companion object : EmptyContinuation() + | override fun resume(data: Any?) {} + | override fun resumeWithException(exception: Throwable) { throw exception } + |} + """.trimMargin() +} diff --git a/compiler/tests-common/tests/org/jetbrains/kotlin/test/KotlinTestUtils.java b/compiler/tests-common/tests/org/jetbrains/kotlin/test/KotlinTestUtils.java index 8fd7df18622..23cefa57c65 100644 --- a/compiler/tests-common/tests/org/jetbrains/kotlin/test/KotlinTestUtils.java +++ b/compiler/tests-common/tests/org/jetbrains/kotlin/test/KotlinTestUtils.java @@ -35,6 +35,7 @@ import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.TestOnly; +import org.jetbrains.kotlin.CoroutineTestUtilKt; import org.jetbrains.kotlin.analyzer.AnalysisResult; import org.jetbrains.kotlin.builtins.DefaultBuiltIns; import org.jetbrains.kotlin.builtins.KotlinBuiltIns; @@ -787,31 +788,7 @@ public class KotlinTestUtils { } testFiles.add(factory.createFile(supportModule, "CoroutineUtil.kt", - "package helpers\n" + - "import " + coroutinesPackage + ".*\n" + - "fun handleResultContinuation(x: (T) -> Unit): Continuation = object: Continuation {\n" + - " override val context = EmptyCoroutineContext\n" + - " override fun resumeWithException(exception: Throwable) {\n" + - " throw exception\n" + - " }\n" + - "\n" + - " override fun resume(data: T) = x(data)\n" + - "}\n" + - "\n" + - "fun handleExceptionContinuation(x: (Throwable) -> Unit): Continuation = object: Continuation {\n" + - " override val context = EmptyCoroutineContext\n" + - " override fun resumeWithException(exception: Throwable) {\n" + - " x(exception)\n" + - " }\n" + - "\n" + - " override fun resume(data: Any?) { }\n" + - "}\n" + - "\n" + - "open class EmptyContinuation(override val context: CoroutineContext = EmptyCoroutineContext) : Continuation {\n" + - " companion object : EmptyContinuation()\n" + - " override fun resume(data: Any?) {}\n" + - " override fun resumeWithException(exception: Throwable) { throw exception }\n" + - "}", + CoroutineTestUtilKt.createTextForHelpers(coroutinesPackage), directives )); }