Skip to content

Commit 2678c36

Browse files
jlavalleeronshapiro
authored andcommitted
Migrate callers of Truth's Subject.failWithRawMessage to Subject.failWithoutActual
Requires the use of Guava 25.1 for Strings.lenientFormat and Truth 0.41 for Subject.failWithoutActual RELNOTES: Migrated from Subject.failWithRawMessage to Subject.failWithoutActual ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=205284461
1 parent fbbf29e commit 2678c36

3 files changed

Lines changed: 78 additions & 66 deletions

File tree

pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
<description>Utilities for testing compilation.</description>
1616

1717
<properties>
18-
<truth.version>0.37</truth.version>
18+
<truth.version>0.41</truth.version>
1919
</properties>
2020

2121
<url>http://github.com/google/compile-testing</url>
@@ -65,7 +65,7 @@
6565
<dependency>
6666
<groupId>com.google.guava</groupId>
6767
<artifactId>guava</artifactId>
68-
<version>23.6-jre</version>
68+
<version>25.1-jre</version>
6969
</dependency>
7070
<dependency>
7171
<groupId>com.google.code.findbugs</groupId>

src/main/java/com/google/testing/compile/CompilationSubject.java

Lines changed: 27 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import static com.google.common.base.Predicates.notNull;
2020
import static com.google.common.collect.Iterables.size;
2121
import static com.google.common.collect.Streams.mapWithIndex;
22+
import static com.google.common.truth.Fact.simpleFact;
2223
import static com.google.common.truth.Truth.assertAbout;
2324
import static com.google.testing.compile.Compilation.Status.FAILURE;
2425
import static com.google.testing.compile.Compilation.Status.SUCCESS;
@@ -76,8 +77,9 @@ public static CompilationSubject assertThat(Compilation actual) {
7677
/** Asserts that the compilation succeeded. */
7778
public void succeeded() {
7879
if (actual().status().equals(FAILURE)) {
79-
failWithRawMessage(
80-
actual().describeFailureDiagnostics() + actual().describeGeneratedSourceFiles());
80+
failWithoutActual(
81+
simpleFact(
82+
actual().describeFailureDiagnostics() + actual().describeGeneratedSourceFiles()));
8183
}
8284
}
8385

@@ -90,9 +92,10 @@ public void succeededWithoutWarnings() {
9092
/** Asserts that the compilation failed. */
9193
public void failed() {
9294
if (actual().status().equals(SUCCESS)) {
93-
failWithRawMessage(
94-
"Compilation was expected to fail, but contained no errors.\n\n"
95-
+ actual().describeGeneratedSourceFiles());
95+
failWithoutActual(
96+
simpleFact(
97+
"Compilation was expected to fail, but contained no errors.\n\n"
98+
+ actual().describeGeneratedSourceFiles()));
9699
}
97100
}
98101

@@ -171,14 +174,15 @@ private void checkDiagnosticCount(
171174
actual().diagnosticsOfKind(kind, more);
172175
int actualCount = size(diagnostics);
173176
if (actualCount != expectedCount) {
174-
failWithRawMessage(
175-
messageListing(
176-
diagnostics,
177-
"Expected %d %s, but found the following %d %s:",
178-
expectedCount,
179-
kindPlural(kind),
180-
actualCount,
181-
kindPlural(kind)));
177+
failWithoutActual(
178+
simpleFact(
179+
messageListing(
180+
diagnostics,
181+
"Expected %d %s, but found the following %d %s:",
182+
expectedCount,
183+
kindPlural(kind),
184+
actualCount,
185+
kindPlural(kind))));
182186
}
183187
}
184188

@@ -283,8 +287,10 @@ private ImmutableList<Diagnostic<? extends JavaFileObject>> findMatchingDiagnost
283287
.filter(diagnostic -> expectedPattern.matcher(diagnostic.getMessage(null)).find())
284288
.collect(toImmutableList());
285289
if (diagnosticsWithMessage.isEmpty()) {
286-
failWithRawMessage(
287-
messageListing(diagnosticsOfKind, "Expected %s, but only found:", expectedDiagnostic));
290+
failWithoutActual(
291+
simpleFact(
292+
messageListing(
293+
diagnosticsOfKind, "Expected %s, but only found:", expectedDiagnostic)));
288294
}
289295
return diagnosticsWithMessage;
290296
}
@@ -375,11 +381,12 @@ <T> Stream<T> mapDiagnostics(Function<? super Diagnostic<? extends JavaFileObjec
375381
}
376382

377383
protected void failExpectingMatchingDiagnostic(String format, Object... args) {
378-
failWithRawMessage(
379-
new StringBuilder("Expected ")
380-
.append(expectedDiagnostic)
381-
.append(String.format(format, args))
382-
.toString());
384+
failWithoutActual(
385+
simpleFact(
386+
new StringBuilder("Expected ")
387+
.append(expectedDiagnostic)
388+
.append(String.format(format, args))
389+
.toString()));
383390
}
384391
}
385392

src/main/java/com/google/testing/compile/JavaSourcesSubject.java

