1515 */
1616package com .diffplug .gradle .spotless ;
1717
18- import static org .assertj .core .api .Assertions .assertThat ;
19- import static org .junit .jupiter .api .Assertions .assertThrows ;
2018import static org .junit .jupiter .api .condition .JRE .JAVA_11 ;
2119
2220import java .io .IOException ;
2321
24- import org .gradle .testkit .runner .BuildResult ;
2522import org .junit .jupiter .api .Test ;
2623import org .junit .jupiter .api .condition .EnabledForJreRange ;
2724
@@ -42,9 +39,9 @@ void integration() throws IOException {
4239 " ktlint()" ,
4340 " }" ,
4441 "}" );
45- setFile ("src/main/kotlin/basic .kt" ).toResource ("kotlin/ktlint/basic.dirty" );
42+ setFile ("src/main/kotlin/Main .kt" ).toResource ("kotlin/ktlint/basic.dirty" );
4643 gradleRunner ().withArguments ("spotlessApply" ).build ();
47- assertFile ("src/main/kotlin/basic .kt" ).sameAsResource ("kotlin/ktlint/basic.clean" );
44+ assertFile ("src/main/kotlin/Main .kt" ).sameAsResource ("kotlin/ktlint/basic.clean" );
4845 }
4946
5047 @ Test
@@ -132,12 +129,12 @@ void testWithIndentation() throws IOException {
132129 "repositories { mavenCentral() }" ,
133130 "spotless {" ,
134131 " kotlin {" ,
135- " ktlint('0.32.0').userData (['indent_size': '6'])" ,
132+ " ktlint().editorConfigOverride (['indent_size': '6'])" ,
136133 " }" ,
137134 "}" );
138- setFile ("src/main/kotlin/basic .kt" ).toResource ("kotlin/ktlint/basic.dirty" );
139- BuildResult result = gradleRunner ().withArguments ("spotlessApply" ).buildAndFail ();
140- assertThat ( result . getOutput ()). contains ( "Unexpected indentation (4) (it should be 6) " );
135+ setFile ("src/main/kotlin/Main .kt" ).toResource ("kotlin/ktlint/basic.dirty" );
136+ gradleRunner ().withArguments ("spotlessApply" ).build ();
137+ assertFile ( "src/main/kotlin/Main.kt" ). sameAsResource ( "kotlin/ktlint/basic.clean-indent6 " );
141138 }
142139
143140 @ Test
@@ -153,27 +150,9 @@ void withExperimental() throws IOException {
153150 " ktlint().setUseExperimental(true)" ,
154151 " }" ,
155152 "}" );
156- setFile ("src/main/kotlin/experimental.kt" ).toResource ("kotlin/ktlint/experimental.dirty" );
157- gradleRunner ().withArguments ("spotlessApply" ).build ();
158- assertFile ("src/main/kotlin/experimental.kt" ).sameAsResource ("kotlin/ktlint/experimental.clean" );
159- }
160-
161- @ Test
162- void withExperimental_0_32 () throws IOException {
163- setFile ("build.gradle" ).toLines (
164- "plugins {" ,
165- " id 'org.jetbrains.kotlin.jvm' version '1.5.31'" ,
166- " id 'com.diffplug.spotless'" ,
167- "}" ,
168- "repositories { mavenCentral() }" ,
169- "spotless {" ,
170- " kotlin {" ,
171- " ktlint('0.32.0').setUseExperimental(true)" ,
172- " }" ,
173- "}" );
174- setFile ("src/main/kotlin/basic.kt" ).toResource ("kotlin/ktlint/basic.dirty" );
153+ setFile ("src/main/kotlin/Main.kt" ).toResource ("kotlin/ktlint/experimental.dirty" );
175154 gradleRunner ().withArguments ("spotlessApply" ).build ();
176- assertFile ("src/main/kotlin/basic .kt" ).sameAsResource ("kotlin/ktlint/basic .clean" );
155+ assertFile ("src/main/kotlin/Main .kt" ).sameAsResource ("kotlin/ktlint/experimental .clean" );
177156 }
178157
179158 @ Test
@@ -193,31 +172,9 @@ void withExperimentalEditorConfigOverride() throws IOException {
193172 " ])" ,
194173 " }" ,
195174 "}" );
196- setFile ("src/main/kotlin/experimental .kt" ).toResource ("kotlin/ktlint/experimentalEditorConfigOverride.dirty" );
175+ setFile ("src/main/kotlin/Main .kt" ).toResource ("kotlin/ktlint/experimentalEditorConfigOverride.dirty" );
197176 gradleRunner ().withArguments ("spotlessApply" ).build ();
198- assertFile ("src/main/kotlin/experimental.kt" ).sameAsResource ("kotlin/ktlint/experimentalEditorConfigOverride.clean" );
199- }
200-
201- @ Test
202- void withEditorConfigOverride_0_45_1 () throws IOException {
203- setFile ("build.gradle" ).toLines (
204- "plugins {" ,
205- " id 'org.jetbrains.kotlin.jvm' version '1.5.31'" ,
206- " id 'com.diffplug.spotless'" ,
207- "}" ,
208- "repositories { mavenCentral() }" ,
209- "spotless {" ,
210- " kotlin {" ,
211- " ktlint('0.45.1')" ,
212- " .editorConfigOverride([" ,
213- " indent_size: 5" ,
214- " ])" ,
215- " }" ,
216- "}" );
217- setFile ("src/main/kotlin/basic.kt" ).toResource ("kotlin/ktlint/basic.dirty" );
218- Throwable error = assertThrows (Throwable .class ,
219- () -> gradleRunner ().withArguments ("spotlessApply" ).build ());
220- assertThat (error ).hasMessageContaining ("KtLint editorConfigOverride supported for version 0.45.2 and later" );
177+ assertFile ("src/main/kotlin/Main.kt" ).sameAsResource ("kotlin/ktlint/experimentalEditorConfigOverride.clean" );
221178 }
222179
223180 /**
@@ -240,9 +197,9 @@ void experimentalSampleUnchangedWithDefaultRuleset() throws IOException {
240197 " ktlint()" ,
241198 " }" ,
242199 "}" );
243- setFile ("src/main/kotlin/experimental .kt" ).toResource ("kotlin/ktlint/experimental.dirty" );
200+ setFile ("src/main/kotlin/Main .kt" ).toResource ("kotlin/ktlint/experimental.dirty" );
244201 gradleRunner ().withArguments ("spotlessApply" ).build ();
245- assertFile ("src/main/kotlin/experimental .kt" ).sameAsResource ("kotlin/ktlint/experimental.dirty" );
202+ assertFile ("src/main/kotlin/Main .kt" ).sameAsResource ("kotlin/ktlint/experimental.dirty" );
246203 }
247204
248205 @ Test
0 commit comments