diff --git a/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/kotlin/org/jetbrains/kotlin/gradle/UpToDatenessIT.kt b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/kotlin/org/jetbrains/kotlin/gradle/UpToDatenessIT.kt index 1afeca3faab..4216c46d47a 100644 --- a/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/kotlin/org/jetbrains/kotlin/gradle/UpToDatenessIT.kt +++ b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/kotlin/org/jetbrains/kotlin/gradle/UpToDatenessIT.kt @@ -8,79 +8,71 @@ import java.io.File class UpToDateIT : BaseGradleIT() { @Test - fun testNoMutation() = testWithMutation(object : ProjectMutation { + fun testWithAllMutations() { + val project = Project("simpleProject", "4.1") + project.setupWorkingDir() + mutations.forEach { it.initProject(project) } + project.build("build") { assertSuccessful() } + mutations.forEach { + it.mutateProject(project) + project.build("build") { + assertSuccessful() + it.checkAfterRebuild(this) + } + } + } + + private val mutations + get() = listOf( + emptyMutation, + optionMutation("compileKotlin.kotlinOptions.jvmTarget", "'1.6'", "'1.8'", + shouldOutdateCompileKotlin = true), + optionMutation("compileKotlin.kotlinOptions.freeCompilerArgs", "[]", "['-Xallow-kotlin-package']", + shouldOutdateCompileKotlin = true), + optionMutation("kotlin.experimental.coroutines", "'error'", "'enable'", + shouldOutdateCompileKotlin = true), + optionMutation("archivesBaseName", "'someName'", "'otherName'", + shouldOutdateCompileKotlin = true), + externalOutputMutation, + compilerClasspathMutation) + + private val emptyMutation = object : ProjectMutation { override fun initProject(project: Project) = Unit override fun mutateProject(project: Project) = Unit override fun checkAfterRebuild(compiledProject: CompiledProject) = with(compiledProject) { assertTasksUpToDate(listOf(":compileKotlin")) } - }) + } - @Test - fun testJvmTargetMutation() = testWithMutation(optionMutation( - "compileKotlin.kotlinOptions.jvmTarget", "'1.6'", "'1.8'", - shouldOutdateCompileKotlin = true)) + private val compilerClasspathMutation = object : ProjectMutation { + lateinit var originalCompilerCp: List + val originalPaths get() = originalCompilerCp.map { it.replace("\\", "/") }.joinToString(", ") { "'$it'" } - @Test - fun testFreeCompilerArgsMutation() = testWithMutation(optionMutation( - "compileKotlin.kotlinOptions.freeCompilerArgs", "[]", "['-Xallow-kotlin-package']", - shouldOutdateCompileKotlin = true)) - - @Test - fun testCoroutinesMutation() = testWithMutation(optionMutation( - "kotlin.experimental.coroutines", "'error'", "'enable'", - shouldOutdateCompileKotlin = true)) - - @Test - fun testArchivesBaseNameMutation() = testWithMutation(optionMutation( - "archivesBaseName", "'someName'", "'otherName'", - shouldOutdateCompileKotlin = true)) - - @Test - fun testSubpluginOptionsMutation() = testWithMutation(object : ProjectMutation { override fun initProject(project: Project) = with(project) { - buildGradle.appendText("""${'\n'} - buildscript { dependencies { classpath "org.jetbrains.kotlin:kotlin-allopen:${'$'}kotlin_version" } } - apply plugin: "kotlin-allopen" - allOpen { annotation("com.my.Annotation") } - """.trimIndent()) + buildGradle.appendText("\nprintln 'compiler_cp=' + compileKotlin.getComputedCompilerClasspath\$kotlin_gradle_plugin()") + build("clean") { originalCompilerCp = "compiler_cp=\\[(.*)]".toRegex().find(output)!!.groupValues[1].split(", ") } + buildGradle.appendText("\ncompileKotlin.compilerClasspath = files($originalPaths).toList()") } override fun mutateProject(project: Project) = with(project) { - buildGradle.modify { it.replace("com.my.Annotation", "com.my.AnotherAnnotation") } - } - - override fun checkAfterRebuild(compiledProject: CompiledProject) = with(compiledProject) { - assertTasksExecuted(listOf(":compileKotlin")) - } - }) - - @Test - fun testCompilerJarMutation() = testWithMutation(object : ProjectMutation { - lateinit var originalCompilerJar: File - val originalPath get() = originalCompilerJar.absolutePath.replace("\\", "/") - - override fun initProject(project: Project) = with(project) { - buildGradle.appendText("\nprintln 'compiler_jar=' + compileKotlin.getCompilerJar\$kotlin_gradle_plugin()") - build("clean") { originalCompilerJar = File("compiler_jar=(.*)".toRegex().find(output)!!.groupValues[1]) } - buildGradle.appendText("\ncompileKotlin.compilerJarFile = file('$originalPath')") - } - - override fun mutateProject(project: Project) = with(project) { - val localCompilerJar = originalCompilerJar.copyTo(File(projectDir, "compiler.jar")) buildGradle.modify { - it.replace("file('${originalPath}')", "file('${localCompilerJar.absolutePath.replace('\\', '/')}')") + val modifiedClasspath = originalCompilerCp.map { + val file = File(it) + val newFile = File(projectDir, file.nameWithoutExtension + "-1.jar") + file.copyTo(newFile) + newFile.absolutePath + }.reversed() + it.replace(originalPaths, modifiedClasspath.joinToString(", ") { "'${it.replace("\\", "/")}'" }) } } override fun checkAfterRebuild(compiledProject: CompiledProject) = with(compiledProject) { assertTasksExecuted(listOf(":compileKotlin")) } - }) + } - @Test - fun testExternalOutputMutation() = testWithMutation(object : ProjectMutation { + private val externalOutputMutation = object : ProjectMutation { override fun initProject(project: Project) = Unit lateinit var helloWorldKtClass: File @@ -95,19 +87,6 @@ class UpToDateIT : BaseGradleIT() { assertTasksExecuted(listOf(":compileKotlin")) Assert.assertTrue(helloWorldKtClass.exists()) } - }) - - private fun testWithMutation(projectMutation: ProjectMutation) { - val project = Project("simpleProject", "4.1") - project.projectDir.run { if (exists()) deleteRecursively() } - project.setupWorkingDir() - projectMutation.initProject(project) - project.build("build") { assertSuccessful() } - projectMutation.mutateProject(project) - project.build("build") { - assertSuccessful() - projectMutation.checkAfterRebuild(this) - } } private val BaseGradleIT.Project.buildGradle get() = File(projectDir, "build.gradle")