[Test gen] Consolidate file reads for checking directives

This commit is contained in:
Kirill Rakhman
2024-02-26 18:09:49 +01:00
committed by Space Team
parent 3c23319f70
commit 5bbec23123
3 changed files with 61 additions and 11 deletions
@@ -23,6 +23,16 @@ open class SimpleTestMethodModel(
) : MethodModel {
object Kind : MethodModel.Kind()
val directives: Map<String, List<String>> by lazy(LazyThreadSafetyMode.NONE) {
InTextDirectivesUtils.findLinesByPrefixRemoved(
InTextDirectivesUtils.textWithDirectives(file),
*InTextDirectivesUtils.IGNORE_BACKEND_DIRECTIVE_PREFIXES,
InTextDirectivesUtils.TARGET_BACKEND_DIRECTIVE_PREFIX,
InTextDirectivesUtils.DORT_TARGET_EXACT_BACKEND_DIRECTIVE_PREFIX,
"// WORKS_WHEN_VALUE_CLASS"
)
}
override val kind: MethodModel.Kind
get() = Kind
@@ -33,7 +43,7 @@ open class SimpleTestMethodModel(
}
override fun shouldBeGenerated(): Boolean {
return InTextDirectivesUtils.isCompatibleTarget(targetBackend, file)
return InTextDirectivesUtils.isCompatibleTarget(targetBackend, directives)
}
override val name: String
@@ -53,7 +63,7 @@ open class SimpleTestMethodModel(
val relativePath = FileUtil.getRelativePath(rootDir, file.parentFile)
relativePath + "-" + extractedName.replaceFirstChar(Char::uppercaseChar)
}
val ignored = skipIgnored && InTextDirectivesUtils.isIgnoredTarget(targetBackend, file)
val ignored = skipIgnored && InTextDirectivesUtils.isIgnoredTarget(targetBackend, directives, false)
return (if (ignored) "ignore" else "test") + escapeForJavaIdentifier(unescapedName).replaceFirstChar(Char::uppercaseChar)
}
@@ -10,13 +10,12 @@ 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 && "WORKS_WHEN_VALUE_CLASS" in directives
else -> false
}