rust/src/compiletest/errors.rs

53 lines
1.5 KiB
Rust
Raw Normal View History

use common::config;
use io::ReaderUtil;
export load_errors;
export expected_error;
type expected_error = { line: uint, kind: ~str, msg: ~str };
// Load any test directives embedded in the file
fn load_errors(testfile: &Path) -> ~[expected_error] {
let mut error_patterns = ~[];
2012-09-25 18:23:04 -05:00
let rdr = io::file_reader(testfile).get();
let mut line_num = 1u;
while !rdr.eof() {
let ln = rdr.read_line();
error_patterns += parse_expected(line_num, ln);
line_num += 1u;
}
2012-08-01 19:30:05 -05:00
return error_patterns;
}
fn parse_expected(line_num: uint, line: ~str) -> ~[expected_error] unsafe {
let error_tag = ~"//~";
let mut idx;
2012-08-06 14:34:08 -05:00
match str::find_str(line, error_tag) {
2012-08-20 14:23:37 -05:00
option::None => return ~[],
option::Some(nn) => { idx = (nn as uint) + str::len(error_tag); }
}
// "//~^^^ kind msg" denotes a message expected
// three lines above current line:
let mut adjust_line = 0u;
2012-02-23 03:44:04 -06:00
let len = str::len(line);
while idx < len && line[idx] == ('^' as u8) {
adjust_line += 1u;
idx += 1u;
}
// Extract kind:
while idx < len && line[idx] == (' ' as u8) { idx += 1u; }
let start_kind = idx;
while idx < len && line[idx] != (' ' as u8) { idx += 1u; }
let kind = str::to_lower(str::slice(line, start_kind, idx));
// Extract msg:
while idx < len && line[idx] == (' ' as u8) { idx += 1u; }
let msg = str::slice(line, idx, len);
2012-08-22 19:24:52 -05:00
debug!("line=%u kind=%s msg=%s", line_num - adjust_line, kind, msg);
2012-08-01 19:30:05 -05:00
return ~[{line: line_num - adjust_line, kind: kind, msg: msg}];
}