Test Java is up-to-date when Kotlin ABI is unchanged

This commit is contained in:
Alexey Tsvetkov
2018-05-15 21:02:27 +03:00
parent b2d13ac89b
commit f9af48c19e
6 changed files with 163 additions and 0 deletions
@@ -0,0 +1,72 @@
/*
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
* that can be found in the license/LICENSE.txt file.
*/
package org.jetbrains.kotlin.gradle
import org.jetbrains.kotlin.gradle.util.modify
import org.junit.Test
class JavaUpToDateIT : BaseGradleIT() {
@Test
fun testKotlinMethodBodyIsChanged() {
val project = Project("javaUpToDate", GradleVersionRequired.AtLeast("4.3"))
project.build("build") {
assertSuccessful()
assertTasksExecuted(":compileKotlin", ":compileJava", ":compileTestKotlin", ":compileTestJava")
}
project.projectFile("MainKotlinClass.kt").modify {
it.replace(
"fun number(): Int = 0",
"fun number(): Int = 1"
)
}
project.build("build") {
assertSuccessful()
assertTasksExecuted(":compileKotlin", ":compileTestKotlin")
assertTasksUpToDate(":compileJava", ":compileTestJava")
}
}
@Test
fun testKotlinNewLineAdded() {
val project = Project("javaUpToDate", GradleVersionRequired.AtLeast("4.3"))
project.build("build") {
assertSuccessful()
assertTasksExecuted(":compileKotlin", ":compileJava", ":compileTestKotlin", ":compileTestJava")
}
project.projectFile("MainKotlinClass.kt").modify { "\n$it" }
project.build("build") {
assertSuccessful()
assertTasksExecuted(":compileKotlin", ":compileTestKotlin")
assertTasksUpToDate(":compileJava", ":compileTestJava")
}
}
@Test
fun testPrivateMethodSignatureChanged() {
val project = Project("javaUpToDate", GradleVersionRequired.AtLeast("4.3"))
project.build("build") {
assertSuccessful()
assertTasksExecuted(":compileKotlin", ":compileJava", ":compileTestKotlin", ":compileTestJava")
}
project.projectFile("MainKotlinClass.kt").modify {
it.replace(
"private fun privateMethod() = 0",
"private fun privateMethod() = \"0\""
)
}
project.build("build") {
assertSuccessful()
// see https://github.com/gradle/gradle/issues/5013
assertTasksExecuted(":compileKotlin", ":compileJava", ":compileTestKotlin", ":compileTestJava")
}
}
}
@@ -0,0 +1,21 @@
buildscript {
repositories {
mavenLocal()
mavenCentral()
}
dependencies {
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
apply plugin: "kotlin"
apply plugin: "java"
repositories {
mavenLocal()
mavenCentral()
}
dependencies {
compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
}
@@ -0,0 +1,16 @@
/*
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
* that can be found in the license/LICENSE.txt file.
*/
package foo;
public class MainJavaClass {
public int numberFromKotlin() {
return (new MainKotlinClass()).number();
}
public int number() {
return 0;
}
}
@@ -0,0 +1,14 @@
/*
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
* that can be found in the license/LICENSE.txt file.
*/
package foo
class MainKotlinClass {
fun numberFromJava(): Int = MainJavaClass().number()
fun number(): Int = 0
private fun privateMethod() = 0
}
@@ -0,0 +1,24 @@
/*
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
* that can be found in the license/LICENSE.txt file.
*/
package foo;
public class TestJavaClass {
public int numberFromMainKotlin() {
return (new MainKotlinClass()).number();
}
public int numberFromMainJava() {
return (new MainJavaClass()).number();
}
public int numberFromTestKotlin() {
return (new TestKotlinClass()).number();
}
public int number() {
return 0;
}
}
@@ -0,0 +1,16 @@
/*
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
* that can be found in the license/LICENSE.txt file.
*/
package foo
class TestKotlinClass {
fun numberFromMainKotlin(): Int = MainKotlinClass().number()
fun numberFromMainJava(): Int = MainJavaClass().number()
fun numberFromTestJava(): Int = TestJavaClass().number()
fun number(): Int = 0
}