Get rid of CodegenTestCase from CodegenTestsOnAndroidGenerator superclass
This commit is contained in:
+17
-13
@@ -5,6 +5,7 @@
|
|||||||
|
|
||||||
package org.jetbrains.kotlin.android.tests
|
package org.jetbrains.kotlin.android.tests
|
||||||
|
|
||||||
|
import com.intellij.openapi.Disposable
|
||||||
import com.intellij.openapi.util.Disposer
|
import com.intellij.openapi.util.Disposer
|
||||||
import com.intellij.openapi.util.SystemInfo
|
import com.intellij.openapi.util.SystemInfo
|
||||||
import com.intellij.openapi.util.io.FileUtil
|
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.psi.KtFile
|
||||||
import org.jetbrains.kotlin.test.*
|
import org.jetbrains.kotlin.test.*
|
||||||
import org.junit.Assert
|
import org.junit.Assert
|
||||||
import org.junit.Ignore
|
|
||||||
import java.io.File
|
import java.io.File
|
||||||
import java.io.FileWriter
|
import java.io.FileWriter
|
||||||
import java.io.IOException
|
import java.io.IOException
|
||||||
|
import kotlin.test.assertTrue
|
||||||
|
|
||||||
data class ConfigurationKey(val kind: ConfigurationKind, val jdkKind: TestJdkKind, val configuration: String)
|
data class ConfigurationKey(val kind: ConfigurationKind, val jdkKind: TestJdkKind, val configuration: String)
|
||||||
|
|
||||||
@Ignore
|
class CodegenTestsOnAndroidGenerator private constructor(private val pathManager: PathManager) {
|
||||||
class CodegenTestsOnAndroidGenerator private constructor(private val pathManager: PathManager) : CodegenTestCase() {
|
|
||||||
private var writtenFilesCount = 0
|
private var writtenFilesCount = 0
|
||||||
|
|
||||||
private var currentModuleIndex = 1
|
private var currentModuleIndex = 1
|
||||||
@@ -143,7 +143,11 @@ class CodegenTestsOnAndroidGenerator private constructor(private val pathManager
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun writeFilesOnDisk() {
|
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(
|
val environment = KotlinCoreEnvironment.createForTests(
|
||||||
disposable,
|
disposable,
|
||||||
@@ -173,7 +177,7 @@ class CodegenTestsOnAndroidGenerator private constructor(private val pathManager
|
|||||||
writtenFilesCount += filesToCompile.size
|
writtenFilesCount += filesToCompile.size
|
||||||
val index = writtenFilesCount / 2500
|
val index = writtenFilesCount / 2500
|
||||||
val outputDir = File(pathManager.getOutputForCompiledFiles(index))
|
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}'...")
|
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)) {
|
if (hasBoxMethod(fullFileText)) {
|
||||||
val testFiles = createTestFiles(file, fullFileText)
|
val testFiles = createTestFiles(file, fullFileText)
|
||||||
val kind = extractConfigurationKind(testFiles)
|
val kind = KotlinBaseTest.extractConfigurationKind(testFiles)
|
||||||
val jdkKind = getTestJdkKind(testFiles)
|
val jdkKind = KotlinBaseTest.getTestJdkKind(testFiles)
|
||||||
val keyConfiguration = CompilerConfiguration()
|
val keyConfiguration = CompilerConfiguration()
|
||||||
updateConfigurationByDirectivesInTestFiles(testFiles, keyConfiguration)
|
CodegenTestCase.updateConfigurationByDirectivesInTestFiles(testFiles, keyConfiguration)
|
||||||
|
|
||||||
val key = ConfigurationKey(kind, jdkKind, keyConfiguration.toString())
|
val key = ConfigurationKey(kind, jdkKind, keyConfiguration.toString())
|
||||||
val filesHolder = holders.getOrPut(key) {
|
val filesHolder = holders.getOrPut(key) {
|
||||||
FilesWriter(KotlinTestUtils.newConfiguration(kind, jdkKind, KotlinTestUtils.getAnnotationsJar()).apply {
|
FilesWriter(KotlinTestUtils.newConfiguration(kind, jdkKind, KotlinTestUtils.getAnnotationsJar()).apply {
|
||||||
println("Creating new configuration by $key")
|
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<TestFile> =
|
private fun createTestFiles(file: File, expectedText: String): List<KotlinBaseTest.TestFile> =
|
||||||
TestFiles.createTestFiles(
|
TestFiles.createTestFiles(
|
||||||
file.name,
|
file.name,
|
||||||
expectedText,
|
expectedText,
|
||||||
object : TestFiles.TestFileFactoryNoModules<TestFile>() {
|
object : TestFiles.TestFileFactoryNoModules<KotlinBaseTest.TestFile>() {
|
||||||
override fun create(fileName: String, text: String, directives: Directives): TestFile {
|
override fun create(fileName: String, text: String, directives: Directives): KotlinBaseTest.TestFile {
|
||||||
return TestFile(fileName, text, directives)
|
return KotlinBaseTest.TestFile(fileName, text, directives)
|
||||||
}
|
}
|
||||||
}, false,
|
}, false,
|
||||||
"kotlin.coroutines"
|
"kotlin.coroutines"
|
||||||
|
|||||||
@@ -140,7 +140,7 @@ public abstract class CodegenTestCase extends KotlinBaseTest<KotlinBaseTest.Test
|
|||||||
return configuration;
|
return configuration;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected static void updateConfigurationByDirectivesInTestFiles(
|
public static void updateConfigurationByDirectivesInTestFiles(
|
||||||
@NotNull List<TestFile> testFilesWithConfigurationDirectives,
|
@NotNull List<TestFile> testFilesWithConfigurationDirectives,
|
||||||
@NotNull CompilerConfiguration configuration
|
@NotNull CompilerConfiguration configuration
|
||||||
) {
|
) {
|
||||||
|
|||||||
@@ -7,7 +7,6 @@ package org.jetbrains.kotlin.test
|
|||||||
|
|
||||||
import org.jetbrains.kotlin.test.testFramework.KtUsefulTestCase
|
import org.jetbrains.kotlin.test.testFramework.KtUsefulTestCase
|
||||||
import java.io.File
|
import java.io.File
|
||||||
import java.util.*
|
|
||||||
|
|
||||||
abstract class KotlinBaseTest<F : KotlinBaseTest.TestFile> : KtUsefulTestCase() {
|
abstract class KotlinBaseTest<F : KotlinBaseTest.TestFile> : KtUsefulTestCase() {
|
||||||
|
|
||||||
@@ -56,17 +55,7 @@ abstract class KotlinBaseTest<F : KotlinBaseTest.TestFile> : KtUsefulTestCase()
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected open fun extractConfigurationKind(files: List<F>): ConfigurationKind {
|
protected open fun extractConfigurationKind(files: List<F>): ConfigurationKind {
|
||||||
var addRuntime = false
|
return Companion.extractConfigurationKind(files)
|
||||||
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
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -106,4 +95,29 @@ abstract class KotlinBaseTest<F : KotlinBaseTest.TestFile> : KtUsefulTestCase()
|
|||||||
|
|
||||||
override fun toString(): String = name
|
override fun toString(): String = name
|
||||||
}
|
}
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
fun extractConfigurationKind(files: List<TestFile>): 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<TestFile>): TestJdkKind {
|
||||||
|
for (file in files) {
|
||||||
|
if (InTextDirectivesUtils.isDirectiveDefined(file.content, "FULL_JDK")) {
|
||||||
|
return TestJdkKind.FULL_JDK
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return TestJdkKind.MOCK_JDK
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user