Migrate DeterministicBuildIT tests into new test dsl.
^KT-45745 In Progress
This commit is contained in:
+81
-72
@@ -5,89 +5,98 @@
|
|||||||
|
|
||||||
package org.jetbrains.kotlin.gradle
|
package org.jetbrains.kotlin.gradle
|
||||||
|
|
||||||
|
import org.gradle.util.GradleVersion
|
||||||
|
import org.jetbrains.kotlin.gradle.testbase.*
|
||||||
import org.jetbrains.kotlin.gradle.util.allJavaFiles
|
import org.jetbrains.kotlin.gradle.util.allJavaFiles
|
||||||
import org.junit.Test
|
import org.junit.jupiter.api.DisplayName
|
||||||
import java.io.File
|
import java.io.File
|
||||||
|
import kotlin.io.path.ExperimentalPathApi
|
||||||
|
import kotlin.io.path.writeText
|
||||||
import kotlin.test.assertEquals
|
import kotlin.test.assertEquals
|
||||||
|
|
||||||
/** Tests that the outputs of a build are deterministic. */
|
@DisplayName("Tests that the outputs of a build are deterministic")
|
||||||
class DeterministicBuildIT : BaseGradleIT() {
|
@SimpleGradlePluginTests
|
||||||
|
@OptIn(ExperimentalPathApi::class)
|
||||||
|
class DeterministicBuildIT : KGPBaseTest() {
|
||||||
|
|
||||||
@Test
|
@DisplayName("Kapt generate stubs task - KT-40882")
|
||||||
fun `test KaptGenerateStubsTask - KT-40882`() = with(
|
@GradleTest
|
||||||
Project("simple", directoryPrefix = "kapt2")
|
fun testKaptGenerateStubsTask(gradleVersion: GradleVersion) {
|
||||||
) {
|
project("kapt2/simple", gradleVersion) {
|
||||||
setupWorkingDir()
|
javaSourcesDir()
|
||||||
projectDir
|
.resolve("Foo.kt")
|
||||||
.resolve("src/main/java/Foo.kt")
|
.writeText(
|
||||||
.writeText(
|
"""
|
||||||
"""
|
class Foo : Bar {
|
||||||
class Foo : Bar {
|
// The fields and methods are ordered such that any sorting by KGP will be detected.
|
||||||
// The fields and methods are ordered such that any sorting by KGP will be detected.
|
val fooField1 = 1
|
||||||
val fooField1 = 1
|
val fooField3 = 3
|
||||||
val fooField3 = 3
|
val fooField2 = 2
|
||||||
val fooField2 = 2
|
fun fooMethod1() {}
|
||||||
fun fooMethod1() {}
|
fun fooMethod3() {}
|
||||||
fun fooMethod3() {}
|
fun fooMethod2() {}
|
||||||
fun fooMethod2() {}
|
}
|
||||||
}
|
""".trimIndent()
|
||||||
""".trimIndent()
|
)
|
||||||
)
|
javaSourcesDir()
|
||||||
projectDir
|
.resolve("Bar.kt")
|
||||||
.resolve("src/main/java/Bar.kt")
|
.writeText(
|
||||||
.writeText(
|
"""
|
||||||
"""
|
interface Bar {
|
||||||
interface Bar {
|
val barField1 = 1
|
||||||
val barField1 = 1
|
val barField3 = 3
|
||||||
val barField3 = 3
|
val barField2 = 2
|
||||||
val barField2 = 2
|
fun barMethod1() {}
|
||||||
fun barMethod1() {}
|
fun barMethod3() {}
|
||||||
fun barMethod3() {}
|
fun barMethod2() {}
|
||||||
fun barMethod2() {}
|
}
|
||||||
}
|
""".trimIndent()
|
||||||
""".trimIndent()
|
)
|
||||||
)
|
|
||||||
|
|
||||||
val buildAndSnapshotStubFiles: () -> Map<File, String> = {
|
fun TestProject.buildAndSnapshotStubFiles(): Map<File, String> {
|
||||||
lateinit var stubFiles: Map<File, String>
|
lateinit var stubFiles: Map<File, String>
|
||||||
build(":kaptGenerateStubsKotlin") {
|
build(":kaptGenerateStubsKotlin") {
|
||||||
assertSuccessful()
|
assertTasksExecuted(":kaptGenerateStubsKotlin")
|
||||||
assertTasksExecuted(":kaptGenerateStubsKotlin")
|
stubFiles = projectPath
|
||||||
stubFiles = fileInWorkingDir("build/tmp/kapt3/stubs").allJavaFiles().map {
|
.resolve("build/tmp/kapt3/stubs")
|
||||||
it to it.readText()
|
.toFile()
|
||||||
}.toMap()
|
.allJavaFiles()
|
||||||
|
.associateWith {
|
||||||
|
it.readText()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return stubFiles
|
||||||
}
|
}
|
||||||
stubFiles
|
|
||||||
}
|
|
||||||
|
|
||||||
// Run the first build
|
// Run the first build
|
||||||
val stubFilesAfterFirstBuild = buildAndSnapshotStubFiles()
|
val stubFilesAfterFirstBuild = buildAndSnapshotStubFiles()
|
||||||
|
|
||||||
// Make a change
|
// Make a change
|
||||||
projectDir.resolve("src/main/java/Foo.kt").also {
|
javaSourcesDir()
|
||||||
it.writeText(
|
.resolve("Foo.kt")
|
||||||
"""
|
.writeText(
|
||||||
class Foo : Bar {
|
"""
|
||||||
val fooField1 = 1
|
class Foo : Bar {
|
||||||
val fooField3 = 3
|
val fooField1 = 1
|
||||||
val fooField2 = 2
|
val fooField3 = 3
|
||||||
fun fooMethod1() { println("Method body changed!") }
|
val fooField2 = 2
|
||||||
fun fooMethod3() {}
|
fun fooMethod1() { println("Method body changed!") }
|
||||||
fun fooMethod2() {}
|
fun fooMethod3() {}
|
||||||
}
|
fun fooMethod2() {}
|
||||||
""".trimIndent()
|
}
|
||||||
)
|
""".trimIndent()
|
||||||
}
|
)
|
||||||
|
|
||||||
// Run the second build
|
// Run the second build
|
||||||
val stubFilesAfterSecondBuild = buildAndSnapshotStubFiles()
|
val stubFilesAfterSecondBuild = buildAndSnapshotStubFiles()
|
||||||
|
|
||||||
// Check that the build outputs are deterministic
|
// Check that the build outputs are deterministic
|
||||||
assertEquals(stubFilesAfterFirstBuild.size, stubFilesAfterSecondBuild.size)
|
assertEquals(stubFilesAfterFirstBuild.size, stubFilesAfterSecondBuild.size)
|
||||||
for (file in stubFilesAfterFirstBuild.keys) {
|
for (file in stubFilesAfterFirstBuild.keys) {
|
||||||
val fileContentsAfterFirstBuild = stubFilesAfterFirstBuild[file]
|
val fileContentsAfterFirstBuild = stubFilesAfterFirstBuild[file]
|
||||||
val fileContentsAfterSecondBuild = stubFilesAfterSecondBuild[file]
|
val fileContentsAfterSecondBuild = stubFilesAfterSecondBuild[file]
|
||||||
assertEquals(fileContentsAfterFirstBuild, fileContentsAfterSecondBuild)
|
assertEquals(fileContentsAfterFirstBuild, fileContentsAfterSecondBuild)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user