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 4216c46d47a..b2276412b29 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,35 +8,51 @@ import java.io.File class UpToDateIT : BaseGradleIT() { @Test - fun testWithAllMutations() { + fun testLanguageVersionChange() { + testMutations(*propertyMutationChain("compileKotlin.kotlinOptions.languageVersion", + "null", "'1.1'", "'1.0'", "null")) + } + + @Test + fun testApiVersionChange() { + testMutations(*propertyMutationChain("compileKotlin.kotlinOptions.apiVersion", + "null", "'1.1'", "'1.0'", "null")) + } + + @Test + fun testOther() { + testMutations(emptyMutation, + OptionMutation("compileKotlin.kotlinOptions.jvmTarget", "'1.6'", "'1.8'"), + OptionMutation("compileKotlin.kotlinOptions.freeCompilerArgs", "[]", "['-Xallow-kotlin-package']"), + OptionMutation("kotlin.experimental.coroutines", "'error'", "'enable'"), + OptionMutation("archivesBaseName", "'someName'", "'otherName'"), + externalOutputMutation, + compilerClasspathMutation) + } + + private fun testMutations(vararg mutations: ProjectMutation) { val project = Project("simpleProject", "4.1") project.setupWorkingDir() - mutations.forEach { it.initProject(project) } - project.build("build") { assertSuccessful() } mutations.forEach { + it.initProject(project) + project.build("build") { assertSuccessful() } + it.mutateProject(project) project.build("build") { - assertSuccessful() - it.checkAfterRebuild(this) + try { + assertSuccessful() + it.checkAfterRebuild(this) + } + catch (e: Throwable) { + throw RuntimeException("Mutation '${it.name}' has failed", e) + } } } } - 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 val name = "emptyMutation" + override fun initProject(project: Project) = Unit override fun mutateProject(project: Project) = Unit @@ -46,6 +62,8 @@ class UpToDateIT : BaseGradleIT() { } private val compilerClasspathMutation = object : ProjectMutation { + override val name = "compilerClasspathMutation" + lateinit var originalCompilerCp: List val originalPaths get() = originalCompilerCp.map { it.replace("\\", "/") }.joinToString(", ") { "'$it'" } @@ -73,6 +91,8 @@ class UpToDateIT : BaseGradleIT() { } private val externalOutputMutation = object : ProjectMutation { + override val name = "externalOutputMutation" + override fun initProject(project: Project) = Unit lateinit var helloWorldKtClass: File @@ -95,16 +115,29 @@ class UpToDateIT : BaseGradleIT() { fun initProject(project: Project) fun mutateProject(project: Project) fun checkAfterRebuild(compiledProject: CompiledProject) + val name: String } - private fun optionMutation( - path: String, - oldValue: String, - newValue: String, - shouldOutdateCompileKotlin: Boolean - ) = object : ProjectMutation { + private fun propertyMutationChain(path: String, vararg values: String): Array = + arrayListOf().apply { + for (i in 1..values.lastIndex) { + add(OptionMutation(path, values[i - 1], values[i], shouldInit = i == 1)) + } + + }.toTypedArray() + + private inner class OptionMutation( + private val path: String, + private val oldValue: String, + private val newValue: String, + private val shouldInit: Boolean = true + ) : ProjectMutation { + override val name = "OptionMutation(path='$path', oldValue='$oldValue', newValue='$newValue')" + override fun initProject(project: Project) = with(project) { - buildGradle.appendText("\n$path = $oldValue") + if (shouldInit) { + buildGradle.appendText("\n$path = $oldValue") + } } override fun mutateProject(project: Project) = with(project) { @@ -112,12 +145,7 @@ class UpToDateIT : BaseGradleIT() { } override fun checkAfterRebuild(compiledProject: CompiledProject) = with(compiledProject) { - if (shouldOutdateCompileKotlin) { - assertTasksExecuted(listOf(":compileKotlin")) - } - else { - assertTasksUpToDate(listOf(":compileKotlin")) - } + assertTasksExecuted(listOf(":compileKotlin")) } } }