Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
}