[BTA tests] Add changeFile overload for versioned source modification
^KT-61860 In Progress
This commit is contained in:
committed by
Space Team
parent
68cf1bdc57
commit
ea3d5371ef
+5
-5
@@ -13,10 +13,7 @@ import org.jetbrains.kotlin.buildtools.api.tests.compilation.model.Module
|
||||
import org.jetbrains.kotlin.tooling.core.KotlinToolingVersion
|
||||
import java.io.File
|
||||
import java.nio.file.Path
|
||||
import kotlin.io.path.absolutePathString
|
||||
import kotlin.io.path.createParentDirectories
|
||||
import kotlin.io.path.listDirectoryEntries
|
||||
import kotlin.io.path.toPath
|
||||
import kotlin.io.path.*
|
||||
|
||||
class JvmModule(
|
||||
project: Project,
|
||||
@@ -51,11 +48,14 @@ class JvmModule(
|
||||
"-cp", dependencyFiles.joinToString(File.pathSeparator),
|
||||
"-module-name", moduleName,
|
||||
)
|
||||
val allowedExtensions = compilationConfig.kotlinScriptFilenameExtensions + setOf("kt", "kts")
|
||||
return BaseTest.compilationService.compileJvm(
|
||||
project.projectId,
|
||||
strategyConfig,
|
||||
compilationConfig,
|
||||
sourcesDirectory.listDirectoryEntries().map { it.toFile() },
|
||||
sourcesDirectory.listDirectoryEntries()
|
||||
.filter { path -> path.pathString.run { allowedExtensions.any { endsWith(".$it") } } }
|
||||
.map { it.toFile() },
|
||||
defaultCompilationArguments + additionalCompilationArguments,
|
||||
)
|
||||
}
|
||||
|
||||
+12
@@ -12,12 +12,24 @@ import org.jetbrains.kotlin.buildtools.api.tests.compilation.model.Module
|
||||
interface ScenarioModule {
|
||||
/**
|
||||
* Performs registered existing file modification.
|
||||
*
|
||||
* Prefer the overload with versioned file modification if it's possible
|
||||
*/
|
||||
fun changeFile(
|
||||
fileName: String,
|
||||
transform: (String) -> String,
|
||||
)
|
||||
|
||||
/**
|
||||
* Performs registered existing file modification.
|
||||
*
|
||||
* Check the example `ExampleIncrementalScenarioTest.testScenario4` out
|
||||
*/
|
||||
fun changeFile(
|
||||
fileName: String,
|
||||
version: UInt,
|
||||
)
|
||||
|
||||
/**
|
||||
* Performs registered file deletion.
|
||||
*/
|
||||
|
||||
+11
-6
@@ -28,11 +28,12 @@ internal class ScenarioModuleImpl(
|
||||
transform: (String) -> String,
|
||||
) {
|
||||
val file = module.sourcesDirectory.resolve(fileName)
|
||||
file.writeText(transform(file.readText()))
|
||||
sourcesChanges = SourcesChanges.Known(
|
||||
modifiedFiles = sourcesChanges.modifiedFiles + file.toFile(),
|
||||
removedFiles = sourcesChanges.removedFiles,
|
||||
)
|
||||
writeFile(fileName, transform(file.readText()))
|
||||
}
|
||||
|
||||
override fun changeFile(fileName: String, version: UInt) {
|
||||
val file = module.sourcesDirectory.resolve("$fileName.$version")
|
||||
writeFile(fileName, file.readText())
|
||||
}
|
||||
|
||||
override fun deleteFile(fileName: String) {
|
||||
@@ -45,8 +46,12 @@ internal class ScenarioModuleImpl(
|
||||
}
|
||||
|
||||
override fun createFile(fileName: String, content: String) {
|
||||
writeFile(fileName, content)
|
||||
}
|
||||
|
||||
private fun writeFile(fileName: String, newContent: String) {
|
||||
val file = module.sourcesDirectory.resolve(fileName)
|
||||
file.writeText(content)
|
||||
file.writeText(newContent)
|
||||
sourcesChanges = SourcesChanges.Known(
|
||||
modifiedFiles = sourcesChanges.modifiedFiles + file.toFile(),
|
||||
removedFiles = sourcesChanges.removedFiles,
|
||||
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
/*
|
||||
* Copyright 2010-2023 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
class Bar {
|
||||
fun bar(bar: Int) = foo()
|
||||
}
|
||||
+16
@@ -107,4 +107,20 @@ class ExampleIncrementalScenarioTest : BaseCompilationTest() {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@DefaultStrategyAgnosticCompilationTest
|
||||
@DisplayName("Sample scenario DSL IC test with versioned source file modification")
|
||||
@TestMetadata("jvm-module-1")
|
||||
fun testScenario4(strategyConfig: CompilerExecutionStrategyConfiguration) {
|
||||
scenario(strategyConfig) {
|
||||
val module1 = module("jvm-module-1")
|
||||
|
||||
module1.changeFile("bar.kt", 1U)
|
||||
|
||||
module1.compile {
|
||||
assertCompiledSources("bar.kt")
|
||||
assertNoOutputSetChanges()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user