2727
2828import com .diffplug .common .base .CharMatcher ;
2929import com .diffplug .common .base .Splitter ;
30- import com .diffplug .common .base .StringPrinter ;
3130import com .diffplug .spotless .LineEnding ;
3231
3332/** Tests the desired behavior from https://github.com/diffplug/spotless/issues/46. */
@@ -70,7 +69,7 @@ void anyExceptionShouldFail() throws Exception {
7069 "> Task :spotlessMisc FAILED\n " +
7170 "Step 'no swearing' found problem in 'README.md':\n " +
7271 "No swearing!\n " +
73- "java.lang.RuntimeException: No swearing!\n " );
72+ "java.lang.RuntimeException: No swearing!" );
7473 }
7574
7675 @ Test
@@ -80,7 +79,7 @@ void unlessEnforceCheckIsFalse() throws Exception {
8079 " enforceCheck false" ,
8180 "} // spotless" );
8281 setFile ("README.md" ).toContent ("This code is fubar." );
83- runWithSuccess ("> Task :compileJava NO-SOURCE" );
82+ runWithSuccess ("> Task :processResources NO-SOURCE" );
8483 }
8584
8685 @ Test
@@ -101,7 +100,7 @@ void unlessExemptedByPath() throws Exception {
101100 " } // format" ,
102101 "} // spotless" );
103102 setFile ("README.md" ).toContent ("This code is fubar." );
104- runWithSuccess ("> Task :spotlessMisc" ,
103+ runWithSuccess ("> Task :spotlessMisc\n " +
105104 "Unable to apply step 'no swearing' to 'README.md'" );
106105 }
107106
@@ -116,26 +115,30 @@ void failsIfNeitherStepNorFileExempted() throws Exception {
116115 runWithFailure ("> Task :spotlessMisc FAILED\n " +
117116 "Step 'no swearing' found problem in 'README.md':\n " +
118117 "No swearing!\n " +
119- "java.lang.RuntimeException: No swearing!\n " );
118+ "java.lang.RuntimeException: No swearing!" );
120119 }
121120
122- private void runWithSuccess (String ... messages ) throws Exception {
121+ private void runWithSuccess (String expectedToStartWith ) throws Exception {
123122 BuildResult result = gradleRunner ().withArguments ("check" ).build ();
124- assertResultAndMessages (result , TaskOutcome .SUCCESS , messages );
123+ assertResultAndMessages (result , TaskOutcome .SUCCESS , expectedToStartWith );
125124 }
126125
127- private void runWithFailure (String ... messages ) throws Exception {
126+ private void runWithFailure (String expectedToStartWith ) throws Exception {
128127 BuildResult result = gradleRunner ().withArguments ("check" ).buildAndFail ();
129- assertResultAndMessages (result , TaskOutcome .FAILED , messages );
128+ assertResultAndMessages (result , TaskOutcome .FAILED , expectedToStartWith );
130129 }
131130
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+
134137 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 ()));
136139 String actualStart = String .join ("\n " , actualLines .subList (0 , numNewlines + 1 ));
137140 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 ());
140143 }
141144}
0 commit comments