From 115cf4666e48f1da0c2e202452d2d3e414d8a8cf Mon Sep 17 00:00:00 2001 From: Mikhail Bogdanov Date: Thu, 9 Apr 2020 12:04:54 +0200 Subject: [PATCH] Get rid of CodegenTestCase from CodegenTestsOnAndroidGenerator superclass --- .../tests/CodegenTestsOnAndroidGenerator.kt | 30 ++++++++------- .../kotlin/codegen/CodegenTestCase.java | 2 +- .../jetbrains/kotlin/test/KotlinBaseTest.kt | 38 +++++++++++++------ 3 files changed, 44 insertions(+), 26 deletions(-) diff --git a/compiler/android-tests/tests/org/jetbrains/kotlin/android/tests/CodegenTestsOnAndroidGenerator.kt b/compiler/android-tests/tests/org/jetbrains/kotlin/android/tests/CodegenTestsOnAndroidGenerator.kt index f71969c52df..1514df3d386 100644 --- a/compiler/android-tests/tests/org/jetbrains/kotlin/android/tests/CodegenTestsOnAndroidGenerator.kt +++ b/compiler/android-tests/tests/org/jetbrains/kotlin/android/tests/CodegenTestsOnAndroidGenerator.kt @@ -5,6 +5,7 @@ package org.jetbrains.kotlin.android.tests +import com.intellij.openapi.Disposable import com.intellij.openapi.util.Disposer import com.intellij.openapi.util.SystemInfo import com.intellij.openapi.util.io.FileUtil @@ -22,15 +23,14 @@ import org.jetbrains.kotlin.idea.KotlinFileType import org.jetbrains.kotlin.psi.KtFile import org.jetbrains.kotlin.test.* import org.junit.Assert -import org.junit.Ignore import java.io.File import java.io.FileWriter import java.io.IOException +import kotlin.test.assertTrue data class ConfigurationKey(val kind: ConfigurationKind, val jdkKind: TestJdkKind, val configuration: String) -@Ignore -class CodegenTestsOnAndroidGenerator private constructor(private val pathManager: PathManager) : CodegenTestCase() { +class CodegenTestsOnAndroidGenerator private constructor(private val pathManager: PathManager) { private var writtenFilesCount = 0 private var currentModuleIndex = 1 @@ -143,7 +143,11 @@ class CodegenTestsOnAndroidGenerator private constructor(private val pathManager } fun writeFilesOnDisk() { - val disposable = TestDisposable() + //don't convert to sam (identity lose) + @Suppress("ObjectLiteralToLambda") + val disposable = object : Disposable { + override fun dispose() {} + } val environment = KotlinCoreEnvironment.createForTests( disposable, @@ -173,7 +177,7 @@ class CodegenTestsOnAndroidGenerator private constructor(private val pathManager writtenFilesCount += filesToCompile.size val index = writtenFilesCount / 2500 val outputDir = File(pathManager.getOutputForCompiledFiles(index)) - assertTrue("Add flavors for ktest$index", index < 3) + assertTrue("Add flavors for ktest$index") { index < 3 } println("Generating ${filesToCompile.size} files into ${outputDir.name}, configuration: '${environment.configuration}'...") @@ -248,16 +252,16 @@ class CodegenTestsOnAndroidGenerator private constructor(private val pathManager if (hasBoxMethod(fullFileText)) { val testFiles = createTestFiles(file, fullFileText) - val kind = extractConfigurationKind(testFiles) - val jdkKind = getTestJdkKind(testFiles) + val kind = KotlinBaseTest.extractConfigurationKind(testFiles) + val jdkKind = KotlinBaseTest.getTestJdkKind(testFiles) val keyConfiguration = CompilerConfiguration() - updateConfigurationByDirectivesInTestFiles(testFiles, keyConfiguration) + CodegenTestCase.updateConfigurationByDirectivesInTestFiles(testFiles, keyConfiguration) val key = ConfigurationKey(kind, jdkKind, keyConfiguration.toString()) val filesHolder = holders.getOrPut(key) { FilesWriter(KotlinTestUtils.newConfiguration(kind, jdkKind, KotlinTestUtils.getAnnotationsJar()).apply { println("Creating new configuration by $key") - updateConfigurationByDirectivesInTestFiles(testFiles, this) + CodegenTestCase.updateConfigurationByDirectivesInTestFiles(testFiles, this) }) } @@ -267,13 +271,13 @@ class CodegenTestsOnAndroidGenerator private constructor(private val pathManager } } - private fun createTestFiles(file: File, expectedText: String): List = + private fun createTestFiles(file: File, expectedText: String): List = TestFiles.createTestFiles( file.name, expectedText, - object : TestFiles.TestFileFactoryNoModules() { - override fun create(fileName: String, text: String, directives: Directives): TestFile { - return TestFile(fileName, text, directives) + object : TestFiles.TestFileFactoryNoModules() { + override fun create(fileName: String, text: String, directives: Directives): KotlinBaseTest.TestFile { + return KotlinBaseTest.TestFile(fileName, text, directives) } }, false, "kotlin.coroutines" diff --git a/compiler/tests-common/tests/org/jetbrains/kotlin/codegen/CodegenTestCase.java b/compiler/tests-common/tests/org/jetbrains/kotlin/codegen/CodegenTestCase.java index 7d7335e678b..5f68e5dc33a 100644 --- a/compiler/tests-common/tests/org/jetbrains/kotlin/codegen/CodegenTestCase.java +++ b/compiler/tests-common/tests/org/jetbrains/kotlin/codegen/CodegenTestCase.java @@ -140,7 +140,7 @@ public abstract class CodegenTestCase extends KotlinBaseTest testFilesWithConfigurationDirectives, @NotNull CompilerConfiguration configuration ) { diff --git a/compiler/tests-common/tests/org/jetbrains/kotlin/test/KotlinBaseTest.kt b/compiler/tests-common/tests/org/jetbrains/kotlin/test/KotlinBaseTest.kt index e0842199fc7..7eeb80af1e7 100644 --- a/compiler/tests-common/tests/org/jetbrains/kotlin/test/KotlinBaseTest.kt +++ b/compiler/tests-common/tests/org/jetbrains/kotlin/test/KotlinBaseTest.kt @@ -7,7 +7,6 @@ package org.jetbrains.kotlin.test import org.jetbrains.kotlin.test.testFramework.KtUsefulTestCase import java.io.File -import java.util.* abstract class KotlinBaseTest : KtUsefulTestCase() { @@ -56,17 +55,7 @@ abstract class KotlinBaseTest : KtUsefulTestCase() } protected open fun extractConfigurationKind(files: List): ConfigurationKind { - var addRuntime = false - var addReflect = false - for (file in files) { - if (InTextDirectivesUtils.isDirectiveDefined(file.content, "WITH_RUNTIME")) { - addRuntime = true - } - if (InTextDirectivesUtils.isDirectiveDefined(file.content, "WITH_REFLECT")) { - addReflect = true - } - } - return if (addReflect) ConfigurationKind.ALL else if (addRuntime) ConfigurationKind.NO_KOTLIN_REFLECT else ConfigurationKind.JDK_ONLY + return Companion.extractConfigurationKind(files) } @@ -106,4 +95,29 @@ abstract class KotlinBaseTest : KtUsefulTestCase() override fun toString(): String = name } + + companion object { + fun extractConfigurationKind(files: List): ConfigurationKind { + var addRuntime = false + var addReflect = false + for (file in files) { + if (InTextDirectivesUtils.isDirectiveDefined(file.content, "WITH_RUNTIME")) { + addRuntime = true + } + if (InTextDirectivesUtils.isDirectiveDefined(file.content, "WITH_REFLECT")) { + addReflect = true + } + } + return if (addReflect) ConfigurationKind.ALL else if (addRuntime) ConfigurationKind.NO_KOTLIN_REFLECT else ConfigurationKind.JDK_ONLY + } + + fun getTestJdkKind(files: List): TestJdkKind { + for (file in files) { + if (InTextDirectivesUtils.isDirectiveDefined(file.content, "FULL_JDK")) { + return TestJdkKind.FULL_JDK + } + } + return TestJdkKind.MOCK_JDK + } + } } \ No newline at end of file