2012-01-11 08:15:54 -06:00
|
|
|
import io::reader_util;
|
2012-01-03 23:01:48 -06:00
|
|
|
|
|
|
|
import common::config;
|
|
|
|
|
|
|
|
export load_errors;
|
|
|
|
export expected_error;
|
|
|
|
|
2012-07-14 00:57:48 -05:00
|
|
|
type expected_error = { line: uint, kind: ~str, msg: ~str };
|
2012-01-03 23:01:48 -06:00
|
|
|
|
|
|
|
// Load any test directives embedded in the file
|
2012-07-14 00:57:48 -05:00
|
|
|
fn load_errors(testfile: ~str) -> ~[expected_error] {
|
2012-06-29 18:26:56 -05:00
|
|
|
let mut error_patterns = ~[];
|
2012-01-03 23:01:48 -06:00
|
|
|
let rdr = result::get(io::file_reader(testfile));
|
2012-03-22 10:39:41 -05:00
|
|
|
let mut line_num = 1u;
|
2012-01-03 23:01:48 -06:00
|
|
|
while !rdr.eof() {
|
|
|
|
let ln = rdr.read_line();
|
|
|
|
error_patterns += parse_expected(line_num, ln);
|
|
|
|
line_num += 1u;
|
|
|
|
}
|
|
|
|
ret error_patterns;
|
|
|
|
}
|
|
|
|
|
2012-07-14 00:57:48 -05:00
|
|
|
fn parse_expected(line_num: uint, line: ~str) -> ~[expected_error] unsafe {
|
|
|
|
let error_tag = ~"//~";
|
2012-03-22 10:39:41 -05:00
|
|
|
let mut idx;
|
2012-02-23 09:59:30 -06:00
|
|
|
alt str::find_str(line, error_tag) {
|
2012-06-29 18:26:56 -05:00
|
|
|
option::none { ret ~[]; }
|
2012-02-23 03:44:04 -06:00
|
|
|
option::some(nn) { idx = (nn as uint) + str::len(error_tag); }
|
2012-02-13 00:00:56 -06:00
|
|
|
}
|
2012-01-03 23:01:48 -06:00
|
|
|
|
2012-06-30 06:23:59 -05:00
|
|
|
// "//~^^^ kind msg" denotes a message expected
|
2012-01-03 23:01:48 -06:00
|
|
|
// three lines above current line:
|
2012-03-22 10:39:41 -05:00
|
|
|
let mut adjust_line = 0u;
|
2012-02-23 03:44:04 -06:00
|
|
|
let len = str::len(line);
|
2012-01-03 23:01:48 -06:00
|
|
|
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; }
|
2012-02-23 02:45:25 -06:00
|
|
|
let kind = str::to_lower(str::slice(line, start_kind, idx));
|
2012-01-03 23:01:48 -06:00
|
|
|
|
|
|
|
// Extract msg:
|
|
|
|
while idx < len && line[idx] == (' ' as u8) { idx += 1u; }
|
2012-02-23 02:45:25 -06:00
|
|
|
let msg = str::slice(line, idx, len);
|
2012-01-03 23:01:48 -06:00
|
|
|
|
2012-07-30 18:01:07 -05:00
|
|
|
debug!{"line=%u kind=%s msg=%s", line_num - adjust_line, kind, msg};
|
2012-01-03 23:01:48 -06:00
|
|
|
|
2012-06-29 18:26:56 -05:00
|
|
|
ret ~[{line: line_num - adjust_line, kind: kind, msg: msg}];
|
2012-01-03 23:01:48 -06:00
|
|
|
}
|