Skip to content

Commit 33fba68

Browse files
committed
Fixup tests broken by the change to RegisterDependenciesTask.
1 parent 3557f57 commit 33fba68

File tree

3 files changed

+34
-22
lines changed

3 files changed

+34
-22
lines changed

plugin-gradle/src/test/java/com/diffplug/gradle/spotless/ErrorShouldRethrowTest.java

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727

2828
import com.diffplug.common.base.CharMatcher;
2929
import com.diffplug.common.base.Splitter;
30-
import com.diffplug.common.base.StringPrinter;
3130
import 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
}

plugin-gradle/src/test/java/com/diffplug/gradle/spotless/GradleIntegrationHarness.java

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -138,17 +138,26 @@ private void taskIsUpToDate(String task, boolean upToDate) throws IOException {
138138
pauseForFilesystem();
139139
BuildResult buildResult = gradleRunner().withArguments(task).build();
140140

141-
TaskOutcome expected = upToDate ? TaskOutcome.UP_TO_DATE : TaskOutcome.SUCCESS;
142-
TaskOutcome notExpected = upToDate ? TaskOutcome.SUCCESS : TaskOutcome.UP_TO_DATE;
143-
144-
boolean everythingAsExpected = !buildResult.tasks(expected).isEmpty() &&
145-
buildResult.tasks(notExpected).isEmpty() &&
146-
buildResult.getTasks().size() == buildResult.tasks(expected).size();
141+
List<String> expected = outcomes(buildResult, upToDate ? TaskOutcome.UP_TO_DATE : TaskOutcome.SUCCESS);
142+
List<String> notExpected = outcomes(buildResult, upToDate ? TaskOutcome.SUCCESS : TaskOutcome.UP_TO_DATE);
143+
boolean everythingAsExpected = !expected.isEmpty() && notExpected.isEmpty() && buildResult.getTasks().size() - 1 == expected.size();
147144
if (!everythingAsExpected) {
148-
fail("Expected all tasks to be " + expected + ", but instead was\n" + buildResultToString(buildResult));
145+
fail("Expected all tasks to be " + (upToDate ? TaskOutcome.UP_TO_DATE : TaskOutcome.SUCCESS) + ", but instead was\n" + buildResultToString(buildResult));
149146
}
150147
}
151148

149+
protected static List<String> outcomes(BuildResult build, TaskOutcome outcome) {
150+
return build.taskPaths(outcome).stream()
151+
.filter(s -> !s.equals(":spotlessInternalRegisterDependencies"))
152+
.collect(Collectors.toList());
153+
}
154+
155+
protected static List<BuildTask> outcomes(BuildResult build) {
156+
return build.getTasks().stream()
157+
.filter(t -> !t.getPath().equals(":spotlessInternalRegisterDependencies"))
158+
.collect(Collectors.toList());
159+
}
160+
152161
static String buildResultToString(BuildResult result) {
153162
return StringPrinter.buildString(printer -> {
154163
for (BuildTask task : result.getTasks()) {

plugin-gradle/src/test/java/com/diffplug/gradle/spotless/UpToDateTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ void testPathologicalCase() throws IOException {
8888
// the format task is UP-TO-DATE (same inputs), but the apply tasks will run again
8989
pauseForFilesystem();
9090
BuildResult buildResult = gradleRunner().withArguments("spotlessApply").build();
91-
Assertions.assertThat(buildResult.taskPaths(TaskOutcome.UP_TO_DATE)).containsExactly(":spotlessMisc");
91+
Assertions.assertThat(buildResult.taskPaths(TaskOutcome.UP_TO_DATE)).containsExactly(":spotlessInternalRegisterDependencies", ":spotlessMisc");
9292
Assertions.assertThat(buildResult.taskPaths(TaskOutcome.SUCCESS)).containsExactly(":spotlessMiscApply", ":spotlessApply");
9393
assertFile("README.md").hasContent("abc");
9494

0 commit comments

Comments
 (0)