Skip to content

Commit 510e272

Browse files
committed
compiletest: Improve diagnostics for line annotation mismatches 2
1 parent 3fb1b53 commit 510e272

File tree

1 file changed

+18
-19
lines changed

1 file changed

+18
-19
lines changed

src/tools/compiletest/src/runtest.rs

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -765,12 +765,6 @@ impl<'test> TestCx<'test> {
765765
}
766766

767767
if !unexpected.is_empty() || !not_found.is_empty() {
768-
self.error(&format!(
769-
"{} unexpected diagnostics reported, {} expected diagnostics not reported",
770-
unexpected.len(),
771-
not_found.len()
772-
));
773-
774768
// Emit locations in a format that is short (relative paths) but "clickable" in editors.
775769
// Also normalize path separators to `/`.
776770
let file_name = self
@@ -794,19 +788,20 @@ impl<'test> TestCx<'test> {
794788
|suggestions: &mut Vec<_>, e: &Error, kind, line, msg, color, rank| {
795789
let mut ret = String::new();
796790
if kind {
797-
ret += &format!("{} {}", "with kind".color(color), e.kind);
791+
ret += &format!("{} {}", "with different kind".color(color), e.kind);
798792
}
799793
if line {
800794
if !ret.is_empty() {
801795
ret.push(' ');
802796
}
803-
ret += &format!("{} {}", "on line".color(color), line_str(e));
797+
ret += &format!("{} {}", "on different line".color(color), line_str(e));
804798
}
805799
if msg {
806800
if !ret.is_empty() {
807801
ret.push(' ');
808802
}
809-
ret += &format!("{} {}", "with message".color(color), e.msg.cyan());
803+
ret +=
804+
&format!("{} {}", "with different message".color(color), e.msg.cyan());
810805
}
811806
suggestions.push((ret, rank));
812807
};
@@ -829,17 +824,20 @@ impl<'test> TestCx<'test> {
829824
// - only known line - meh, but suggested
830825
// - others are not worth suggesting
831826
if !unexpected.is_empty() {
832-
let header = "--- reported in JSON output but not expected in test file ---";
833-
println!("{}", header.green());
827+
self.error(&format!(
828+
"{} diagnostics reported in JSON output but not expected in test file",
829+
unexpected.len(),
830+
));
834831
for error in &unexpected {
835832
print_error(error);
836833
let mut suggestions = Vec::new();
837834
for candidate in &not_found {
835+
let kind_mismatch = candidate.kind != error.kind;
838836
let mut push_red_suggestion = |line, msg, rank| {
839837
push_suggestion(
840838
&mut suggestions,
841839
candidate,
842-
candidate.kind != error.kind,
840+
kind_mismatch,
843841
line,
844842
msg,
845843
Color::Red,
@@ -851,26 +849,28 @@ impl<'test> TestCx<'test> {
851849
} else if candidate.line_num.is_some()
852850
&& candidate.line_num == error.line_num
853851
{
854-
push_red_suggestion(false, true, 1);
852+
push_red_suggestion(false, true, if kind_mismatch { 2 } else { 1 });
855853
}
856854
}
857855

858856
show_suggestions(suggestions, "expected", Color::Red);
859857
}
860-
println!("{}", "---".green());
861858
}
862859
if !not_found.is_empty() {
863-
let header = "--- expected in test file but not reported in JSON output ---";
864-
println!("{}", header.red());
860+
self.error(&format!(
861+
"{} diagnostics expected in test file but not reported in JSON output",
862+
not_found.len()
863+
));
865864
for error in &not_found {
866865
print_error(error);
867866
let mut suggestions = Vec::new();
868867
for candidate in unexpected.iter().chain(&unimportant) {
868+
let kind_mismatch = candidate.kind != error.kind;
869869
let mut push_green_suggestion = |line, msg, rank| {
870870
push_suggestion(
871871
&mut suggestions,
872872
candidate,
873-
candidate.kind != error.kind,
873+
kind_mismatch,
874874
line,
875875
msg,
876876
Color::Green,
@@ -882,13 +882,12 @@ impl<'test> TestCx<'test> {
882882
} else if candidate.line_num.is_some()
883883
&& candidate.line_num == error.line_num
884884
{
885-
push_green_suggestion(false, true, 1);
885+
push_green_suggestion(false, true, if kind_mismatch { 2 } else { 1 });
886886
}
887887
}
888888

889889
show_suggestions(suggestions, "reported", Color::Green);
890890
}
891-
println!("{}", "---".red());
892891
}
893892
panic!(
894893
"errors differ from expected\nstatus: {}\ncommand: {}\n",

0 commit comments

Comments
 (0)