15
15
*/
16
16
package com .diffplug .gradle .spotless ;
17
17
18
- import static org .assertj .core .api .Assertions .assertThat ;
19
-
20
18
import java .io .IOException ;
21
19
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 ;
24
22
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 {
43
27
44
- @ Test
45
- void withExperimentalEditorConfigOverride () throws IOException {
28
+ @ ParameterizedTest
29
+ @ ValueSource (booleans = {true , false })
30
+ void testTarget (boolean useDefaultTarget ) throws IOException {
46
31
setFile ("build.gradle" ).toLines (
47
32
"plugins {" ,
48
33
" id 'org.jetbrains.kotlin.jvm' version '1.5.31'" ,
@@ -51,6 +36,7 @@ void withExperimentalEditorConfigOverride() throws IOException {
51
36
"repositories { mavenCentral() }" ,
52
37
"spotless {" ,
53
38
" kotlinGradle {" ,
39
+ " " + (useDefaultTarget ? "" : "target \" *.kts\" " ),
54
40
" ktlint().editorConfigOverride([" ,
55
41
" ktlint_experimental: \" enabled\" ," ,
56
42
" ij_kotlin_allow_trailing_comma: true," ,
@@ -59,25 +45,14 @@ void withExperimentalEditorConfigOverride() throws IOException {
59
45
" }" ,
60
46
"}" );
61
47
setFile ("configuration.gradle.kts" ).toResource ("kotlin/ktlint/experimentalEditorConfigOverride.dirty" );
48
+ setFile ("configuration.kts" ).toResource ("kotlin/ktlint/experimentalEditorConfigOverride.dirty" );
62
49
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
+ }
82
57
}
83
58
}
0 commit comments