1515 */
1616package com .diffplug .gradle .spotless ;
1717
18- import static org .assertj .core .api .Assertions .assertThat ;
19-
2018import java .io .IOException ;
2119
22- import org .gradle . testkit . runner . BuildResult ;
23- import org .junit .jupiter .api . Test ;
20+ import org .junit . jupiter . params . ParameterizedTest ;
21+ import org .junit .jupiter .params . provider . ValueSource ;
2422
25- class KotlinGradleExtensionTest extends GradleIntegrationHarness {
26- @ Test
27- void integration_default_diktat () throws IOException {
28- setFile ("build.gradle" ).toLines (
29- "plugins {" ,
30- " id 'org.jetbrains.kotlin.jvm' version '1.4.30'" ,
31- " id 'com.diffplug.spotless'" ,
32- "}" ,
33- "repositories { mavenCentral() }" ,
34- "spotless {" ,
35- " kotlinGradle {" ,
36- " diktat()" ,
37- " }" ,
38- "}" );
39- setFile ("configuration.gradle.kts" ).toResource ("kotlin/diktat/basic.dirty" );
40- BuildResult result = gradleRunner ().withArguments ("spotlessApply" ).buildAndFail ();
41- assertThat (result .getOutput ()).contains ("[AVOID_NESTED_FUNCTIONS] try to avoid using nested functions" );
42- }
23+ /**
24+ * We test KotlinGradleExtension only behaviors here.
25+ */
26+ class KotlinGradleExtensionTest extends KotlinExtensionTest {
4327
44- @ Test
45- void withExperimentalEditorConfigOverride () throws IOException {
28+ @ ParameterizedTest
29+ @ ValueSource (booleans = {true , false })
30+ void testTarget (boolean useDefaultTarget ) throws IOException {
4631 setFile ("build.gradle" ).toLines (
4732 "plugins {" ,
4833 " id 'org.jetbrains.kotlin.jvm' version '1.5.31'" ,
@@ -51,6 +36,7 @@ void withExperimentalEditorConfigOverride() throws IOException {
5136 "repositories { mavenCentral() }" ,
5237 "spotless {" ,
5338 " kotlinGradle {" ,
39+ " " + (useDefaultTarget ? "" : "target \" *.kts\" " ),
5440 " ktlint().editorConfigOverride([" ,
5541 " ktlint_experimental: \" enabled\" ," ,
5642 " ij_kotlin_allow_trailing_comma: true," ,
@@ -59,25 +45,14 @@ void withExperimentalEditorConfigOverride() throws IOException {
5945 " }" ,
6046 "}" );
6147 setFile ("configuration.gradle.kts" ).toResource ("kotlin/ktlint/experimentalEditorConfigOverride.dirty" );
48+ setFile ("configuration.kts" ).toResource ("kotlin/ktlint/experimentalEditorConfigOverride.dirty" );
6249 gradleRunner ().withArguments ("spotlessApply" ).build ();
63- assertFile ("configuration.gradle.kts" ).sameAsResource ("kotlin/ktlint/experimentalEditorConfigOverride.clean" );
64- }
65-
66- @ Test
67- void integration_ktfmt_with_dropbox_style () throws IOException {
68- setFile ("build.gradle" ).toLines (
69- "plugins {" ,
70- " id 'org.jetbrains.kotlin.jvm' version '1.5.31'" ,
71- " id 'com.diffplug.spotless'" ,
72- "}" ,
73- "repositories { mavenCentral() }" ,
74- "spotless {" ,
75- " kotlinGradle {" ,
76- " ktfmt().dropboxStyle()" ,
77- " }" ,
78- "}" );
79- setFile ("configuration.gradle.kts" ).toResource ("kotlin/ktfmt/dropboxstyle.dirty" );
80- gradleRunner ().withArguments ("spotlessApply" ).build ();
81- assertFile ("configuration.gradle.kts" ).sameAsResource ("kotlin/ktfmt/dropboxstyle.clean" );
50+ if (useDefaultTarget ) {
51+ assertFile ("configuration.gradle.kts" ).sameAsResource ("kotlin/ktlint/experimentalEditorConfigOverride.clean" );
52+ assertFile ("configuration.kts" ).sameAsResource ("kotlin/ktlint/experimentalEditorConfigOverride.dirty" );
53+ } else {
54+ assertFile ("configuration.gradle.kts" ).sameAsResource ("kotlin/ktlint/experimentalEditorConfigOverride.clean" );
55+ assertFile ("configuration.kts" ).sameAsResource ("kotlin/ktlint/experimentalEditorConfigOverride.clean" );
56+ }
8257 }
8358}
0 commit comments