From de8fc9fb75893c8e50570f29a50e26a2d32b3a4b Mon Sep 17 00:00:00 2001 From: wakingrufus Date: Tue, 28 Mar 2023 09:07:14 -0500 Subject: [PATCH] WIP repro #657 --- .../gradle/ktlint/ConfigurationCacheTest.kt | 47 +++++++++++-------- .../gradle/ktlint/testdsl/TestAnnotations.kt | 2 +- .../gradle/ktlint/testdsl/TestDsl.kt | 40 ++++++++++++++++ 3 files changed, 68 insertions(+), 21 deletions(-) diff --git a/plugin/src/test/kotlin/org/jlleitschuh/gradle/ktlint/ConfigurationCacheTest.kt b/plugin/src/test/kotlin/org/jlleitschuh/gradle/ktlint/ConfigurationCacheTest.kt index 5b882d91..b16b8db1 100644 --- a/plugin/src/test/kotlin/org/jlleitschuh/gradle/ktlint/ConfigurationCacheTest.kt +++ b/plugin/src/test/kotlin/org/jlleitschuh/gradle/ktlint/ConfigurationCacheTest.kt @@ -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 @@ -18,19 +15,23 @@ 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) } @@ -38,7 +39,8 @@ class ConfigurationCacheTest : AbstractPluginTest() { 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.") @@ -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) @@ -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) diff --git a/plugin/src/test/kotlin/org/jlleitschuh/gradle/ktlint/testdsl/TestAnnotations.kt b/plugin/src/test/kotlin/org/jlleitschuh/gradle/ktlint/testdsl/TestAnnotations.kt index 497fdcf6..a791fe37 100644 --- a/plugin/src/test/kotlin/org/jlleitschuh/gradle/ktlint/testdsl/TestAnnotations.kt +++ b/plugin/src/test/kotlin/org/jlleitschuh/gradle/ktlint/testdsl/TestAnnotations.kt @@ -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" diff --git a/plugin/src/test/kotlin/org/jlleitschuh/gradle/ktlint/testdsl/TestDsl.kt b/plugin/src/test/kotlin/org/jlleitschuh/gradle/ktlint/testdsl/TestDsl.kt index 97c2ae80..22729e33 100644 --- a/plugin/src/test/kotlin/org/jlleitschuh/gradle/ktlint/testdsl/TestDsl.kt +++ b/plugin/src/test/kotlin/org/jlleitschuh/gradle/ktlint/testdsl/TestDsl.kt @@ -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) @@ -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