File tree Expand file tree Collapse file tree 2 files changed +25
-3
lines changed
main/java/com/google/testing/compile
test/java/com/google/testing/compile Expand file tree Collapse file tree 2 files changed +25
-3
lines changed Original file line number Diff line number Diff line change @@ -183,11 +183,18 @@ private void checkDiagnosticCount(
183183 }
184184
185185 private static String messageListing (
186- Iterable <? extends Diagnostic <?>> diagnostics , String headingFormat , Object ... formatArgs ) {
186+ Iterable <? extends Diagnostic <? extends JavaFileObject >> diagnostics ,
187+ String headingFormat ,
188+ Object ... formatArgs ) {
187189 StringBuilder listing =
188190 new StringBuilder (String .format (headingFormat , formatArgs )).append ('\n' );
189- for (Diagnostic <?> diagnostic : diagnostics ) {
190- listing .append (diagnostic .getMessage (null )).append ('\n' );
191+ for (Diagnostic <? extends JavaFileObject > diagnostic : diagnostics ) {
192+ listing .append (
193+ String .format (
194+ "%s: %d - %s\n " ,
195+ diagnostic .getSource ().getName (),
196+ diagnostic .getLineNumber (),
197+ diagnostic .getMessage (null )));
191198 }
192199 return listing .toString ();
193200 }
Original file line number Diff line number Diff line change @@ -415,6 +415,21 @@ public void hadWarningCount() {
415415 assertThat (compilerWithWarning ().compile (sourceFile )).hadWarningCount (2 );
416416 }
417417
418+ @ Test
419+ public void hadWarningCountReportsLineNumbers () {
420+ expectFailure
421+ .whenTesting ()
422+ .about (compilations ())
423+ .that (compilerWithWarning ().compile (sourceFile ))
424+ .hadWarningCount (0 );
425+ AssertionError expected = expectFailure .getFailure ();
426+
427+ assertThat (expected .getMessage ())
428+ .contains (String .format ("%s: 6 - this is a message" , sourceFile .getName ()));
429+ assertThat (expected .getMessage ())
430+ .contains (String .format ("%s: 7 - this is a message" , sourceFile .getName ()));
431+ }
432+
418433 @ Test
419434 public void hadWarningCount_wrongCount () {
420435 expectFailure
You can’t perform that action at this time.
0 commit comments