2012-12-03 18:48:01 -06:00
|
|
|
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
|
|
|
|
// file at the top-level directory of this distribution and at
|
|
|
|
// http://rust-lang.org/COPYRIGHT.
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
|
|
|
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
|
|
|
// option. This file may not be copied, modified, or distributed
|
|
|
|
// except according to those terms.
|
|
|
|
|
2013-11-11 00:46:32 -06:00
|
|
|
use std::io::buffered::BufferedReader;
|
|
|
|
use std::io::File;
|
2013-10-25 19:04:37 -05:00
|
|
|
|
2013-01-30 16:10:03 -06:00
|
|
|
pub struct ExpectedError { line: uint, kind: ~str, msg: ~str }
|
2012-01-03 23:01:48 -06:00
|
|
|
|
|
|
|
// Load any test directives embedded in the file
|
2013-01-30 16:10:03 -06:00
|
|
|
pub fn load_errors(testfile: &Path) -> ~[ExpectedError] {
|
2013-10-06 18:08:56 -05:00
|
|
|
|
2012-06-29 18:26:56 -05:00
|
|
|
let mut error_patterns = ~[];
|
2013-10-30 01:31:07 -05:00
|
|
|
let mut rdr = BufferedReader::new(File::open(testfile).unwrap());
|
2012-03-22 10:39:41 -05:00
|
|
|
let mut line_num = 1u;
|
2013-12-08 01:12:07 -06:00
|
|
|
for ln in rdr.lines() {
|
2013-06-11 21:13:42 -05:00
|
|
|
error_patterns.push_all_move(parse_expected(line_num, ln));
|
2012-01-03 23:01:48 -06:00
|
|
|
line_num += 1u;
|
|
|
|
}
|
2012-08-01 19:30:05 -05:00
|
|
|
return error_patterns;
|
2012-01-03 23:01:48 -06:00
|
|
|
}
|
|
|
|
|
2013-01-26 00:51:32 -06:00
|
|
|
fn parse_expected(line_num: uint, line: ~str) -> ~[ExpectedError] {
|
2013-10-06 15:24:50 -05:00
|
|
|
let line = line.trim();
|
2013-04-09 01:08:16 -05:00
|
|
|
let error_tag = ~"//~";
|
|
|
|
let mut idx;
|
2013-06-10 01:23:05 -05:00
|
|
|
match line.find_str(error_tag) {
|
2013-04-09 01:08:16 -05:00
|
|
|
None => return ~[],
|
2013-06-09 09:44:58 -05:00
|
|
|
Some(nn) => { idx = (nn as uint) + error_tag.len(); }
|
2013-04-09 01:08:16 -05:00
|
|
|
}
|
2012-01-03 23:01:48 -06:00
|
|
|
|
2013-04-09 01:08:16 -05:00
|
|
|
// "//~^^^ kind msg" denotes a message expected
|
|
|
|
// three lines above current line:
|
|
|
|
let mut adjust_line = 0u;
|
2013-06-09 09:44:58 -05:00
|
|
|
let len = line.len();
|
2013-04-09 01:08:16 -05:00
|
|
|
while idx < len && line[idx] == ('^' as u8) {
|
|
|
|
adjust_line += 1u;
|
|
|
|
idx += 1u;
|
|
|
|
}
|
2012-01-03 23:01:48 -06:00
|
|
|
|
2013-04-09 01:08:16 -05:00
|
|
|
// Extract kind:
|
|
|
|
while idx < len && line[idx] == (' ' as u8) { idx += 1u; }
|
|
|
|
let start_kind = idx;
|
|
|
|
while idx < len && line[idx] != (' ' as u8) { idx += 1u; }
|
2013-04-23 04:08:13 -05:00
|
|
|
|
2013-06-09 09:44:58 -05:00
|
|
|
let kind = line.slice(start_kind, idx);
|
2013-11-07 01:59:40 -06:00
|
|
|
let kind = kind.to_ascii().to_lower().into_str();
|
2012-01-03 23:01:48 -06:00
|
|
|
|
2013-04-09 01:08:16 -05:00
|
|
|
// Extract msg:
|
|
|
|
while idx < len && line[idx] == (' ' as u8) { idx += 1u; }
|
2013-06-09 09:44:58 -05:00
|
|
|
let msg = line.slice(idx, len).to_owned();
|
2012-01-03 23:01:48 -06:00
|
|
|
|
2013-10-21 15:08:31 -05:00
|
|
|
debug!("line={} kind={} msg={}", line_num - adjust_line, kind, msg);
|
2012-01-03 23:01:48 -06:00
|
|
|
|
2013-04-09 01:08:16 -05:00
|
|
|
return ~[ExpectedError{line: line_num - adjust_line, kind: kind,
|
|
|
|
msg: msg}];
|
2012-01-03 23:01:48 -06:00
|
|
|
}
|