Skip to content

Commit 722723d

Browse files
committed
Expect all help/note messages are specified in a cfail test if it contains help/note annotations,
closes #21195
1 parent dd51c3a commit 722723d

File tree

1 file changed

+15
-6
lines changed

1 file changed

+15
-6
lines changed

src/compiletest/runtest.rs

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -927,6 +927,13 @@ fn check_expected_errors(expected_errors: Vec<errors::ExpectedError>,
927927
format!("{}:{}:", testfile.display(), ee.line)
928928
}).collect::<Vec<String>>();
929929

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

993-
if !was_expected && is_compiler_error_or_warning(line) {
994-
fatal_proc_rec(&format!("unexpected compiler error or warning: '{}'",
1000+
if !was_expected && is_unexpected_compiler_message(line, expect_help, expect_note) {
1001+
fatal_proc_rec(&format!("unexpected compiler message: '{}'",
9951002
line),
9961003
proc_res);
9971004
}
@@ -1007,16 +1014,15 @@ fn check_expected_errors(expected_errors: Vec<errors::ExpectedError>,
10071014
}
10081015
}
10091016

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

10171024
let mut i = 0;
1018-
return
1019-
scan_until_char(line, ':', &mut i) &&
1025+
return scan_until_char(line, ':', &mut i) &&
10201026
scan_char(line, ':', &mut i) &&
10211027
scan_integer(line, &mut i) &&
10221028
scan_char(line, ':', &mut i) &&
@@ -1028,7 +1034,10 @@ fn is_compiler_error_or_warning(line: &str) -> bool {
10281034
scan_integer(line, &mut i) &&
10291035
scan_char(line, ' ', &mut i) &&
10301036
(scan_string(line, "error", &mut i) ||
1031-
scan_string(line, "warning", &mut i));
1037+
scan_string(line, "warning", &mut i) ||
1038+
(expect_help && scan_string(line, "help", &mut i)) ||
1039+
(expect_note && scan_string(line, "note", &mut i))
1040+
);
10321041
}
10331042

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

0 commit comments

Comments
 (0)