Skip to content

Commit

Permalink
Improve unexpected error scanner for compile-fail tests (Closes rust-…
Browse files Browse the repository at this point in the history
  • Loading branch information
0c0w3 committed Sep 11, 2012
1 parent cd8ec6d commit d90b481
Show file tree
Hide file tree
Showing 2 changed files with 81 additions and 3 deletions.
81 changes: 78 additions & 3 deletions src/compiletest/runtest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand All @@ -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};
Expand Down
3 changes: 3 additions & 0 deletions src/test/compile-fail/issue-1476.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
fn main() {
log(error, x); //~ ERROR unresolved name: x
}

0 comments on commit d90b481

Please sign in to comment.