[KAPT] Migrate kapt tests to new test infrastructure
This commit is contained in:
committed by
teamcity
parent
fdf1b8b1c0
commit
9c41e75802
+2
-1
@@ -35,7 +35,8 @@ class SimpleDirective(
|
||||
class StringDirective(
|
||||
name: String,
|
||||
description: String,
|
||||
applicability: DirectiveApplicability
|
||||
applicability: DirectiveApplicability,
|
||||
val multiLine: Boolean
|
||||
) : Directive(name, description, applicability)
|
||||
|
||||
class ValueDirective<T : Any>(
|
||||
|
||||
+3
-2
@@ -29,9 +29,10 @@ abstract class SimpleDirectivesContainer : DirectivesContainer() {
|
||||
|
||||
protected fun stringDirective(
|
||||
description: String,
|
||||
applicability: DirectiveApplicability = DirectiveApplicability.Global
|
||||
applicability: DirectiveApplicability = DirectiveApplicability.Global,
|
||||
multiLine: Boolean = false
|
||||
): DirectiveDelegateProvider<StringDirective> {
|
||||
return DirectiveDelegateProvider { StringDirective(it, description, applicability) }
|
||||
return DirectiveDelegateProvider { StringDirective(it, description, applicability, multiLine) }
|
||||
}
|
||||
|
||||
protected inline fun <reified T : Enum<T>> enumDirective(
|
||||
|
||||
+8
@@ -17,6 +17,7 @@ import org.jetbrains.kotlin.idea.KotlinLanguage
|
||||
import org.jetbrains.kotlin.psi.KtFile
|
||||
import org.jetbrains.kotlin.sourceFiles.LightTreeFile
|
||||
import org.jetbrains.kotlin.test.model.TestFile
|
||||
import org.jetbrains.kotlin.test.model.TestModule
|
||||
import org.jetbrains.kotlin.test.util.KtTestUtil
|
||||
import org.jetbrains.kotlin.toSourceLinesMapping
|
||||
import java.io.File
|
||||
@@ -142,3 +143,10 @@ val TestFile.isJsFile: Boolean
|
||||
|
||||
val TestFile.isMjsFile: Boolean
|
||||
get() = name.endsWith(".mjs")
|
||||
|
||||
val TestModule.javaFiles: List<TestFile>
|
||||
get() = files.filter { it.isJavaFile }
|
||||
|
||||
fun SourceFileProvider.getRealJavaFiles(module: TestModule): List<File> {
|
||||
return module.javaFiles.map { getRealFileForSourceFile(it) }
|
||||
}
|
||||
|
||||
+1
@@ -10,6 +10,7 @@ import java.io.File
|
||||
abstract class TemporaryDirectoryManager(protected val testServices: TestServices) : TestService {
|
||||
abstract fun getOrCreateTempDirectory(name: String): File
|
||||
abstract fun cleanupTemporaryDirectories()
|
||||
abstract val rootDir: File
|
||||
}
|
||||
|
||||
val TestServices.temporaryDirectoryManager: TemporaryDirectoryManager by TestServices.testServiceAccessor()
|
||||
|
||||
+9
-5
@@ -18,12 +18,13 @@ class RegisteredDirectivesParser(private val container: DirectivesContainer, pri
|
||||
fun parseDirective(line: String): RawDirective? {
|
||||
val result = DIRECTIVE_PATTERN.matchEntire(line)?.groupValues ?: return null
|
||||
val name = result.getOrNull(NAME_GROUP) ?: return null
|
||||
val values = result.getOrNull(VALUES_GROUP)?.split(SPACES_PATTERN)?.filter { it.isNotBlank() }?.takeIf { it.isNotEmpty() }
|
||||
return RawDirective(name, values)
|
||||
val rawValue = result.getOrNull(VALUES_GROUP)
|
||||
val values = rawValue?.split(SPACES_PATTERN)?.filter { it.isNotBlank() }?.takeIf { it.isNotEmpty() }
|
||||
return RawDirective(name, values, rawValue)
|
||||
}
|
||||
}
|
||||
|
||||
data class RawDirective(val name: String, val values: List<String>?)
|
||||
data class RawDirective(val name: String, val values: List<String>?, val rawValue: String?)
|
||||
data class ParsedDirective(val directive: Directive, val values: List<*>)
|
||||
|
||||
private val simpleDirectives = mutableListOf<SimpleDirective>()
|
||||
@@ -58,7 +59,7 @@ class RegisteredDirectivesParser(private val container: DirectivesContainer, pri
|
||||
}
|
||||
|
||||
fun convertToRegisteredDirective(rawDirective: RawDirective): ParsedDirective? {
|
||||
val (name, rawValues) = rawDirective
|
||||
val (name, rawValues, rawValueString) = rawDirective
|
||||
val directive = container[name] ?: return null
|
||||
|
||||
val values: List<*> = when (directive) {
|
||||
@@ -72,7 +73,10 @@ class RegisteredDirectivesParser(private val container: DirectivesContainer, pri
|
||||
}
|
||||
|
||||
is StringDirective -> {
|
||||
rawValues ?: emptyList<Any?>()
|
||||
when (directive.multiLine) {
|
||||
true -> listOfNotNull(rawValueString)
|
||||
false -> rawValues ?: emptyList()
|
||||
}
|
||||
}
|
||||
|
||||
is ValueDirective<*> -> {
|
||||
|
||||
+2
-5
@@ -15,11 +15,8 @@ import org.jetbrains.kotlin.test.compileJavaFilesExternally
|
||||
import org.jetbrains.kotlin.test.directives.CodegenTestDirectives
|
||||
import org.jetbrains.kotlin.test.directives.CodegenTestDirectives.USE_JAVAC_BASED_ON_JVM_TARGET
|
||||
import org.jetbrains.kotlin.test.model.TestModule
|
||||
import org.jetbrains.kotlin.test.services.TestServices
|
||||
import org.jetbrains.kotlin.test.services.assertions
|
||||
import org.jetbrains.kotlin.test.services.javaFiles
|
||||
import org.jetbrains.kotlin.test.services.*
|
||||
import org.jetbrains.kotlin.test.services.jvm.compiledClassesManager
|
||||
import org.jetbrains.kotlin.test.services.sourceFileProvider
|
||||
import org.jetbrains.kotlin.test.util.KtTestUtil
|
||||
import java.io.File
|
||||
|
||||
@@ -43,7 +40,7 @@ class JavaCompilerFacade(private val testServices: TestServices) {
|
||||
javaClassesOutputDirectory
|
||||
)
|
||||
|
||||
val javaFiles = module.javaFiles.map { testServices.sourceFileProvider.getRealFileForSourceFile(it) }
|
||||
val javaFiles = testServices.sourceFileProvider.getRealJavaFiles(module)
|
||||
val ignoreErrors = CodegenTestDirectives.IGNORE_JAVA_ERRORS in module.directives
|
||||
compileJavaFiles(module, configuration[JVMConfigurationKeys.JVM_TARGET] ?: JvmTarget.DEFAULT, javaFiles, finalJavacOptions, ignoreErrors)
|
||||
}
|
||||
|
||||
+4
-2
@@ -22,6 +22,7 @@ import org.jetbrains.kotlin.types.AbstractTypeChecker
|
||||
import org.jetbrains.kotlin.types.FlexibleTypeImpl
|
||||
import org.junit.jupiter.api.BeforeEach
|
||||
import org.junit.jupiter.api.TestInfo
|
||||
import kotlin.jvm.optionals.getOrNull
|
||||
|
||||
abstract class AbstractKotlinCompilerTest {
|
||||
companion object {
|
||||
@@ -68,11 +69,12 @@ abstract class AbstractKotlinCompilerTest {
|
||||
}
|
||||
|
||||
@BeforeEach
|
||||
@OptIn(ExperimentalStdlibApi::class)
|
||||
fun initTestInfo(testInfo: TestInfo) {
|
||||
initTestInfo(
|
||||
KotlinTestInfo(
|
||||
className = testInfo.testClass.orElseGet(null)?.name ?: "_undefined_",
|
||||
methodName = testInfo.testMethod.orElseGet(null)?.name ?: "_testUndefined_",
|
||||
className = testInfo.testClass.getOrNull()?.name ?: "_undefined_",
|
||||
methodName = testInfo.testMethod.getOrNull()?.name ?: "_testUndefined_",
|
||||
tags = testInfo.tags
|
||||
)
|
||||
)
|
||||
|
||||
-3
@@ -151,6 +151,3 @@ fun createCompilerConfiguration(module: TestModule, configurators: List<Abstract
|
||||
private operator fun <T : Any> CompilerConfiguration.set(key: CompilerConfigurationKey<T>, value: T) {
|
||||
put(key, value)
|
||||
}
|
||||
|
||||
val TestModule.javaFiles: List<TestFile>
|
||||
get() = files.filter { it.isJavaFile }
|
||||
|
||||
+3
@@ -29,6 +29,9 @@ class TemporaryDirectoryManagerImpl(testServices: TestServices) : TemporaryDirec
|
||||
KtTestUtil.tmpDirForTest(packageName + simplifiedClassName, "test$simplifiedMethodName")
|
||||
}
|
||||
|
||||
override val rootDir: File
|
||||
get() = rootTempDir
|
||||
|
||||
override fun getOrCreateTempDirectory(name: String): File {
|
||||
return cache.getOrPut(name) { KtTestUtil.tmpDir(rootTempDir, name) }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user