[Tests] Introduce replacing source transformer
This commit is contained in:
+1
-1
@@ -131,7 +131,7 @@ object NewTestGeneratorImpl : TestGenerator(METHOD_GENERATORS) {
|
||||
for (clazz in testClassModels.flatMapTo(mutableSetOf()) { classModel -> classModel.imports }) {
|
||||
val realName = when (clazz) {
|
||||
TransformingTestMethodModel.TransformerFunctionsClassPlaceHolder::class.java ->
|
||||
"org.jetbrains.kotlin.test.runners.TransformersFunctions"
|
||||
"org.jetbrains.kotlin.test.utils.TransformersFunctions"
|
||||
else -> clazz.name
|
||||
}
|
||||
p.println("import $realName;")
|
||||
|
||||
+13
-6
@@ -23,14 +23,21 @@ object TransformingTestMethodGenerator : MethodGenerator<TransformingTestMethodM
|
||||
|
||||
override fun generateBody(method: TransformingTestMethodModel, p: Printer) {
|
||||
with(method) {
|
||||
if (registerInConstructor) {
|
||||
val lines = transformer.lines()
|
||||
val message = "There is a registered source transformer for the testcase"
|
||||
if (lines.size > 1) {
|
||||
p.println("/*")
|
||||
p.println(" $message:")
|
||||
lines.forEach { p.println(" $it") }
|
||||
p.println("*/")
|
||||
} else {
|
||||
val restOfLine = lines.firstOrNull()?.takeIf { it.isNotBlank() }?.let { ": $it" } ?: ""
|
||||
p.println("// $message$restOfLine")
|
||||
}
|
||||
}
|
||||
val filePath = KtTestUtil.getFilePath(source.file) + if (source.file.isDirectory) "/" else ""
|
||||
p.println("${RunTestMethodModel.METHOD_NAME}(\"$filePath\"${if (registerInConstructor) "" else ", $transformer"});")
|
||||
if (registerInConstructor) {
|
||||
p.println("/*")
|
||||
p.println(" There is a registered source transformer for the testcase:")
|
||||
transformer.lines().forEach { p.println(" $it") }
|
||||
p.println("*/")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+5
-1
@@ -10,9 +10,13 @@ import org.jetbrains.kotlin.test.TargetBackend
|
||||
import java.io.File
|
||||
import java.util.regex.Pattern
|
||||
|
||||
const val WORKS_WHEN_VALUE_CLASS = "WORKS_WHEN_VALUE_CLASS"
|
||||
// will replace OPTIONAL_JVM_INLINE_ANNOTATION with @JvmInline or remove it depending on compiler backend
|
||||
// for JVM IR both ones are generated according to value classes feature (https://github.com/Kotlin/KEEP/issues/237)
|
||||
|
||||
fun TestEntityModel.containsWithoutJvmInline(): Boolean = when (this) {
|
||||
is ClassModel -> methods.any { it.containsWithoutJvmInline() } || innerTestClasses.any { it.containsWithoutJvmInline() }
|
||||
is SimpleTestMethodModel -> file.isFile && file.readLines().any { Regex("^\\s*//\\s*WORKS_WHEN_VALUE_CLASS\\s*$").matches(it) }
|
||||
is SimpleTestMethodModel -> file.isFile && file.readLines().any { Regex("^\\s*//\\s*$WORKS_WHEN_VALUE_CLASS\\s*$").matches(it) }
|
||||
else -> false
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user