Migrate ClassFileIsRemovedIT test to new test DSL.
Rename ClassFileIsRemovedIT.kt into SourceFileIsModifiedIT.kt. ^KT-45747 In Progress
This commit is contained in:
-65
@@ -1,65 +0,0 @@
|
||||
package org.jetbrains.kotlin.gradle
|
||||
|
||||
import org.jetbrains.kotlin.gradle.util.findFileByName
|
||||
import org.jetbrains.kotlin.gradle.util.getFileByName
|
||||
import org.jetbrains.kotlin.gradle.util.modify
|
||||
import org.junit.Test
|
||||
import java.io.File
|
||||
import kotlin.test.assertNull
|
||||
import kotlin.test.assertTrue
|
||||
|
||||
class ClassFileIsRemovedIT : BaseGradleIT() {
|
||||
@Test
|
||||
fun testClassIsRemovedNonIC() {
|
||||
doTestClassIsRemoved(defaultBuildOptions())
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testClassIsRemovedIC() {
|
||||
doTestClassIsRemoved(defaultBuildOptions().copy(incremental = true))
|
||||
}
|
||||
|
||||
private fun doTestClassIsRemoved(buildOptions: BuildOptions) {
|
||||
doTest(buildOptions) { dummyFile ->
|
||||
assertTrue(dummyFile.delete(), "Could not delete $dummyFile")
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testClassIsRenamedNonIC() {
|
||||
doTestClassIsRenamed(defaultBuildOptions())
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testClassIsRenamedIC() {
|
||||
doTestClassIsRenamed(defaultBuildOptions().copy(incremental = true))
|
||||
}
|
||||
|
||||
fun doTestClassIsRenamed(buildOptions: BuildOptions) {
|
||||
doTest(buildOptions) { dummyFile ->
|
||||
dummyFile.modify { it.replace("Dummy", "ForDummies") }
|
||||
}
|
||||
}
|
||||
|
||||
fun doTest(buildOptions: BuildOptions, transformDummy: (File) -> Unit) {
|
||||
val project = Project("kotlinInJavaRoot")
|
||||
project.build("build", options = buildOptions) {
|
||||
assertSuccessful()
|
||||
}
|
||||
|
||||
val dummyFile = project.projectDir.getFileByName("Dummy.kt")
|
||||
transformDummy(dummyFile)
|
||||
|
||||
project.build("build", options = buildOptions) {
|
||||
assertSuccessful()
|
||||
val dummyClassFile = project.projectDir.findFileByName("Dummy.class")
|
||||
assertNull(dummyClassFile, "$dummyClassFile should not exist!")
|
||||
}
|
||||
|
||||
// check that class removal does not trigger rebuild
|
||||
project.build("build", options = buildOptions) {
|
||||
assertSuccessful()
|
||||
assertTasksUpToDate(":compileKotlin", ":compileJava")
|
||||
}
|
||||
}
|
||||
}
|
||||
-10
@@ -257,16 +257,6 @@ class KotlinGradleIT : BaseGradleIT() {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testKotlinInJavaRoot() {
|
||||
Project("kotlinInJavaRoot").build("build") {
|
||||
assertSuccessful()
|
||||
assertReportExists()
|
||||
assertTasksExecuted(":compileKotlin")
|
||||
assertContains(":compileTestKotlin NO-SOURCE")
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testIncrementalPropertyFromLocalPropertiesFile() {
|
||||
val project = Project("kotlinProject")
|
||||
|
||||
+82
@@ -0,0 +1,82 @@
|
||||
package org.jetbrains.kotlin.gradle
|
||||
|
||||
import org.gradle.util.GradleVersion
|
||||
import org.jetbrains.kotlin.gradle.testbase.*
|
||||
import org.junit.jupiter.api.DisplayName
|
||||
import java.nio.file.Files
|
||||
import java.nio.file.Path
|
||||
import kotlin.test.assertNull
|
||||
import kotlin.test.assertTrue
|
||||
|
||||
@DisplayName("Source file modifications")
|
||||
@SimpleGradlePluginTests
|
||||
class SourceFileIsModifiedIT : KGPBaseTest() {
|
||||
|
||||
@DisplayName("Removed in non-incremental compilation")
|
||||
@GradleTest
|
||||
fun testClassIsRemovedNonIC(gradleVersion: GradleVersion) {
|
||||
doTestClassIsRemoved(gradleVersion, defaultBuildOptions)
|
||||
}
|
||||
|
||||
@DisplayName("Removed in incremental compilation")
|
||||
@GradleTest
|
||||
fun testClassIsRemovedIC(gradleVersion: GradleVersion) {
|
||||
doTestClassIsRemoved(gradleVersion, defaultBuildOptions.copy(incremental = true))
|
||||
}
|
||||
|
||||
private fun doTestClassIsRemoved(
|
||||
gradleVersion: GradleVersion,
|
||||
buildOptions: BuildOptions
|
||||
) {
|
||||
doTest(gradleVersion, buildOptions) { dummyFile ->
|
||||
assertTrue(Files.deleteIfExists(dummyFile), "Could not delete $dummyFile")
|
||||
}
|
||||
}
|
||||
|
||||
@DisplayName("Renamed in non-incremental compilation")
|
||||
@GradleTest
|
||||
fun testClassIsRenamedNonIC(gradleVersion: GradleVersion) {
|
||||
doTestClassIsRenamed(gradleVersion, defaultBuildOptions)
|
||||
}
|
||||
|
||||
@DisplayName("Renamed in incremental compilation")
|
||||
@GradleTest
|
||||
fun testClassIsRenamedIC(gradleVersion: GradleVersion) {
|
||||
doTestClassIsRenamed(gradleVersion, defaultBuildOptions.copy(incremental = true))
|
||||
}
|
||||
|
||||
private fun doTestClassIsRenamed(
|
||||
gradleVersion: GradleVersion,
|
||||
buildOptions: BuildOptions
|
||||
) {
|
||||
doTest(gradleVersion, buildOptions) { dummyFile ->
|
||||
dummyFile.modify { it.replace("Dummy", "ForDummies") }
|
||||
}
|
||||
}
|
||||
|
||||
private fun doTest(
|
||||
gradleVersion: GradleVersion,
|
||||
buildOptions: BuildOptions,
|
||||
transformDummy: (Path) -> Unit
|
||||
) {
|
||||
project("kotlinInJavaRoot", gradleVersion) {
|
||||
build("build", buildOptions = buildOptions) {
|
||||
assertTasksExecuted(":compileKotlin")
|
||||
assertTasksNoSource(":compileTestKotlin")
|
||||
}
|
||||
|
||||
val dummyFile = projectPath.resolve("src/main/java/kotlinPackage/Dummy.kt")
|
||||
transformDummy(dummyFile)
|
||||
|
||||
build("build", buildOptions = buildOptions) {
|
||||
val dummyClassFile = kotlinClassesDir().findInPath("Dummy.class")
|
||||
assertNull(dummyClassFile, "$dummyClassFile should not exist!")
|
||||
}
|
||||
|
||||
// check that class removal does not trigger rebuild
|
||||
build("build", buildOptions = buildOptions) {
|
||||
assertTasksUpToDate(":compileKotlin", ":compileJava")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+6
@@ -18,6 +18,7 @@ import org.junit.jupiter.api.io.TempDir
|
||||
import org.junit.jupiter.params.provider.Arguments
|
||||
import org.junit.jupiter.params.provider.ArgumentsProvider
|
||||
import java.nio.file.Path
|
||||
import java.util.*
|
||||
import java.util.stream.Stream
|
||||
import kotlin.streams.asStream
|
||||
|
||||
@@ -41,6 +42,7 @@ abstract class KGPBaseTest {
|
||||
val projectIsolation: Boolean = false,
|
||||
val configurationCacheProblems: BaseGradleIT.ConfigurationCacheProblems = BaseGradleIT.ConfigurationCacheProblems.FAIL,
|
||||
val parallel: Boolean = true,
|
||||
val incremental: Boolean? = null,
|
||||
val maxWorkers: Int = (Runtime.getRuntime().availableProcessors() / 4 - 1).coerceAtLeast(2),
|
||||
val fileSystemWatchEnabled: Boolean = false,
|
||||
val buildCacheEnabled: Boolean = false,
|
||||
@@ -87,6 +89,10 @@ abstract class KGPBaseTest {
|
||||
arguments.add("--no-parallel")
|
||||
}
|
||||
|
||||
if (incremental != null) {
|
||||
arguments.add("-Pkotlin.incremental=$incremental")
|
||||
}
|
||||
|
||||
if (gradleVersion >= GradleVersion.version("6.5")) {
|
||||
if (fileSystemWatchEnabled) {
|
||||
arguments.add("--watch-fs")
|
||||
|
||||
+20
@@ -0,0 +1,20 @@
|
||||
/*
|
||||
* Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* 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.testbase
|
||||
|
||||
import java.nio.file.Files
|
||||
import java.nio.file.Path
|
||||
import kotlin.streams.asSequence
|
||||
|
||||
/**
|
||||
* Find the file with given [name] in current [Path].
|
||||
*
|
||||
* @return `null` if file is absent in current [Path]
|
||||
*/
|
||||
internal fun Path.findInPath(name: String): Path? = Files
|
||||
.walk(this)
|
||||
.asSequence()
|
||||
.find { it.fileName.toString() == name }
|
||||
+3
-12
@@ -1,16 +1,8 @@
|
||||
buildscript {
|
||||
repositories {
|
||||
mavenLocal()
|
||||
mavenCentral()
|
||||
}
|
||||
dependencies {
|
||||
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
|
||||
}
|
||||
plugins {
|
||||
id "java"
|
||||
id "org.jetbrains.kotlin.jvm"
|
||||
}
|
||||
|
||||
apply plugin: "kotlin"
|
||||
apply plugin: 'java'
|
||||
|
||||
repositories {
|
||||
mavenLocal()
|
||||
mavenCentral()
|
||||
@@ -23,7 +15,6 @@ sourceSets {
|
||||
dependencies {
|
||||
implementation 'com.google.guava:guava:12.0'
|
||||
testImplementation 'org.testng:testng:6.8'
|
||||
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
|
||||
}
|
||||
|
||||
test {
|
||||
|
||||
Reference in New Issue
Block a user