Remove coroutinesPackage from tests, since it is kotlin.coroutines

anyway.
Simplify createTextForHelpers: remove experimental coroutines version.
This commit is contained in:
Ilmir Usmanov
2021-03-26 20:39:21 +01:00
committed by TeamCityServer
parent c868116535
commit 5617d83c6b
5 changed files with 93 additions and 166 deletions
@@ -8105,11 +8105,6 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
public static class Resume extends AbstractLightAnalysisModeTest {
@TestMetadata("boxTypeParameterOfSuperType.kt")
public void ignoreBoxTypeParameterOfSuperType() throws Exception {
runTest("compiler/testData/codegen/box/coroutines/inlineClasses/resume/boxTypeParameterOfSuperType.kt");
}
private void runTest(String testDataFilePath) throws Exception {
KotlinTestUtils.runTest(this::doTest, TargetBackend.JVM, testDataFilePath);
}
@@ -8128,6 +8123,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes
runTest("compiler/testData/codegen/box/coroutines/inlineClasses/resume/boxReturnValueOfSuspendLambda.kt");
}
@TestMetadata("boxTypeParameterOfSuperType.kt")
public void testBoxTypeParameterOfSuperType() throws Exception {
runTest("compiler/testData/codegen/box/coroutines/inlineClasses/resume/boxTypeParameterOfSuperType.kt");
}
@TestMetadata("boxUnboxInsideCoroutine.kt")
public void testBoxUnboxInsideCoroutine() throws Exception {
runTest("compiler/testData/codegen/box/coroutines/inlineClasses/resume/boxUnboxInsideCoroutine.kt");
@@ -8338,11 +8338,6 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
public static class ResumeWithException extends AbstractLightAnalysisModeTest {
@TestMetadata("boxTypeParameterOfSuperType.kt")
public void ignoreBoxTypeParameterOfSuperType() throws Exception {
runTest("compiler/testData/codegen/box/coroutines/inlineClasses/resumeWithException/boxTypeParameterOfSuperType.kt");
}
private void runTest(String testDataFilePath) throws Exception {
KotlinTestUtils.runTest(this::doTest, TargetBackend.JVM, testDataFilePath);
}
@@ -8361,6 +8356,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes
runTest("compiler/testData/codegen/box/coroutines/inlineClasses/resumeWithException/boxReturnValueOfSuspendLambda.kt");
}
@TestMetadata("boxTypeParameterOfSuperType.kt")
public void testBoxTypeParameterOfSuperType() throws Exception {
runTest("compiler/testData/codegen/box/coroutines/inlineClasses/resumeWithException/boxTypeParameterOfSuperType.kt");
}
@TestMetadata("boxUnboxInsideCoroutine.kt")
public void testBoxUnboxInsideCoroutine() throws Exception {
runTest("compiler/testData/codegen/box/coroutines/inlineClasses/resumeWithException/boxUnboxInsideCoroutine.kt");
@@ -14188,6 +14188,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes
runTest("compiler/testData/codegen/box/inlineClasses/kt44867.kt");
}
@TestMetadata("safeAsOfTypeParameterWithInlineClassBound.kt")
public void ignoreSafeAsOfTypeParameterWithInlineClassBound() throws Exception {
runTest("compiler/testData/codegen/box/inlineClasses/safeAsOfTypeParameterWithInlineClassBound.kt");
}
@TestMetadata("simpleSecondaryConstructor.kt")
public void ignoreSimpleSecondaryConstructor() throws Exception {
runTest("compiler/testData/codegen/box/inlineClasses/simpleSecondaryConstructor.kt");
@@ -14941,11 +14946,6 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes
runTest("compiler/testData/codegen/box/inlineClasses/resultRunCatchingOrElse.kt");
}
@TestMetadata("safeAsOfTypeParameterWithInlineClassBound.kt")
public void testSafeAsOfTypeParameterWithInlineClassBound() throws Exception {
runTest("compiler/testData/codegen/box/inlineClasses/safeAsOfTypeParameterWithInlineClassBound.kt");
}
@TestMetadata("secondaryConstructorWithVararg.kt")
public void testSecondaryConstructorWithVararg() throws Exception {
runTest("compiler/testData/codegen/box/inlineClasses/secondaryConstructorWithVararg.kt");
@@ -101,17 +101,13 @@ abstract class BasicBoxTest(
fun doTest(filePath: String) {
doTestWithIgnoringByFailFile(filePath, coroutinesPackage = "")
doTestWithIgnoringByFailFile(filePath)
}
fun doTestWithCoroutinesPackageReplacement(filePath: String, coroutinesPackage: String) {
doTestWithIgnoringByFailFile(filePath, coroutinesPackage)
}
fun doTestWithIgnoringByFailFile(filePath: String, coroutinesPackage: String) {
fun doTestWithIgnoringByFailFile(filePath: String) {
val failFile = File("$filePath.fail")
try {
doTest(filePath, "OK", MainCallParameters.noCall(), coroutinesPackage)
doTest(filePath, "OK", MainCallParameters.noCall())
} catch (e: Throwable) {
if (failFile.exists()) {
KotlinTestUtils.assertEqualsToFile(failFile, e.message ?: "")
@@ -121,7 +117,7 @@ abstract class BasicBoxTest(
}
}
open fun doTest(filePath: String, expectedResult: String, mainCallParameters: MainCallParameters, coroutinesPackage: String = "") {
open fun doTest(filePath: String, expectedResult: String, mainCallParameters: MainCallParameters) {
val file = File(filePath)
logger.logFile("Test file", file)
@@ -130,9 +126,6 @@ abstract class BasicBoxTest(
val dceOutputDir = getOutputDir(file, testGroupOutputDirForMinification)
val pirOutputDir = getOutputDir(file, testGroupOutputDirForPir)
var fileContent = KtTestUtil.doLoadFile(file)
if (coroutinesPackage.isNotEmpty()) {
fileContent = fileContent.replace("COROUTINES_PACKAGE", coroutinesPackage)
}
val needsFullIrRuntime = KJS_WITH_FULL_RUNTIME.matcher(fileContent).find() || WITH_RUNTIME.matcher(fileContent).find() || WITH_STDLIB.matcher(fileContent).find()
@@ -157,7 +150,7 @@ abstract class BasicBoxTest(
val propertyLazyInitialization = PROPERTY_LAZY_INITIALIZATION.matcher(fileContent).find()
TestFileFactoryImpl(coroutinesPackage).use { testFactory ->
TestFileFactoryImpl().use { testFactory ->
val inputFiles = TestFiles.createTestFiles(
file.name,
fileContent,
@@ -957,7 +950,7 @@ abstract class BasicBoxTest(
TestCase.assertEquals(expectedResult, result)
}
private inner class TestFileFactoryImpl(val coroutinesPackage: String) : TestFiles.TestFileFactory<TestModule, TestFile>, Closeable {
private inner class TestFileFactoryImpl() : TestFiles.TestFileFactory<TestModule, TestFile>, Closeable {
var testPackage: String? = null
val tmpDir = KtTestUtil.tmpDir("js-tests")
val defaultModule = TestModule(TEST_MODULE, emptyList(), emptyList())
@@ -65,10 +65,10 @@ abstract class BasicIrBoxTest(
private val cachedDependencies = mutableMapOf<String, Collection<String>>()
override fun doTest(filePath: String, expectedResult: String, mainCallParameters: MainCallParameters, coroutinesPackage: String) {
override fun doTest(filePath: String, expectedResult: String, mainCallParameters: MainCallParameters) {
compilationCache.clear()
cachedDependencies.clear()
super.doTest(filePath, expectedResult, mainCallParameters, coroutinesPackage)
super.doTest(filePath, expectedResult, mainCallParameters)
}
override val testChecker get() = if (runTestInNashorn) NashornIrJsTestChecker() else V8IrJsTestChecker
@@ -11,7 +11,6 @@ import java.nio.file.Path
import java.nio.file.Paths
import java.util.regex.Matcher
import java.util.regex.Pattern
import java.io.File
private const val MODULE_DELIMITER = ",\\s*"
// These patterns are copies from
@@ -34,8 +33,7 @@ fun buildCompileList(source: Path, outputDirectory: String): List<TestFile> {
val srcText = srcFile.readText().replace(Regex("<!.*?!>(.*?)<!>")) { match -> match.groupValues[1] }
if (srcText.contains("// WITH_COROUTINES")) {
result.add(TestFile("helpers.kt", "$outputDirectory/helpers.kt",
createTextForHelpers(true), TestModule.support))
result.add(TestFile("helpers.kt", "$outputDirectory/helpers.kt", createTextForHelpers(), TestModule.support))
}
val matcher = FILE_OR_MODULE_PATTERN.matcher(srcText)
@@ -7,138 +7,74 @@ package org.jetbrains.kotlin
// This is almost a full copy of kotlin/compiler/tests-common/tests/org/jetbrains/kotlin/coroutineTestUtil.kt
// TODO: get it automatically as a dependency
fun createTextForHelpers(isReleaseCoroutines: Boolean): String {
val coroutinesPackage = "kotlin.coroutines"
fun createTextForHelpers(): String = """
package helpers
import kotlin.coroutines.*
val emptyContinuationBody =
if (isReleaseCoroutines)
"""
|override fun resumeWith(result: Result<Any?>) {
| result.getOrThrow()
|}
""".trimMargin()
else
"""
|override fun resume(data: Any?) {}
|override fun resumeWithException(exception: Throwable) { throw exception }
""".trimMargin()
val handleResultContinuationBody =
if (isReleaseCoroutines)
"""
|override fun resumeWith(result: Result<T>) {
| x(result.getOrThrow())
|}
""".trimMargin()
else
"""
|override fun resumeWithException(exception: Throwable) {
| throw exception
|}
|
|override fun resume(data: T) = x(data)
""".trimMargin()
val handleExceptionContinuationBody =
if (isReleaseCoroutines)
"""
|override fun resumeWith(result: Result<Any?>) {
| result.exceptionOrNull()?.let(x)
|}
""".trimMargin()
else
"""
|override fun resumeWithException(exception: Throwable) {
| x(exception)
|}
|
|override fun resume(data: Any?) {}
""".trimMargin()
val continuationAdapterBody =
if (isReleaseCoroutines)
"""
|override fun resumeWith(result: Result<T>) {
| if (result.isSuccess) {
| resume(result.getOrThrow())
| } else {
| resumeWithException(result.exceptionOrNull()!!)
| }
|}
|
|abstract fun resumeWithException(exception: Throwable)
|abstract fun resume(value: T)
""".trimMargin()
else
""
return """
|package helpers
|import $coroutinesPackage.*
|
|fun <T> handleResultContinuation(x: (T) -> Unit): Continuation<T> = object: Continuation<T> {
| override val context = EmptyCoroutineContext
| $handleResultContinuationBody
|}
|
|
|fun handleExceptionContinuation(x: (Throwable) -> Unit): Continuation<Any?> = object: Continuation<Any?> {
| override val context = EmptyCoroutineContext
| $handleExceptionContinuationBody
|}
|
|open class EmptyContinuation(override val context: CoroutineContext = EmptyCoroutineContext) : Continuation<Any?> {
| companion object : EmptyContinuation()
| $emptyContinuationBody
|}
|
|abstract class ContinuationAdapter<in T> : Continuation<T> {
| override val context: CoroutineContext = EmptyCoroutineContext
| $continuationAdapterBody
|}
|class StateMachineCheckerClass {
| private var counter = 0
| var finished = false
|
| var proceed: () -> Unit = {}
|
| fun reset() {
| counter = 0
| finished = false
| proceed = {}
| }
|
| suspend fun suspendHere() = suspendCoroutine<Unit> { c ->
| counter++
| proceed = { c.resume(Unit) }
| }
|
| fun check(numberOfSuspensions: Int, checkFinished: Boolean = true) {
| for (i in 1..numberOfSuspensions) {
| if (counter != i) error("Wrong state-machine generated: suspendHere called should be called exactly once in one state. Expected " + i + ", got " + counter)
| proceed()
| }
| if (counter != numberOfSuspensions)
| error("Wrong state-machine generated: suspendHere called should be called exactly once in one state. Expected " + numberOfSuspensions + ", got " + counter)
| if (finished) error("Wrong state-machine generated: it is finished early")
| proceed()
| if (checkFinished && !finished) error("Wrong state-machine generated: it is not finished yet")
| }
|}
|val StateMachineChecker = StateMachineCheckerClass()
|object CheckStateMachineContinuation: ContinuationAdapter<Unit>() {
| override val context: CoroutineContext
| get() = EmptyCoroutineContext
|
| override fun resume(value: Unit) {
| StateMachineChecker.proceed = {
| StateMachineChecker.finished = true
| }
| }
|
| override fun resumeWithException(exception: Throwable) {
| throw exception
| }
|}
""".trimMargin()
fun <T> handleResultContinuation(x: (T) -> Unit): Continuation<T> = object: Continuation<T> {
override val context = EmptyCoroutineContext
override fun resumeWith(result: Result<T>) {
x(result.getOrThrow())
}
}
fun handleExceptionContinuation(x: (Throwable) -> Unit): Continuation<Any?> = object: Continuation<Any?> {
override val context = EmptyCoroutineContext
override fun resumeWith(result: Result<Any?>) {
result.exceptionOrNull()?.let(x)
}
}
open class EmptyContinuation(override val context: CoroutineContext = EmptyCoroutineContext) : Continuation<Any?> {
companion object : EmptyContinuation()
override fun resumeWith(result: Result<Any?>) {
result.getOrThrow()
}
}
class StateMachineCheckerClass {
private var counter = 0
var finished = false
var proceed: () -> Unit = {}
fun reset() {
counter = 0
finished = false
proceed = {}
}
suspend fun suspendHere() = suspendCoroutine<Unit> { c ->
counter++
proceed = { c.resume(Unit) }
}
fun check(numberOfSuspensions: Int, checkFinished: Boolean = true) {
for (i in 1..numberOfSuspensions) {
if (counter != i) error("Wrong state-machine generated: suspendHere called should be called exactly once in one state. Expected " + i + ", got " + counter)
proceed()
}
if (counter != numberOfSuspensions)
error("Wrong state-machine generated: suspendHere called should be called exactly once in one state. Expected " + numberOfSuspensions + ", got " + counter)
if (finished) error("Wrong state-machine generated: it is finished early")
proceed()
if (checkFinished && !finished) error("Wrong state-machine generated: it is not finished yet")
}
}
val StateMachineChecker = StateMachineCheckerClass()
object CheckStateMachineContinuation: Continuation<Unit>() {
override val context: CoroutineContext
get() = EmptyCoroutineContext
override fun resumeWith(result: Result<Unit>) {
result.getOrThrow()
StateMachineChecker.proceed = {
StateMachineChecker.finished = true
}
}
}
"""