Skip to content

Commit 36656f8

Browse files
committed
Expect all help/note messages are specified in a cfail test if it contains help/note annotations,
closes #21195
1 parent 0f196bc commit 36656f8

File tree

1 file changed

+15
-6
lines changed

1 file changed

+15
-6
lines changed

src/compiletest/runtest.rs

+15-6
Original file line numberDiff line numberDiff line change
@@ -929,6 +929,13 @@ fn check_expected_errors(expected_errors: Vec<errors::ExpectedError>,
929929
format!("{}:{}:", testfile.display(), ee.line)
930930
}).collect::<Vec<String>>();
931931

932+
let (expect_help, expect_note) =
933+
expected_errors.iter()
934+
.fold((false, false),
935+
|(acc_help, acc_note), ee|
936+
(acc_help || ee.kind == "help:", acc_note ||
937+
ee.kind == "note:"));
938+
932939
fn prefix_matches(line: &str, prefix: &str) -> bool {
933940
use std::ascii::AsciiExt;
934941
// On windows just translate all '\' path separators to '/'
@@ -992,8 +999,8 @@ fn check_expected_errors(expected_errors: Vec<errors::ExpectedError>,
992999
was_expected = true;
9931000
}
9941001

995-
if !was_expected && is_compiler_error_or_warning(line) {
996-
fatal_proc_rec(&format!("unexpected compiler error or warning: '{}'",
1002+
if !was_expected && is_unexpected_compiler_message(line, expect_help, expect_note) {
1003+
fatal_proc_rec(&format!("unexpected compiler message: '{}'",
9971004
line),
9981005
proc_res);
9991006
}
@@ -1009,16 +1016,15 @@ fn check_expected_errors(expected_errors: Vec<errors::ExpectedError>,
10091016
}
10101017
}
10111018

1012-
fn is_compiler_error_or_warning(line: &str) -> bool {
1019+
fn is_unexpected_compiler_message(line: &str, expect_help: bool, expect_note: bool) -> bool {
10131020
let mut c = Path::new(line).components();
10141021
let line = match c.next() {
10151022
Some(Component::Prefix(_)) => c.as_path().to_str().unwrap(),
10161023
_ => line,
10171024
};
10181025

10191026
let mut i = 0;
1020-
return
1021-
scan_until_char(line, ':', &mut i) &&
1027+
return scan_until_char(line, ':', &mut i) &&
10221028
scan_char(line, ':', &mut i) &&
10231029
scan_integer(line, &mut i) &&
10241030
scan_char(line, ':', &mut i) &&
@@ -1030,7 +1036,10 @@ fn is_compiler_error_or_warning(line: &str) -> bool {
10301036
scan_integer(line, &mut i) &&
10311037
scan_char(line, ' ', &mut i) &&
10321038
(scan_string(line, "error", &mut i) ||
1033-
scan_string(line, "warning", &mut i));
1039+
scan_string(line, "warning", &mut i) ||
1040+
(expect_help && scan_string(line, "help", &mut i)) ||
1041+
(expect_note && scan_string(line, "note", &mut i))
1042+
);
10341043
}
10351044

10361045
fn scan_until_char(haystack: &str, needle: char, idx: &mut usize) -> bool {

0 commit comments

Comments
 (0)