1
1
/*
2
- * Copyright 2020-2021 DiffPlug
2
+ * Copyright 2020-2025 DiffPlug
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
17
17
18
18
import java .io .IOException ;
19
19
20
+ import org .gradle .testkit .runner .GradleRunner ;
20
21
import org .junit .jupiter .api .Test ;
21
22
22
- class ToggleOffOnTest extends GradleIntegrationHarness {
23
+ abstract class ToggleOffOnTest extends GradleIntegrationHarness {
24
+ private boolean useConfigCache ;
25
+
26
+ ToggleOffOnTest (boolean useConfigCache ) {
27
+ this .useConfigCache = useConfigCache ;
28
+ }
29
+
30
+ static class WithConfigCache extends ToggleOffOnTest {
31
+ WithConfigCache () {
32
+ super (true );
33
+ }
34
+ }
35
+
36
+ static class WithoutConfigCache extends ToggleOffOnTest {
37
+ WithoutConfigCache () {
38
+ super (false );
39
+ }
40
+ }
41
+
42
+ @ Override
43
+ public GradleRunner gradleRunner () throws IOException {
44
+ if (useConfigCache ) {
45
+ setFile ("gradle.properties" ).toLines ("org.gradle.unsafe.configuration-cache=true" ,
46
+ "org.gradle.configuration-cache=true" );
47
+ return super .gradleRunner ().withGradleVersion (GradleVersionSupport .CONFIGURATION_CACHE .version );
48
+ } else {
49
+ return super .gradleRunner ();
50
+ }
51
+ }
52
+
23
53
@ Test
24
- void toggleOffOn () throws IOException {
54
+ void lowercase () throws IOException {
25
55
setFile ("build.gradle" ).toLines (
26
56
"plugins { id 'com.diffplug.spotless' }" ,
27
57
"spotless {" ,
58
+ " lineEndings 'UNIX'" ,
28
59
" format 'toLower', {" ,
29
60
" target '**/*.md'" ,
30
- " custom 'lowercase', { str -> str.toLowerCase() } " ,
61
+ " addStep(com.diffplug.spotless.TestingOnly.lowercase()) " ,
31
62
" toggleOffOn()" ,
32
63
" }" ,
33
64
"}" );
@@ -37,12 +68,50 @@ void toggleOffOn() throws IOException {
37
68
"D E F" ,
38
69
"spotless:on" ,
39
70
"G H I" );
40
- gradleRunner ().withArguments ("spotlessApply" ).build ();
71
+ gradleRunner ().withArguments ("spotlessApply" , "--stacktrace" ).build ();
72
+ assertFile ("test.md" ).hasLines (
73
+ "a b c" ,
74
+ "spotless:off" ,
75
+ "D E F" ,
76
+ "spotless:on" ,
77
+ "g h i" );
78
+ gradleRunner ().withArguments ("spotlessApply" , "--stacktrace" ).build ();
79
+ gradleRunner ().withArguments ("spotlessApply" , "--stacktrace" ).build ();
80
+ gradleRunner ().withArguments ("spotlessApply" , "--stacktrace" ).build ();
81
+ setFile ("test.md" ).toLines (
82
+ "A B C" ,
83
+ "spotless:off" ,
84
+ "D E F" ,
85
+ "spotless:on" ,
86
+ "G H I" );
87
+ gradleRunner ().withArguments ("spotlessApply" , "--stacktrace" ).build ();
41
88
assertFile ("test.md" ).hasLines (
42
89
"a b c" ,
43
90
"spotless:off" ,
44
91
"D E F" ,
45
92
"spotless:on" ,
46
93
"g h i" );
47
94
}
95
+
96
+ @ Test
97
+ void gjf () throws IOException {
98
+ setFile ("build.gradle" ).toLines (
99
+ "plugins {" ,
100
+ " id 'com.diffplug.spotless'" ,
101
+ "}" ,
102
+ "repositories { mavenCentral() }" ,
103
+ "" ,
104
+ "spotless {" ,
105
+ " java {" ,
106
+ " target file('test.java')" ,
107
+ " googleJavaFormat('1.17.0')" ,
108
+ " toggleOffOn()" ,
109
+ " }" ,
110
+ "}" );
111
+
112
+ setFile ("test.java" ).toResource ("java/googlejavaformat/JavaCodeUnformatted.test" );
113
+ gradleRunner ().withArguments ("spotlessApply" ).build ();
114
+ assertFile ("test.java" ).sameAsResource ("java/googlejavaformat/JavaCodeFormatted.test" );
115
+ gradleRunner ().withArguments ("spotlessCheck" ).build ();
116
+ }
48
117
}
0 commit comments