IC tests: add infrastructure for K1/K2 lookups comparison
Adapt lookup tests to allow running K1 and K2 on the same testdata and compare the lookups recorded.
This commit is contained in:
committed by
Space Team
parent
684d0b8690
commit
1989e8f094
@@ -24,7 +24,7 @@ data class BuildLogFinder(
|
||||
private val isJsEnabled: Boolean = false,
|
||||
private val isScopeExpansionEnabled: Boolean = false,
|
||||
private val isKlibEnabled: Boolean = false,
|
||||
private val isFirEnabled: Boolean = false,
|
||||
private val isFirEnabled: Boolean = true,
|
||||
private val isJpsBuild: Boolean = false,
|
||||
) {
|
||||
companion object {
|
||||
|
||||
+63
-23
@@ -18,7 +18,6 @@ package org.jetbrains.kotlin.incremental.testingUtils
|
||||
|
||||
import com.intellij.openapi.util.io.FileUtil
|
||||
import java.io.File
|
||||
import java.util.*
|
||||
import kotlin.math.max
|
||||
|
||||
private val COMMANDS = listOf("new", "touch", "delete")
|
||||
@@ -30,28 +29,59 @@ enum class TouchPolicy {
|
||||
CHECKSUM
|
||||
}
|
||||
|
||||
fun copyTestSources(testDataDir: File, sourceDestinationDir: File, filePrefix: String): Map<File, File> {
|
||||
val mapping = hashMapOf<File, File>()
|
||||
FileUtil.copyDir(testDataDir, sourceDestinationDir) {
|
||||
it.isDirectory || it.name.startsWith(filePrefix) && (it.name.endsWith(".kt") || it.name.endsWith(".java"))
|
||||
/**
|
||||
* Optional suffix (first filename extension) that could be inserted before first "regular" extension
|
||||
*/
|
||||
enum class OptionalVariantSuffix {
|
||||
None,
|
||||
K1,
|
||||
K2;
|
||||
|
||||
companion object {
|
||||
/**
|
||||
* A regex used to recognize a variant suffix in the filename.
|
||||
* Note: Should match all possible suffixes, but "None", and should be compatible with comparison logic in `genVariantMatchingName`
|
||||
*/
|
||||
val anySuffixRegex = Regex(".(K[12]).")
|
||||
}
|
||||
}
|
||||
|
||||
for (file in sourceDestinationDir.walk()) {
|
||||
if (!file.isFile) continue
|
||||
fun String.genVariantMatchingName(expectedOptionalVariant: OptionalVariantSuffix): String? {
|
||||
if (expectedOptionalVariant == OptionalVariantSuffix.None) return this
|
||||
val variantMatch = OptionalVariantSuffix.anySuffixRegex.find(this) ?: return this
|
||||
if (variantMatch.groups[1]?.value != expectedOptionalVariant.name) return null
|
||||
return removeRange(variantMatch.range.first, variantMatch.range.last)
|
||||
}
|
||||
|
||||
val renamedFile =
|
||||
if (filePrefix.isEmpty()) {
|
||||
file
|
||||
}
|
||||
else {
|
||||
File(sourceDestinationDir, file.name.removePrefix(filePrefix)).apply {
|
||||
file.renameTo(this)
|
||||
fun copyTestSources(
|
||||
testDataDir: File,
|
||||
sourceDestinationDir: File,
|
||||
filePrefix: String,
|
||||
optionalVariantSuffix: OptionalVariantSuffix = OptionalVariantSuffix.None,
|
||||
): Map<File, File> {
|
||||
val mapping = hashMapOf<File, File>()
|
||||
|
||||
fun copyDir(fromDir: File, toDir: File) {
|
||||
FileUtil.ensureExists(toDir)
|
||||
for (file in fromDir.listFiles().orEmpty()) {
|
||||
if (file.isDirectory) {
|
||||
copyDir(file, File(toDir, file.name))
|
||||
} else if (file.name.endsWith(".kt") || file.name.endsWith(".java")) {
|
||||
val nameWithoutVariant = file.name.genVariantMatchingName(optionalVariantSuffix) ?: continue // prefixed but with different variant
|
||||
if (nameWithoutVariant.startsWith(filePrefix)) {
|
||||
val targetFile = File(toDir, nameWithoutVariant.substring(filePrefix.length))
|
||||
if (nameWithoutVariant != file.name /* variant-prefixed file replaces the one without a variant prefix */ ||
|
||||
!mapping.containsKey(targetFile)
|
||||
) {
|
||||
FileUtil.copy(file, targetFile)
|
||||
mapping[targetFile] = file
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
mapping[renamedFile] = File(testDataDir, file.name)
|
||||
}
|
||||
}
|
||||
|
||||
copyDir(testDataDir, sourceDestinationDir)
|
||||
return mapping
|
||||
}
|
||||
|
||||
@@ -59,7 +89,8 @@ fun getModificationsToPerform(
|
||||
testDataDir: File,
|
||||
moduleNames: Collection<String>?,
|
||||
allowNoFilesWithSuffixInTestData: Boolean,
|
||||
touchPolicy: TouchPolicy
|
||||
touchPolicy: TouchPolicy,
|
||||
optionalVariantSuffix: OptionalVariantSuffix = OptionalVariantSuffix.None,
|
||||
): List<List<Modification>> {
|
||||
|
||||
fun getModificationsForIteration(newSuffix: String, touchSuffix: String, deleteSuffix: String): List<Modification> {
|
||||
@@ -92,21 +123,30 @@ fun getModificationsToPerform(
|
||||
deleteSuffix to { path, _ -> DeleteFile(path) }
|
||||
)
|
||||
|
||||
val modifications = ArrayList<Modification>()
|
||||
val modifications = LinkedHashMap<String, Modification>()
|
||||
|
||||
for (file in testDataDir.walkTopDown()) {
|
||||
if (!file.isFile) continue
|
||||
|
||||
val relativeFilePath = file.toRelativeString(testDataDir)
|
||||
|
||||
val (suffix, createModification) = rules.entries.firstOrNull { file.path.endsWith(it.key) } ?: continue
|
||||
|
||||
val (moduleName, fileName) = splitToModuleNameAndFileName(relativeFilePath)
|
||||
// NOTE: the code do not allow to combine module prefixes with directory structure
|
||||
val relativeFilePath = file.toRelativeString(testDataDir)
|
||||
val relativeFilePathWithoutVariant =
|
||||
relativeFilePath.genVariantMatchingName(optionalVariantSuffix) ?: continue
|
||||
|
||||
val (moduleName, fileName) = splitToModuleNameAndFileName(relativeFilePathWithoutVariant)
|
||||
val srcDir = moduleName?.let { "$it/src" } ?: "src"
|
||||
modifications.add(createModification(srcDir + "/" + fileName.removeSuffix(suffix), file))
|
||||
val targetPath = srcDir + "/" + fileName.removeSuffix(suffix)
|
||||
|
||||
if (relativeFilePathWithoutVariant != relativeFilePath /* variant-prefixed file replaces the one without a variant prefix */ ||
|
||||
!modifications.containsKey(targetPath)
|
||||
) {
|
||||
modifications[targetPath] = createModification(targetPath, file)
|
||||
}
|
||||
}
|
||||
|
||||
return modifications
|
||||
return modifications.values.toList()
|
||||
}
|
||||
|
||||
val haveFilesWithoutNumbers = testDataDir.walkTopDown().any { it.name.matches(".+\\.($COMMANDS_AS_REGEX_PART)$".toRegex()) }
|
||||
|
||||
Reference in New Issue
Block a user