Lines changed: 49 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
*/
1616
package com.google.testing.compile;
1717

18+
import static com.google.common.truth.Fact.simpleFact;
1819
import static com.google.common.truth.Truth.assertAbout;
1920
import static com.google.testing.compile.CompilationSubject.compilations;
2021
import static com.google.testing.compile.Compiler.javac;
@@ -150,8 +151,9 @@ private CompilationClause(Iterable<? extends Processor> processors) {
150151
@Override
151152
public void parsesAs(JavaFileObject first, JavaFileObject... rest) {
152153
if (Iterables.isEmpty(actual())) {
153-
failWithRawMessage(
154-
"Compilation generated no additional source files, though some were expected.");
154+
failWithoutActual(
155+
simpleFact(
156+
"Compilation generated no additional source files, though some were expected."));
155157
return;
156158
}
157159
ParseResult actualResult = Parser.parse(actual());
@@ -163,7 +165,7 @@ public void parsesAs(JavaFileObject first, JavaFileObject... rest) {
163165
message.append('\n');
164166
message.append(error);
165167
}
166-
failWithRawMessage(message.toString());
168+
failWithoutActual(simpleFact(message.toString()));
167169
return;
168170
}
169171
final ParseResult expectedResult = Parser.parse(Lists.asList(first, rest));
@@ -246,51 +248,54 @@ public String apply(CompilationUnitTree generated) {
246248
}
247249
})
248250
.toList());
249-
failWithRawMessage(
250-
Joiner.on('\n')
251-
.join(
252-
"",
253-
"An expected source declared one or more top-level types that were not present.",
254-
"",
255-
String.format("Expected top-level types: <%s>", expectedTypes),
256-
String.format(
257-
"Declared by expected file: <%s>",
258-
expectedTree.getSourceFile().toUri().getPath()),
259-
"",
260-
"The top-level types that were present are as follows: ",
261-
"",
262-
generatedTypesReport,
263-
""));
251+
failWithoutActual(
252+
simpleFact(
253+
Joiner.on('\n')
254+
.join(
255+
"",
256+
"An expected source declared one or more top-level types that were not "
257+
+ "present.",
258+
"",
259+
String.format("Expected top-level types: <%s>", expectedTypes),
260+
String.format(
261+
"Declared by expected file: <%s>",
262+
expectedTree.getSourceFile().toUri().getPath()),
263+
"",
264+
"The top-level types that were present are as follows: ",
265+
"",
266+
generatedTypesReport,
267+
"")));
264268
}
265269

266270
/** Called when the {@code generatesSources()} verb fails with a diff candidate. */
267271
private void failWithCandidate(
268272
JavaFileObject expectedSource, JavaFileObject actualSource, String diffReport) {
269273
try {
270-
failWithRawMessage(
271-
Joiner.on('\n')
272-
.join(
273-
"",
274-
"Source declared the same top-level types of an expected source, but",
275-
"didn't match exactly.",
276-
"",
277-
String.format("Expected file: <%s>", expectedSource.toUri().getPath()),
278-
String.format("Actual file: <%s>", actualSource.toUri().getPath()),
279-
"",
280-
"Diffs:",
281-
"======",
282-
"",
283-
diffReport,
284-
"",
285-
"Expected Source: ",
286-
"================",
287-
"",
288-
expectedSource.getCharContent(false).toString(),
289-
"",
290-
"Actual Source:",
291-
"=================",
292-
"",
293-
actualSource.getCharContent(false).toString()));
274+
failWithoutActual(
275+
simpleFact(
276+
Joiner.on('\n')
277+
.join(
278+
"",
279+
"Source declared the same top-level types of an expected source, but",
280+
"didn't match exactly.",
281+
"",
282+
String.format("Expected file: <%s>", expectedSource.toUri().getPath()),
283+
String.format("Actual file: <%s>", actualSource.toUri().getPath()),
284+
"",
285+
"Diffs:",
286+
"======",
287+
"",
288+
diffReport,
289+
"",
290+
"Expected Source: ",
291+
"================",
292+
"",
293+
expectedSource.getCharContent(false).toString(),
294+
"",
295+
"Actual Source:",
296+
"=================",
297+
"",
298+
actualSource.getCharContent(false).toString())));
294299
} catch (IOException e) {
295300
throw new IllegalStateException(
296301
"Couldn't read from JavaFileObject when it was already " + "in memory.", e);
@@ -471,8 +476,8 @@ public T generatesSources(JavaFileObject first, JavaFileObject... rest) {
471476
public T generatesFiles(JavaFileObject first, JavaFileObject... rest) {
472477
for (JavaFileObject expected : Lists.asList(first, rest)) {
473478
if (!wasGenerated(expected)) {
474-
failWithRawMessage(
475-
"Did not find a generated file corresponding to " + expected.getName());
479+
failWithoutActual(
480+
simpleFact("Did not find a generated file corresponding to " + expected.getName()));
476481
}
477482
}
478483
return thisObject();

0 commit comments

Comments
 (0)