15
15
*/
16
16
package com .diffplug .gradle .spotless ;
17
17
18
- import static org .assertj .core .api .Assertions .assertThat ;
19
- import static org .junit .jupiter .api .Assertions .assertThrows ;
20
18
import static org .junit .jupiter .api .condition .JRE .JAVA_11 ;
21
19
22
20
import java .io .IOException ;
23
21
24
- import org .gradle .testkit .runner .BuildResult ;
25
22
import org .junit .jupiter .api .Test ;
26
23
import org .junit .jupiter .api .condition .EnabledForJreRange ;
27
24
@@ -42,9 +39,9 @@ void integration() throws IOException {
42
39
" ktlint()" ,
43
40
" }" ,
44
41
"}" );
45
- setFile ("src/main/kotlin/basic .kt" ).toResource ("kotlin/ktlint/basic.dirty" );
42
+ setFile ("src/main/kotlin/Main .kt" ).toResource ("kotlin/ktlint/basic.dirty" );
46
43
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" );
48
45
}
49
46
50
47
@ Test
@@ -132,12 +129,12 @@ void testWithIndentation() throws IOException {
132
129
"repositories { mavenCentral() }" ,
133
130
"spotless {" ,
134
131
" kotlin {" ,
135
- " ktlint('0.32.0').userData (['indent_size': '6'])" ,
132
+ " ktlint().editorConfigOverride (['indent_size': '6'])" ,
136
133
" }" ,
137
134
"}" );
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 " );
141
138
}
142
139
143
140
@ Test
@@ -153,27 +150,9 @@ void withExperimental() throws IOException {
153
150
" ktlint().setUseExperimental(true)" ,
154
151
" }" ,
155
152
"}" );
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" );
175
154
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" );
177
156
}
178
157
179
158
@ Test
@@ -193,31 +172,9 @@ void withExperimentalEditorConfigOverride() throws IOException {
193
172
" ])" ,
194
173
" }" ,
195
174
"}" );
196
- setFile ("src/main/kotlin/experimental .kt" ).toResource ("kotlin/ktlint/experimentalEditorConfigOverride.dirty" );
175
+ setFile ("src/main/kotlin/Main .kt" ).toResource ("kotlin/ktlint/experimentalEditorConfigOverride.dirty" );
197
176
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" );
221
178
}
222
179
223
180
/**
@@ -240,9 +197,9 @@ void experimentalSampleUnchangedWithDefaultRuleset() throws IOException {
240
197
" ktlint()" ,
241
198
" }" ,
242
199
"}" );
243
- setFile ("src/main/kotlin/experimental .kt" ).toResource ("kotlin/ktlint/experimental.dirty" );
200
+ setFile ("src/main/kotlin/Main .kt" ).toResource ("kotlin/ktlint/experimental.dirty" );
244
201
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" );
246
203
}
247
204
248
205
@ Test
0 commit comments