27
27
28
28
import com .diffplug .common .base .CharMatcher ;
29
29
import com .diffplug .common .base .Splitter ;
30
- import com .diffplug .common .base .StringPrinter ;
31
30
import com .diffplug .spotless .LineEnding ;
32
31
33
32
/** Tests the desired behavior from https://github.com/diffplug/spotless/issues/46. */
@@ -70,7 +69,7 @@ void anyExceptionShouldFail() throws Exception {
70
69
"> Task :spotlessMisc FAILED\n " +
71
70
"Step 'no swearing' found problem in 'README.md':\n " +
72
71
"No swearing!\n " +
73
- "java.lang.RuntimeException: No swearing!\n " );
72
+ "java.lang.RuntimeException: No swearing!" );
74
73
}
75
74
76
75
@ Test
@@ -80,7 +79,7 @@ void unlessEnforceCheckIsFalse() throws Exception {
80
79
" enforceCheck false" ,
81
80
"} // spotless" );
82
81
setFile ("README.md" ).toContent ("This code is fubar." );
83
- runWithSuccess ("> Task :compileJava NO-SOURCE" );
82
+ runWithSuccess ("> Task :processResources NO-SOURCE" );
84
83
}
85
84
86
85
@ Test
@@ -101,7 +100,7 @@ void unlessExemptedByPath() throws Exception {
101
100
" } // format" ,
102
101
"} // spotless" );
103
102
setFile ("README.md" ).toContent ("This code is fubar." );
104
- runWithSuccess ("> Task :spotlessMisc" ,
103
+ runWithSuccess ("> Task :spotlessMisc\n " +
105
104
"Unable to apply step 'no swearing' to 'README.md'" );
106
105
}
107
106
@@ -116,26 +115,30 @@ void failsIfNeitherStepNorFileExempted() throws Exception {
116
115
runWithFailure ("> Task :spotlessMisc FAILED\n " +
117
116
"Step 'no swearing' found problem in 'README.md':\n " +
118
117
"No swearing!\n " +
119
- "java.lang.RuntimeException: No swearing!\n " );
118
+ "java.lang.RuntimeException: No swearing!" );
120
119
}
121
120
122
- private void runWithSuccess (String ... messages ) throws Exception {
121
+ private void runWithSuccess (String expectedToStartWith ) throws Exception {
123
122
BuildResult result = gradleRunner ().withArguments ("check" ).build ();
124
- assertResultAndMessages (result , TaskOutcome .SUCCESS , messages );
123
+ assertResultAndMessages (result , TaskOutcome .SUCCESS , expectedToStartWith );
125
124
}
126
125
127
- private void runWithFailure (String ... messages ) throws Exception {
126
+ private void runWithFailure (String expectedToStartWith ) throws Exception {
128
127
BuildResult result = gradleRunner ().withArguments ("check" ).buildAndFail ();
129
- assertResultAndMessages (result , TaskOutcome .FAILED , messages );
128
+ assertResultAndMessages (result , TaskOutcome .FAILED , expectedToStartWith );
130
129
}
131
130
132
- private void assertResultAndMessages (BuildResult result , TaskOutcome outcome , String ... messages ) {
133
- String expectedToStartWith = StringPrinter .buildStringFromLines (messages ).trim ();
131
+ private void assertResultAndMessages (BuildResult result , TaskOutcome outcome , String expectedToStartWith ) {
132
+ String output = result .getOutput ();
133
+ int register = output .indexOf (":spotlessInternalRegisterDependencies" );
134
+ int firstNewlineAfterThat = output .indexOf ('\n' , register + 1 );
135
+ String useThisToMatch = output .substring (firstNewlineAfterThat );
136
+
134
137
int numNewlines = CharMatcher .is ('\n' ).countIn (expectedToStartWith );
135
- List <String > actualLines = Splitter .on ('\n' ).splitToList (LineEnding .toUnix (result . getOutput () .trim ()));
138
+ List <String > actualLines = Splitter .on ('\n' ).splitToList (LineEnding .toUnix (useThisToMatch .trim ()));
136
139
String actualStart = String .join ("\n " , actualLines .subList (0 , numNewlines + 1 ));
137
140
Assertions .assertThat (actualStart ).isEqualTo (expectedToStartWith );
138
- Assertions .assertThat (result . tasks ( outcome ).size () + result . tasks ( TaskOutcome .UP_TO_DATE ).size () + result . tasks ( TaskOutcome .NO_SOURCE ).size ())
139
- .isEqualTo (result . getTasks ( ).size ());
141
+ Assertions .assertThat (outcomes ( result , outcome ).size () + outcomes ( result , TaskOutcome .UP_TO_DATE ).size () + outcomes ( result , TaskOutcome .NO_SOURCE ).size ())
142
+ .isEqualTo (outcomes ( result ).size ());
140
143
}
141
144
}
0 commit comments