Skip to content

Commit

Permalink
WIP repro #657
Browse files Browse the repository at this point in the history
  • Loading branch information
wakingrufus committed Mar 28, 2023
1 parent 8338219 commit de8fc9f
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,7 @@ import org.assertj.core.api.Assertions.assertThat
import org.gradle.testkit.runner.TaskOutcome
import org.gradle.util.GradleVersion
import org.jlleitschuh.gradle.ktlint.tasks.KtLintFormatTask
import org.jlleitschuh.gradle.ktlint.testdsl.CommonTest
import org.jlleitschuh.gradle.ktlint.testdsl.GradleTestVersions
import org.jlleitschuh.gradle.ktlint.testdsl.build
import org.jlleitschuh.gradle.ktlint.testdsl.project
import org.jlleitschuh.gradle.ktlint.testdsl.*
import org.junit.jupiter.api.DisplayName

@GradleTestVersions
Expand All @@ -18,27 +15,32 @@ class ConfigurationCacheTest : AbstractPluginTest() {
@DisplayName("Should support configuration cache without errors on running linting")
@CommonTest
internal fun configurationCacheForCheckTask(gradleVersion: GradleVersion) {
project(gradleVersion) {
createSourceFile(
"src/main/kotlin/CleanSource.kt",
project(gradleVersion = gradleVersion,
projectSetup= ktsProjectSetup(gradleVersion)) {
withFailingSources()
withCleanSources()
this.projectPath.resolve("build.gradle.kts").appendText(
"""
val foo = "bar"
""".trimIndent()
|ktlint {
| filter { exclude("**/FailSource.kt") }
|}
|
""".trimMargin()
)

build(
configurationCacheFlag,
configurationCacheWarnFlag,
CHECK_PARENT_TASK_NAME
CHECK_PARENT_TASK_NAME,
"--info"
) {
assertThat(task(":$mainSourceSetCheckTaskName")?.outcome).isEqualTo(TaskOutcome.SUCCESS)
}

build(
configurationCacheFlag,
configurationCacheWarnFlag,
CHECK_PARENT_TASK_NAME
CHECK_PARENT_TASK_NAME,
"--info"
) {
assertThat(task(":$mainSourceSetCheckTaskName")?.outcome).isEqualTo(TaskOutcome.UP_TO_DATE)
assertThat(output).contains("Reusing configuration cache.")
Expand All @@ -50,16 +52,21 @@ class ConfigurationCacheTest : AbstractPluginTest() {
@CommonTest
fun configurationCacheForFormatTasks(gradleVersion: GradleVersion) {
project(gradleVersion) {
val sourceFile = "\nval foo = \"bar\"\n"
createSourceFile(
"src/main/kotlin/CleanSource.kt",
sourceFile
)
withFailingSources()
withCleanSources()
val formatTaskName = KtLintFormatTask.buildTaskNameForSourceSet("main")
//language=Groovy
buildGradle.appendText(
"""
ktlint.filter { exclude("**/FailSource.kt") }
""".trimIndent()
)
build(
configurationCacheFlag,
configurationCacheWarnFlag,
FORMAT_PARENT_TASK_NAME
FORMAT_PARENT_TASK_NAME,
"--info"
) {
assertThat(task(":$formatTaskName")?.outcome).isEqualTo(TaskOutcome.SUCCESS)
assertThat(task(":$mainSourceSetFormatTaskName")?.outcome).isEqualTo(TaskOutcome.SUCCESS)
Expand All @@ -68,7 +75,7 @@ class ConfigurationCacheTest : AbstractPluginTest() {
configurationCacheFlag,
configurationCacheWarnFlag,
FORMAT_PARENT_TASK_NAME,
"--debug"
"--info"
) {
assertThat(task(":$formatTaskName")?.outcome).isEqualTo(TaskOutcome.UP_TO_DATE)
assertThat(task(":$mainSourceSetFormatTaskName")?.outcome).isEqualTo(TaskOutcome.UP_TO_DATE)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import kotlin.streams.asStream

object TestVersions {
const val minSupportedGradleVersion = KtlintBasePlugin.LOWEST_SUPPORTED_GRADLE_VERSION
const val maxSupportedGradleVersion = "8.0.1"
const val maxSupportedGradleVersion = "8.0.2"
val pluginVersion = File("VERSION_CURRENT.txt").readText().trim()
const val minSupportedKotlinPluginVersion = "1.4.32"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,9 @@ fun TestProject.buildAndFail(
fun defaultProjectSetup(gradleVersion: GradleVersion): (File) -> Unit =
projectSetup("jvm", gradleVersion)

fun ktsProjectSetup(gradleVersion: GradleVersion): (File) -> Unit =
ktsProject("jvm", gradleVersion)

private val GradleVersion.supportedKotlinVersion
get() = TestVersions.maxSupportedKotlinPluginVersion(this)

Expand Down Expand Up @@ -183,7 +186,44 @@ fun projectSetup(
""".trimMargin()
)
}
fun ktsProject(
kotlinPluginType: String,
gradleVersion: GradleVersion
): (File) -> Unit = {
val kotlinPluginVersion = gradleVersion.supportedKotlinVersion
//language=Groovy
it.resolve("build.gradle.kts").writeText(
"""
|plugins {
| id("org.jetbrains.kotlin.$kotlinPluginType")
| id("org.jlleitschuh.gradle.ktlint")
|}
|
|repositories {
| mavenCentral()
|}
|
""".trimMargin()
)

//language=Groovy
it.resolve("settings.gradle").writeText(
"""
|pluginManagement {
| repositories {
| mavenLocal()
| gradlePluginPortal()
| }
|
| plugins {
| id 'org.jetbrains.kotlin.$kotlinPluginType' version '$kotlinPluginVersion'
| id 'org.jlleitschuh.gradle.ktlint' version '${TestVersions.pluginVersion}'
| }
|}
|
""".trimMargin()
)
}
private val sharedTestKitDir = File(".")
.resolve(".gradle-test-kit")
.absoluteFile
Expand Down

0 comments on commit de8fc9f

Please sign in to comment.