Skip to content

Commit 7d31b53

Browse files
Chang-Ericronshapiro
authored andcommitted
Print out warnings as well as errors in describeFailureDiagnostics.
RELNOTES=`CompilationSubject.succeeded()` now shows warnings as well as errors on failure. ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=225420368
1 parent acf6ae7 commit 7d31b53

3 files changed

Lines changed: 27 additions & 13 deletions

File tree

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

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -220,16 +220,12 @@ public String toString() {
220220

221221
/** Returns a description of the why the compilation failed. */
222222
String describeFailureDiagnostics() {
223-
ImmutableList<Diagnostic<? extends JavaFileObject>> errors = errors();
224-
if (errors.isEmpty()) {
225-
return "Compilation produced no errors.\n";
226-
}
227-
StringBuilder message = new StringBuilder("Compilation produced the following errors:\n");
228-
errors.stream().forEach(error -> message.append(error).append('\n'));
229-
// If we compiled with -Werror we should output the warnings too
230-
if (compiler.options().contains("-Werror")) {
231-
warnings().stream().forEach(warning -> message.append(warning).append('\n'));
223+
ImmutableList<Diagnostic<? extends JavaFileObject>> diagnostics = diagnostics();
224+
if (diagnostics.isEmpty()) {
225+
return "Compilation produced no diagnostics.\n";
232226
}
227+
StringBuilder message = new StringBuilder("Compilation produced the following diagnostics:\n");
228+
diagnostics.forEach(diagnostic -> message.append(diagnostic).append('\n'));
233229
return message.toString();
234230
}
235231

src/test/java/com/google/testing/compile/CompilationSubjectTest.java

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,8 @@ public void succeeded_failureReportsGeneratedFiles() {
9999
.that(compilerWithGeneratorAndError().compile(HELLO_WORLD_RESOURCE))
100100
.succeeded();
101101
AssertionError expected = expectFailure.getFailure();
102-
assertThat(expected.getMessage()).contains("Compilation produced the following errors:\n");
102+
assertThat(expected.getMessage()).contains(
103+
"Compilation produced the following diagnostics:\n");
103104
assertThat(expected.getMessage()).contains(FailingGeneratingProcessor.GENERATED_CLASS_NAME);
104105
assertThat(expected.getMessage()).contains(FailingGeneratingProcessor.GENERATED_SOURCE);
105106
}
@@ -112,7 +113,8 @@ public void succeeded_failureReportsNoGeneratedFiles() {
112113
.that(javac().compile(HELLO_WORLD_BROKEN_RESOURCE))
113114
.succeeded();
114115
AssertionError expected = expectFailure.getFailure();
115-
assertThat(expected.getMessage()).startsWith("Compilation produced the following errors:\n");
116+
assertThat(expected.getMessage()).startsWith(
117+
"Compilation produced the following diagnostics:\n");
116118
assertThat(expected.getMessage()).contains("No files were generated.");
117119
}
118120

@@ -132,6 +134,22 @@ public void succeeded_exceptionCreatedOrPassedThrough() {
132134
}
133135
}
134136

137+
@Test
138+
public void succeeded_failureReportsWarnings() {
139+
expectFailure
140+
.whenTesting()
141+
.about(compilations())
142+
.that(compilerWithWarning().compile(HELLO_WORLD_BROKEN))
143+
.succeeded();
144+
AssertionError expected = expectFailure.getFailure();
145+
assertThat(expected.getMessage())
146+
.startsWith("Compilation produced the following diagnostics:\n");
147+
assertThat(expected.getMessage()).contains("No files were generated.");
148+
// "this is a message" is output by compilerWithWarning() since the source has
149+
// @DiagnosticMessage
150+
assertThat(expected.getMessage()).contains("warning: this is a message");
151+
}
152+
135153
@Test
136154
public void succeededWithoutWarnings() {
137155
assertThat(javac().compile(HELLO_WORLD)).succeededWithoutWarnings();

src/test/java/com/google/testing/compile/JavaSourcesSubjectFactoryTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,7 @@ public void compilesWithoutError_failureReportsFiles() {
337337
.processedWith(new FailingGeneratingProcessor())
338338
.compilesWithoutError();
339339
AssertionError expected = expectFailure.getFailure();
340-
assertThat(expected.getMessage()).contains("Compilation produced the following errors:\n");
340+
assertThat(expected.getMessage()).contains("Compilation produced the following diagnostics:\n");
341341
assertThat(expected.getMessage()).contains(FailingGeneratingProcessor.GENERATED_CLASS_NAME);
342342
assertThat(expected.getMessage()).contains(FailingGeneratingProcessor.GENERATED_SOURCE);
343343
}
@@ -350,7 +350,7 @@ public void compilesWithoutError_throws() {
350350
.that(JavaFileObjects.forResource("HelloWorld-broken.java"))
351351
.compilesWithoutError();
352352
AssertionError expected = expectFailure.getFailure();
353-
assertThat(expected.getMessage()).startsWith("Compilation produced the following errors:\n");
353+
assertThat(expected.getMessage()).startsWith("Compilation produced the following diagnostics:\n");
354354
assertThat(expected.getMessage()).contains("No files were generated.");
355355
}
356356

0 commit comments

Comments
 (0)