diff options
Diffstat (limited to 'src/compiletest/errors.rs')
| -rw-r--r-- | src/compiletest/errors.rs | 73 |
1 files changed, 38 insertions, 35 deletions
diff --git a/src/compiletest/errors.rs b/src/compiletest/errors.rs index dcfac688c7f..fc815d66a4d 100644 --- a/src/compiletest/errors.rs +++ b/src/compiletest/errors.rs @@ -9,9 +9,7 @@ // except according to those terms. use self::WhichLine::*; -use std::ascii::AsciiExt; use std::io::{BufferedReader, File}; -use regex::Regex; pub struct ExpectedError { pub line: uint, @@ -19,6 +17,9 @@ pub struct ExpectedError { pub msg: String, } +#[derive(PartialEq, Show)] +enum WhichLine { ThisLine, FollowPrevious(uint), AdjustBackward(uint) } + /// Looks for either "//~| KIND MESSAGE" or "//~^^... KIND MESSAGE" /// The former is a "follow" that inherits its target from the preceding line; /// the latter is an "adjusts" that goes that many lines up. @@ -26,15 +27,8 @@ pub struct ExpectedError { /// Goal is to enable tests both like: //~^^^ ERROR go up three /// and also //~^ ERROR message one for the preceding line, and /// //~| ERROR message two for that same line. - -pub static EXPECTED_PATTERN : &'static str = - r"//~(?P<follow>\|)?(?P<adjusts>\^*)\s*(?P<kind>\S*)\s*(?P<msg>.*)"; - -#[derive(PartialEq, Show)] -enum WhichLine { ThisLine, FollowPrevious(uint), AdjustBackward(uint) } - // Load any test directives embedded in the file -pub fn load_errors(re: &Regex, testfile: &Path) -> Vec<ExpectedError> { +pub fn load_errors(testfile: &Path) -> Vec<ExpectedError> { let mut rdr = BufferedReader::new(File::open(testfile).unwrap()); // `last_nonfollow_error` tracks the most recently seen @@ -50,7 +44,7 @@ pub fn load_errors(re: &Regex, testfile: &Path) -> Vec<ExpectedError> { rdr.lines().enumerate().filter_map(|(line_no, ln)| { parse_expected(last_nonfollow_error, line_no + 1, - ln.unwrap().as_slice(), re) + ln.unwrap().as_slice()) .map(|(which, error)| { match which { FollowPrevious(_) => {} @@ -63,30 +57,39 @@ pub fn load_errors(re: &Regex, testfile: &Path) -> Vec<ExpectedError> { fn parse_expected(last_nonfollow_error: Option<uint>, line_num: uint, - line: &str, - re: &Regex) -> Option<(WhichLine, ExpectedError)> { - re.captures(line).and_then(|caps| { - let adjusts = caps.name("adjusts").unwrap_or("").len(); - let kind = caps.name("kind").unwrap_or("").to_ascii_lowercase(); - let msg = caps.name("msg").unwrap_or("").trim().to_string(); - let follow = caps.name("follow").unwrap_or("").len() > 0; + line: &str) -> Option<(WhichLine, ExpectedError)> { + let start = match line.find_str("//~") { Some(i) => i, None => return None }; + let (follow, adjusts) = if line.char_at(start + 3) == '|' { + (true, 0) + } else { + (false, line[start + 3..].chars().take_while(|c| *c == '^').count()) + }; + let kind_start = start + 3 + adjusts + (follow as usize); + let letters = line[kind_start..].chars(); + let kind = letters.skip_while(|c| c.is_whitespace()) + .take_while(|c| !c.is_whitespace()) + .map(|c| c.to_lowercase()) + .collect::<String>(); + let letters = line[kind_start..].chars(); + let msg = letters.skip_while(|c| c.is_whitespace()) + .skip_while(|c| !c.is_whitespace()) + .collect::<String>().trim().to_string(); - let (which, line) = if follow { - assert!(adjusts == 0, "use either //~| or //~^, not both."); - let line = last_nonfollow_error.unwrap_or_else(|| { - panic!("encountered //~| without preceding //~^ line.") - }); - (FollowPrevious(line), line) - } else { - let which = - if adjusts > 0 { AdjustBackward(adjusts) } else { ThisLine }; - let line = line_num - adjusts; - (which, line) - }; + let (which, line) = if follow { + assert!(adjusts == 0, "use either //~| or //~^, not both."); + let line = last_nonfollow_error.unwrap_or_else(|| { + panic!("encountered //~| without preceding //~^ line.") + }); + (FollowPrevious(line), line) + } else { + let which = + if adjusts > 0 { AdjustBackward(adjusts) } else { ThisLine }; + let line = line_num - adjusts; + (which, line) + }; - debug!("line={} which={:?} kind={:?} msg={:?}", line_num, which, kind, msg); - Some((which, ExpectedError { line: line, - kind: kind, - msg: msg, })) - }) + debug!("line={} which={:?} kind={:?} msg={:?}", line_num, which, kind, msg); + Some((which, ExpectedError { line: line, + kind: kind, + msg: msg, })) } |
