2014-05-20 18:15:34 +01:00
|
|
|
// Copyright 2012-2014 The Rust Project Developers. See the COPYRIGHT
|
2012-12-03 16:48:01 -08:00
|
|
|
// 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.
|
|
|
|
|
2014-01-15 13:25:09 -08:00
|
|
|
use std::io::{BufferedReader, File};
|
2014-05-20 18:15:34 +01:00
|
|
|
use regex::Regex;
|
2013-10-25 17:04:37 -07:00
|
|
|
|
2014-03-28 11:10:15 -07:00
|
|
|
pub struct ExpectedError {
|
|
|
|
pub line: uint,
|
2014-05-14 20:47:24 -07:00
|
|
|
pub kind: StrBuf,
|
|
|
|
pub msg: StrBuf,
|
2014-03-28 11:10:15 -07:00
|
|
|
}
|
2012-01-03 21:01:48 -08:00
|
|
|
|
2014-05-20 18:15:34 +01:00
|
|
|
pub static EXPECTED_PATTERN : &'static str = r"//~(?P<adjusts>\^*)\s*(?P<kind>\S*)\s*(?P<msg>.*)";
|
2013-10-06 16:08:56 -07:00
|
|
|
|
2014-05-20 18:15:34 +01:00
|
|
|
// Load any test directives embedded in the file
|
|
|
|
pub fn load_errors(re: &Regex, testfile: &Path) -> Vec<ExpectedError> {
|
2013-10-29 23:31:07 -07:00
|
|
|
let mut rdr = BufferedReader::new(File::open(testfile).unwrap());
|
2012-01-03 21:01:48 -08:00
|
|
|
|
2014-05-20 18:15:34 +01:00
|
|
|
rdr.lines().enumerate().filter_map(|(line_no, ln)| {
|
2014-05-19 23:19:56 -07:00
|
|
|
parse_expected(line_no + 1, ln.unwrap().as_slice(), re)
|
2014-05-20 18:15:34 +01:00
|
|
|
}).collect()
|
|
|
|
}
|
2012-01-03 21:01:48 -08:00
|
|
|
|
2014-05-20 18:15:34 +01:00
|
|
|
fn parse_expected(line_num: uint, line: &str, re: &Regex) -> Option<ExpectedError> {
|
|
|
|
re.captures(line).and_then(|caps| {
|
|
|
|
let adjusts = caps.name("adjusts").len();
|
|
|
|
let kind = caps.name("kind").to_ascii().to_lower().into_str().to_strbuf();
|
|
|
|
let msg = caps.name("msg").trim().to_strbuf();
|
|
|
|
|
|
|
|
debug!("line={} kind={} msg={}", line_num, kind, msg);
|
|
|
|
Some(ExpectedError {
|
|
|
|
line: line_num - adjusts,
|
|
|
|
kind: kind,
|
|
|
|
msg: msg,
|
|
|
|
})
|
|
|
|
})
|
2012-01-03 21:01:48 -08:00
|
|
|
}
|