Improve unexpected error scanner for compile-fail tests (Closes #1476)

This commit is contained in:
Drew Willcoxon 2012-09-10 23:50:16 -07:00 committed by Brian Anderson
parent dc11e87b84
commit 98bd4a992c
2 changed files with 81 additions and 3 deletions

View File

@ -289,9 +289,9 @@ fn check_expected_errors(expected_errors: ~[errors::expected_error],
was_expected = true;
}
if !was_expected && (str::contains(line, ~"error") ||
str::contains(line, ~"warning")) {
fatal_procres(fmt!("unexpected error pattern '%s'!", line),
if !was_expected && is_compiler_error_or_warning(line) {
fatal_procres(fmt!("unexpected compiler error or warning: '%s'",
line),
procres);
}
}
@ -305,6 +305,81 @@ fn check_expected_errors(expected_errors: ~[errors::expected_error],
}
}
fn is_compiler_error_or_warning(line: ~str) -> bool {
let mut i = 0u;
return
scan_until_char(line, ':', &mut i) &&
scan_char(line, ':', &mut i) &&
scan_integer(line, &mut i) &&
scan_char(line, ':', &mut i) &&
scan_integer(line, &mut i) &&
scan_char(line, ':', &mut i) &&
scan_char(line, ' ', &mut i) &&
scan_integer(line, &mut i) &&
scan_char(line, ':', &mut i) &&
scan_integer(line, &mut i) &&
scan_char(line, ' ', &mut i) &&
(scan_string(line, ~"error", &mut i) ||
scan_string(line, ~"warning", &mut i));
}
fn scan_until_char(haystack: ~str, needle: char, idx: &mut uint) -> bool {
if *idx >= haystack.len() {
return false;
}
let opt = str::find_char_from(haystack, needle, *idx);
if opt.is_none() {
return false;
}
*idx = opt.get();
return true;
}
fn scan_char(haystack: ~str, needle: char, idx: &mut uint) -> bool {
if *idx >= haystack.len() {
return false;
}
let {ch, next} = str::char_range_at(haystack, *idx);
if ch != needle {
return false;
}
*idx = next;
return true;
}
fn scan_integer(haystack: ~str, idx: &mut uint) -> bool {
let mut i = *idx;
while i < haystack.len() {
let {ch, next} = str::char_range_at(haystack, i);
if ch < '0' || '9' < ch {
break;
}
i = next;
}
if i == *idx {
return false;
}
*idx = i;
return true;
}
fn scan_string(haystack: ~str, needle: ~str, idx: &mut uint) -> bool {
let mut haystack_i = *idx;
let mut needle_i = 0u;
while needle_i < needle.len() {
if haystack_i >= haystack.len() {
return false;
}
let {ch, next} = str::char_range_at(haystack, haystack_i);
haystack_i = next;
if !scan_char(needle, ch, &mut needle_i) {
return false;
}
}
*idx = haystack_i;
return true;
}
type procargs = {prog: ~str, args: ~[~str]};
type procres = {status: int, stdout: ~str, stderr: ~str, cmdline: ~str};

View File

@ -0,0 +1,3 @@
fn main() {
log(error, x); //~ ERROR unresolved name: x
}