KT-45777: Address review comments - update tests

This commit is contained in:
Hung Nguyen
2021-09-06 10:07:00 +01:00
committed by nataliya.valtman
parent a48bf63630
commit 9b71bd5bb4
3 changed files with 155 additions and 74 deletions
@@ -26,6 +26,17 @@ abstract class IncrementalCompilationBaseIT : BaseGradleIT() {
) )
} }
protected fun doTest(
fileToModify: String,
modifyFileContents: (originalContents: String) -> String,
assertResults: CompiledProject.() -> Unit,
) {
doTest(
modifyProject = { projectDir.getFileByName(fileToModify).modify(modifyFileContents) },
assertResults = { assertResults() }
)
}
protected fun doTest( protected fun doTest(
project: Project = defaultProject(), project: Project = defaultProject(),
task: String = "build", task: String = "build",
@@ -55,11 +55,18 @@ open class IncrementalCompilationJvmMultiProjectIT : BaseIncrementalCompilationM
} }
} }
// checks that multi-project ic is disabled when there is a task that outputs to javaDestination dir // checks that multi-project ic is disabled when there is a task that outputs to javaDestination dir
// that is not JavaCompile or KotlinCompile // that is not JavaCompile or KotlinCompile
@Test @Test
fun testCompileLibWithGroovy() { open fun testCompileLibWithGroovy() {
testCompileLibWithGroovy_doTest {
assertCompiledKotlinFiles(
File(project.projectDir, "app").allKotlinFiles() + File(project.projectDir, "lib").getFileByName("A.kt")
)
}
}
protected fun testCompileLibWithGroovy_doTest(assertResults: CompiledProject.() -> Unit) {
val project = defaultProject() val project = defaultProject()
project.setupWorkingDir() project.setupWorkingDir()
val lib = File(project.projectDir, "lib") val lib = File(project.projectDir, "lib")
@@ -93,15 +100,10 @@ open class IncrementalCompilationJvmMultiProjectIT : BaseIncrementalCompilationM
project.changeMethodBodyInLib() project.changeMethodBodyInLib()
project.build("build") { project.build("build") {
assertSuccessful() assertSuccessful()
assertCompiledKotlinFiles(testCompileLibWithGroovy_expectedFiles(project)) assertResults()
} }
} }
/** Expected files to be recompiled for [testCompileLibWithGroovy], which may be overridden in subclasses. */
open fun testCompileLibWithGroovy_expectedFiles(project: Project): Iterable<File> {
return File(project.projectDir, "app").allKotlinFiles() + File(project.projectDir, "lib").getFileByName("A.kt")
}
/** Regression test for KT-43489. Make sure build history mapping is not initialized too early. */ /** Regression test for KT-43489. Make sure build history mapping is not initialized too early. */
@Test @Test
fun testBuildHistoryMappingLazilyComputedWithWorkers() { fun testBuildHistoryMappingLazilyComputedWithWorkers() {
@@ -151,20 +153,72 @@ class IncrementalCompilationClasspathSnapshotJvmMultiProjectIT : IncrementalComp
override fun defaultBuildOptions() = super.defaultBuildOptions().copy(useClasspathSnapshot = true) override fun defaultBuildOptions() = super.defaultBuildOptions().copy(useClasspathSnapshot = true)
override fun testAddDependencyInLib_expectedFiles(project: Project): Iterable<File> { @Test
// With classpath snapshot, no files are recompiled override fun testNonAbiChangeInLib_changeMethodBody() {
return emptyList() doTest(
modifyProject = changeMethodBodyInLib,
assertResults = {
assertTasksExecuted(":lib:$compileKotlinTaskName")
assertTasksExecuted(":app:$compileKotlinTaskName") // TODO: App compilation should have 'compile avoidance'
assertCompiledKotlinFiles(File(project.projectDir, "lib").getFilesByNames("A.kt"))
}
)
} }
override fun testAbiChangeInLib_afterLibClean_expectedFiles(project: Project): Iterable<File> { @Test
// With classpath snapshot, app compilation is incremental override fun testAddDependencyInLib() {
return File(project.projectDir, "app").getFilesByNames("AA.kt", "AAA.kt", "BB.kt", "fooUseA.kt") + doTest(
File(project.projectDir, "lib").allKotlinFiles() modifyProject = { testAddDependencyInLib_modifyProject() },
assertResults = {
assertTasksExecuted(":lib:$compileKotlinTaskName")
assertTasksUpToDate(":app:$compileKotlinTaskName")
assertCompiledKotlinFiles(emptyList()) // Lib compilation is incremental (no files are recompiled)
}
)
} }
override fun testCompileLibWithGroovy_expectedFiles(project: Project): Iterable<File> { @Test
// With classpath snapshot, no files in app are recompiled override fun testAbiChangeInLib_afterLibClean() {
return listOf(File(project.projectDir, "lib").getFileByName("A.kt")) doTest(
modifyProject = {
build(":lib:clean") { assertSuccessful() }
changeMethodSignatureInLib()
},
assertResults = {
assertCompiledKotlinFiles(
// App compilation is incremental
File(project.projectDir, "app").getFilesByNames("AA.kt", "AAA.kt", "BB.kt", "fooUseA.kt") +
File(project.projectDir, "lib").allKotlinFiles()
)
}
)
}
@Test
override fun testCompileLibWithGroovy() {
testCompileLibWithGroovy_doTest {
assertTasksExecuted(":lib:$compileKotlinTaskName")
assertTasksExecuted(":app:$compileKotlinTaskName") // TODO: App compilation should have 'compile avoidance'
assertCompiledKotlinFiles(listOf(File(project.projectDir, "lib").getFileByName("A.kt")))
}
}
@Test
override fun testAbiChangeInLib_afterLibClean_withAbiSnapshot() {
doTest(
options = defaultBuildOptions().copy(abiSnapshot = true),
modifyProject = {
build(":lib:clean") { assertSuccessful() }
changeMethodSignatureInLib()
},
assertResults = {
assertCompiledKotlinFiles(
// App compilation is incremental
File(project.projectDir, "app").getFilesByNames("AA.kt", "AAA.kt", "BB.kt", "fooUseA.kt") +
File(project.projectDir, "lib").allKotlinFiles()
)
}
)
} }
} }
@@ -213,56 +267,53 @@ abstract class BaseIncrementalCompilationMultiProjectIT : IncrementalCompilation
} }
@Test @Test
fun testNonAbiChangeInLib_changeMethodBody() { open fun testNonAbiChangeInLib_changeMethodBody() {
doTest( doTest(
modifyProject = changeMethodBodyInLib, modifyProject = changeMethodBodyInLib,
expectedCompiledFileNames = listOf("A.kt") // In lib
)
}
@Test
fun testAddDependencyInLib() {
doTest(
modifyProject = {
File(projectDir, "lib/build.gradle").modify {
"""
$it
dependencies {
$additionalLibDependencies
}
""".trimIndent()
}
},
assertResults = { assertResults = {
assertCompiledKotlinFiles(testAddDependencyInLib_expectedFiles(project)) assertCompiledKotlinFiles(File(project.projectDir, "lib").getFilesByNames("A.kt"))
} }
) )
} }
/** Expected files to be recompiled for [testAddDependencyInLib], which may be overridden in subclasses. */ @Test
open fun testAddDependencyInLib_expectedFiles(project: Project): Iterable<File> { open fun testAddDependencyInLib() {
return File(project.projectDir, "lib").allKotlinFiles() doTest(
modifyProject = { testAddDependencyInLib_modifyProject() },
assertResults = {
assertTasksExecuted(":lib:$compileKotlinTaskName")
assertTasksUpToDate(":app:$compileKotlinTaskName")
assertCompiledKotlinFiles(File(project.projectDir, "lib").allKotlinFiles())
}
)
}
protected fun Project.testAddDependencyInLib_modifyProject() {
File(projectDir, "lib/build.gradle").modify {
"""
$it
dependencies {
$additionalLibDependencies
}
""".trimIndent()
}
} }
@Test @Test
fun testAbiChangeInLib_afterLibClean() { // To see if app compilation can be incremental after non-incremental lib compilation open fun testAbiChangeInLib_afterLibClean() { // To see if app compilation can be incremental after non-incremental lib compilation
doTest( doTest(
modifyProject = { modifyProject = {
build(":lib:clean") { assertSuccessful() } build(":lib:clean") { assertSuccessful() }
changeMethodSignatureInLib() changeMethodSignatureInLib()
}, },
assertResults = { assertResults = {
assertCompiledKotlinFiles(testAbiChangeInLib_afterLibClean_expectedFiles(project)) // App compilation is non-incremental
assertCompiledKotlinFiles(project.projectDir.allKotlinFiles())
} }
) )
} }
/** Expected files for [testAbiChangeInLib_afterLibClean], which may be overridden in subclasses. */
open fun testAbiChangeInLib_afterLibClean_expectedFiles(project: Project): Iterable<File> {
return project.projectDir.allKotlinFiles()
}
@Test @Test
fun testMoveFunctionFromLibToApp() { fun testMoveFunctionFromLibToApp() {
doTest( doTest(
@@ -410,7 +461,7 @@ abstract class BaseIncrementalCompilationMultiProjectIT : IncrementalCompilation
} }
@Test @Test
fun testAbiChangeInLib_afterLibClean_withAbiSnapshot() { open fun testAbiChangeInLib_afterLibClean_withAbiSnapshot() {
doTest( doTest(
options = defaultBuildOptions().copy(abiSnapshot = true), options = defaultBuildOptions().copy(abiSnapshot = true),
modifyProject = { modifyProject = {
@@ -419,7 +470,7 @@ abstract class BaseIncrementalCompilationMultiProjectIT : IncrementalCompilation
}, },
assertResults = { assertResults = {
// TODO: With ABI snapshot, app compilation should be incremental, currently it is not. // TODO: With ABI snapshot, app compilation should be incremental, currently it is not.
assertCompiledKotlinFiles(testAbiChangeInLib_afterLibClean_expectedFiles(project)) assertCompiledKotlinFiles(project.projectDir.allKotlinFiles())
} }
) )
} }
@@ -5,17 +5,25 @@
package org.jetbrains.kotlin.gradle package org.jetbrains.kotlin.gradle
import org.jetbrains.kotlin.gradle.util.getFilesByNames
import org.junit.Test import org.junit.Test
import java.io.File
open class IncrementalJavaChangeDefaultIT : IncrementalCompilationJavaChangesBase(usePreciseJavaTracking = null) { open class IncrementalJavaChangeDefaultIT : IncrementalCompilationJavaChangesBase(usePreciseJavaTracking = null) {
@Test @Test
override fun testAbiChangeInLib_changeMethodSignature_tracked() { override fun testAbiChangeInLib_changeMethodSignature_tracked() {
doTest(trackedJavaClass, changeSignature, expectedCompiledFileNames = listOf("TrackedJavaClassChild.kt", "useTrackedJavaClass.kt")) doTest(
trackedJavaClassInLib, changeMethodSignature,
expectedCompiledFileNames = listOf("TrackedJavaClassChild.kt", "useTrackedJavaClass.kt") // In app
)
} }
@Test @Test
override fun testNonAbiChangeInLib_changeMethodBody_tracked() { override fun testNonAbiChangeInLib_changeMethodBody_tracked() {
doTest(trackedJavaClass, changeBody, expectedCompiledFileNames = listOf()) doTest(
trackedJavaClassInLib, changeMethodBody,
expectedCompiledFileNames = emptyList()
)
} }
} }
@@ -25,19 +33,26 @@ class IncrementalJavaChangeClasspathSnapshotIT : IncrementalJavaChangeDefaultIT(
@Test @Test
override fun testAbiChangeInLib_changeMethodSignature() { override fun testAbiChangeInLib_changeMethodSignature() {
// With classpath snapshot, fewer Kotlin files are recompiled
doTest( doTest(
javaClass, changeSignature, javaClassInLib, changeMethodSignature,
expectedCompiledFileNames = listOf("JavaClassChild.kt", "useJavaClass.kt") assertResults = {
// Fewer Kotlin files are recompiled
assertCompiledKotlinFiles(
File(project.projectDir, "app").getFilesByNames("JavaClassChild.kt", "useJavaClass.kt")
)
}
) )
} }
@Test @Test
override fun testNonAbiChangeInLib_changeMethodBody() { override fun testNonAbiChangeInLib_changeMethodBody() {
// With classpath snapshot, no Kotlin files are recompiled
doTest( doTest(
javaClass, changeBody, javaClassInLib, changeMethodBody,
expectedCompiledFileNames = emptyList() assertResults = {
assertTasksExecuted(":lib:compileKotlin")
assertTasksExecuted(":app:compileKotlin") // TODO: App compilation should have 'compile avoidance'
assertCompiledKotlinFiles(emptyList())
}
) )
} }
} }
@@ -45,12 +60,16 @@ class IncrementalJavaChangeClasspathSnapshotIT : IncrementalJavaChangeDefaultIT(
class IncrementalJavaChangePreciseIT : IncrementalCompilationJavaChangesBase(usePreciseJavaTracking = true) { class IncrementalJavaChangePreciseIT : IncrementalCompilationJavaChangesBase(usePreciseJavaTracking = true) {
@Test @Test
override fun testAbiChangeInLib_changeMethodSignature_tracked() { override fun testAbiChangeInLib_changeMethodSignature_tracked() {
doTest(trackedJavaClass, changeSignature, expectedCompiledFileNames = listOf("TrackedJavaClassChild.kt", "useTrackedJavaClass.kt")) doTest(
trackedJavaClassInLib,
changeMethodSignature,
expectedCompiledFileNames = listOf("TrackedJavaClassChild.kt", "useTrackedJavaClass.kt") // In app
)
} }
@Test @Test
override fun testNonAbiChangeInLib_changeMethodBody_tracked() { override fun testNonAbiChangeInLib_changeMethodBody_tracked() {
doTest(trackedJavaClass, changeBody, expectedCompiledFileNames = listOf()) doTest(trackedJavaClassInLib, changeMethodBody, expectedCompiledFileNames = emptyList())
} }
} }
@@ -58,10 +77,10 @@ open class IncrementalJavaChangeDisablePreciseIT : IncrementalCompilationJavaCha
@Test @Test
override fun testAbiChangeInLib_changeMethodSignature_tracked() { override fun testAbiChangeInLib_changeMethodSignature_tracked() {
doTest( doTest(
trackedJavaClass, changeSignature, trackedJavaClassInLib, changeMethodSignature,
expectedCompiledFileNames = listOf( expectedCompiledFileNames = listOf(
"TrackedJavaClassChild.kt", "useTrackedJavaClass.kt", "useTrackedJavaClassFooMethodUsage.kt", "TrackedJavaClassChild.kt", "useTrackedJavaClass.kt", "useTrackedJavaClassFooMethodUsage.kt", // In app
"useTrackedJavaClassSameModule.kt" "useTrackedJavaClassSameModule.kt" // In lib
) )
) )
} }
@@ -69,10 +88,10 @@ open class IncrementalJavaChangeDisablePreciseIT : IncrementalCompilationJavaCha
@Test @Test
override fun testNonAbiChangeInLib_changeMethodBody_tracked() { override fun testNonAbiChangeInLib_changeMethodBody_tracked() {
doTest( doTest(
trackedJavaClass, changeBody, trackedJavaClassInLib, changeMethodBody,
expectedCompiledFileNames = listOf( expectedCompiledFileNames = listOf(
"TrackedJavaClassChild.kt", "useTrackedJavaClass.kt", "useTrackedJavaClassFooMethodUsage.kt", "TrackedJavaClassChild.kt", "useTrackedJavaClass.kt", "useTrackedJavaClassFooMethodUsage.kt", // In app
"useTrackedJavaClassSameModule.kt" "useTrackedJavaClassSameModule.kt" // In lib
) )
) )
} }
@@ -88,24 +107,24 @@ abstract class IncrementalCompilationJavaChangesBase(val usePreciseJavaTracking:
override fun defaultProject() = Project("incrementalMultiproject") override fun defaultProject() = Project("incrementalMultiproject")
override fun defaultBuildOptions() = super.defaultBuildOptions().copy(usePreciseJavaTracking = usePreciseJavaTracking) override fun defaultBuildOptions() = super.defaultBuildOptions().copy(usePreciseJavaTracking = usePreciseJavaTracking)
protected val trackedJavaClass = "TrackedJavaClass.java" protected val javaClassInLib = "JavaClass.java"
protected val javaClass = "JavaClass.java" protected val trackedJavaClassInLib = "TrackedJavaClass.java"
protected val changeBody: (String) -> String = { it.replace("Hello, World!", "Hello, World!!!!") } protected val changeMethodSignature: (String) -> String = { it.replace("String getString", "Object getString") }
protected val changeSignature: (String) -> String = { it.replace("String getString", "Object getString") } protected val changeMethodBody: (String) -> String = { it.replace("Hello, World!", "Hello, World!!!!") }
@Test @Test
open fun testAbiChangeInLib_changeMethodSignature() { open fun testAbiChangeInLib_changeMethodSignature() {
doTest( doTest(
javaClass, changeSignature, javaClassInLib, changeMethodSignature,
expectedCompiledFileNames = listOf("JavaClassChild.kt", "useJavaClass.kt", "useJavaClassFooMethodUsage.kt") expectedCompiledFileNames = listOf("JavaClassChild.kt", "useJavaClass.kt", "useJavaClassFooMethodUsage.kt") // In app
) )
} }
@Test @Test
open fun testNonAbiChangeInLib_changeMethodBody() { open fun testNonAbiChangeInLib_changeMethodBody() {
doTest( doTest(
javaClass, changeBody, javaClassInLib, changeMethodBody,
expectedCompiledFileNames = listOf("JavaClassChild.kt", "useJavaClass.kt", "useJavaClassFooMethodUsage.kt") expectedCompiledFileNames = listOf("JavaClassChild.kt", "useJavaClass.kt", "useJavaClassFooMethodUsage.kt") // In app
) )
} }