From 53fe1e0bb2c063e6f9bbbea80bab52306975a1db Mon Sep 17 00:00:00 2001 From: Goooler Date: Sun, 26 Nov 2023 13:11:57 +0800 Subject: [PATCH] Polish KotlinGradleExtensionTest --- .../gradle/spotless/KotlinExtensionTest.java | 2 +- .../spotless/KotlinGradleExtensionTest.java | 61 ++++++------------- 2 files changed, 19 insertions(+), 44 deletions(-) diff --git a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/KotlinExtensionTest.java b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/KotlinExtensionTest.java index dd0f2f5e21..6973eb020c 100644 --- a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/KotlinExtensionTest.java +++ b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/KotlinExtensionTest.java @@ -30,7 +30,7 @@ class KotlinExtensionTest extends GradleIntegrationHarness { void integrationDiktat() throws IOException { setFile("build.gradle").toLines( "plugins {", - " id 'org.jetbrains.kotlin.jvm' version '1.4.30'", + " id 'org.jetbrains.kotlin.jvm' version '1.5.31'", " id 'com.diffplug.spotless'", "}", "repositories { mavenCentral() }", diff --git a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/KotlinGradleExtensionTest.java b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/KotlinGradleExtensionTest.java index 7dade5f2ff..f2b8590083 100644 --- a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/KotlinGradleExtensionTest.java +++ b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/KotlinGradleExtensionTest.java @@ -15,34 +15,19 @@ */ package com.diffplug.gradle.spotless; -import static org.assertj.core.api.Assertions.assertThat; - import java.io.IOException; -import org.gradle.testkit.runner.BuildResult; -import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.ValueSource; -class KotlinGradleExtensionTest extends GradleIntegrationHarness { - @Test - void integration_default_diktat() throws IOException { - setFile("build.gradle").toLines( - "plugins {", - " id 'org.jetbrains.kotlin.jvm' version '1.4.30'", - " id 'com.diffplug.spotless'", - "}", - "repositories { mavenCentral() }", - "spotless {", - " kotlinGradle {", - " diktat()", - " }", - "}"); - setFile("configuration.gradle.kts").toResource("kotlin/diktat/basic.dirty"); - BuildResult result = gradleRunner().withArguments("spotlessApply").buildAndFail(); - assertThat(result.getOutput()).contains("[AVOID_NESTED_FUNCTIONS] try to avoid using nested functions"); - } +/** + * We test KotlinGradleExtension only behaviors here. + */ +class KotlinGradleExtensionTest extends KotlinExtensionTest { - @Test - void withExperimentalEditorConfigOverride() throws IOException { + @ParameterizedTest + @ValueSource(booleans = {true, false}) + void testTarget(boolean useDefaultTarget) throws IOException { setFile("build.gradle").toLines( "plugins {", " id 'org.jetbrains.kotlin.jvm' version '1.5.31'", @@ -51,6 +36,7 @@ void withExperimentalEditorConfigOverride() throws IOException { "repositories { mavenCentral() }", "spotless {", " kotlinGradle {", + " " + (useDefaultTarget ? "" : "target \"*.kts\""), " ktlint().editorConfigOverride([", " ktlint_experimental: \"enabled\",", " ij_kotlin_allow_trailing_comma: true,", @@ -59,25 +45,14 @@ void withExperimentalEditorConfigOverride() throws IOException { " }", "}"); setFile("configuration.gradle.kts").toResource("kotlin/ktlint/experimentalEditorConfigOverride.dirty"); + setFile("configuration.kts").toResource("kotlin/ktlint/experimentalEditorConfigOverride.dirty"); gradleRunner().withArguments("spotlessApply").build(); - assertFile("configuration.gradle.kts").sameAsResource("kotlin/ktlint/experimentalEditorConfigOverride.clean"); - } - - @Test - void integration_ktfmt_with_dropbox_style() throws IOException { - setFile("build.gradle").toLines( - "plugins {", - " id 'org.jetbrains.kotlin.jvm' version '1.5.31'", - " id 'com.diffplug.spotless'", - "}", - "repositories { mavenCentral() }", - "spotless {", - " kotlinGradle {", - " ktfmt().dropboxStyle()", - " }", - "}"); - setFile("configuration.gradle.kts").toResource("kotlin/ktfmt/dropboxstyle.dirty"); - gradleRunner().withArguments("spotlessApply").build(); - assertFile("configuration.gradle.kts").sameAsResource("kotlin/ktfmt/dropboxstyle.clean"); + if (useDefaultTarget) { + assertFile("configuration.gradle.kts").sameAsResource("kotlin/ktlint/experimentalEditorConfigOverride.clean"); + assertFile("configuration.kts").sameAsResource("kotlin/ktlint/experimentalEditorConfigOverride.dirty"); + } else { + assertFile("configuration.gradle.kts").sameAsResource("kotlin/ktlint/experimentalEditorConfigOverride.clean"); + assertFile("configuration.kts").sameAsResource("kotlin/ktlint/experimentalEditorConfigOverride.clean"); + } } }