IDE perf tests for K/N: Produce duplicated *.kt files on demand
This commit is contained in:
+40
@@ -61,6 +61,7 @@ class PerformanceNativeProjectsTest : AbstractPerformanceProjectsTest() {
|
||||
|
||||
private enum class TestProject(
|
||||
val templateName: String,
|
||||
val duplicatesAmount: Int = 2,
|
||||
val filesToHighlight: List<String>
|
||||
) {
|
||||
HELLO_WORLD(
|
||||
@@ -85,6 +86,7 @@ class PerformanceNativeProjectsTest : AbstractPerformanceProjectsTest() {
|
||||
|
||||
init {
|
||||
assertTrue(filesToHighlight.isNotEmpty())
|
||||
assertTrue(duplicatesAmount in 0..100)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -230,6 +232,44 @@ class PerformanceNativeProjectsTest : AbstractPerformanceProjectsTest() {
|
||||
fail("Some files have not been merged in project root directory: $projectRoot: ${unmergedFiles.joinToString()}")
|
||||
}
|
||||
|
||||
// produce N duplicates of *.kt files inside the project root
|
||||
if (testProject.duplicatesAmount > 0) {
|
||||
val originalKtFiles = projectRoot.walkTopDown()
|
||||
.filter { it.isFile && it.name.endsWith(".kt") }
|
||||
.toList()
|
||||
|
||||
for (originalKtFile in originalKtFiles) {
|
||||
val originalKtFileContents = originalKtFile.readLines()
|
||||
|
||||
assertTrue(
|
||||
"$originalKtFile must have @file:Suppress(\"PackageDirectoryMismatch\") annotation",
|
||||
originalKtFileContents.any { it.startsWith("@file:Suppress") && it.contains("\"PackageDirectoryMismatch\"") }
|
||||
)
|
||||
|
||||
val packageLineIndex = originalKtFileContents.indexOfFirst { it.startsWith("package perfTestPackage1") }
|
||||
assertTrue(
|
||||
"$originalKtFile must have package declaration: package perfTestPackage1",
|
||||
packageLineIndex != -1
|
||||
)
|
||||
|
||||
for (i in 1..testProject.duplicatesAmount) {
|
||||
val n = i + 1
|
||||
val duplicateKtFile = originalKtFile.resolveSibling("${originalKtFile.nameWithoutExtension}$n.kt")
|
||||
duplicateKtFile.writeText(
|
||||
buildString {
|
||||
originalKtFileContents.forEachIndexed { index, line ->
|
||||
if (index == packageLineIndex) {
|
||||
appendln(line.replace("perfTestPackage1", "perfTestPackage$n"))
|
||||
} else {
|
||||
appendln(line)
|
||||
}
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// check all necessary files are there
|
||||
listOf("build.gradle.kts", "settings.gradle.kts", "gradle.properties")
|
||||
.filter { !projectRoot.resolve(it).exists() }
|
||||
|
||||
Reference in New Issue
Block a user