diff options
| author | Corey Farwell <coreyf@rwell.org> | 2016-03-14 10:28:38 -0400 | 
|---|---|---|
| committer | Corey Farwell <coreyf@rwell.org> | 2016-03-18 19:04:29 -0400 | 
| commit | 985cddf518a05446f80be3b4febc20c6653f5554 (patch) | |
| tree | b1536306c02eee7eaee55f01090902c83de7acb3 /src/compiletest/errors.rs | |
| parent | 2de6ddd75e202acdedfcd05b51a863dcc10459ca (diff) | |
| download | rust-985cddf518a05446f80be3b4febc20c6653f5554.tar.gz rust-985cddf518a05446f80be3b4febc20c6653f5554.zip | |
Use enum for message kind in compiletest harness.
Diffstat (limited to 'src/compiletest/errors.rs')
| -rw-r--r-- | src/compiletest/errors.rs | 47 | 
1 files changed, 44 insertions, 3 deletions
| diff --git a/src/compiletest/errors.rs b/src/compiletest/errors.rs index c1fbfcda475..0a7784ccc00 100644 --- a/src/compiletest/errors.rs +++ b/src/compiletest/errors.rs @@ -9,14 +9,54 @@ // except according to those terms. use self::WhichLine::*; +use std::fmt; use std::fs::File; use std::io::BufReader; use std::io::prelude::*; use std::path::Path; +use std::str::FromStr; + +#[derive(Clone, Debug, PartialEq)] +pub enum ErrorKind { + Help, + Error, + Note, + Suggestion, + Warning, +} + +impl FromStr for ErrorKind { + type Err = (); + fn from_str(s: &str) -> Result<Self, Self::Err> { + match &s.trim_right_matches(':') as &str { + "HELP" => Ok(ErrorKind::Help), + "ERROR" => Ok(ErrorKind::Error), + "NOTE" => Ok(ErrorKind::Note), + "SUGGESTION" => Ok(ErrorKind::Suggestion), + "WARN" => Ok(ErrorKind::Warning), + "WARNING" => Ok(ErrorKind::Warning), + _ => Err(()), + } + } +} + +impl fmt::Display for ErrorKind { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + match *self { + ErrorKind::Help => write!(f, "help"), + ErrorKind::Error => write!(f, "error"), + ErrorKind::Note => write!(f, "note"), + ErrorKind::Suggestion => write!(f, "suggestion"), + ErrorKind::Warning => write!(f, "warning"), + } + } +} pub struct ExpectedError { pub line_num: usize, - pub kind: String, + /// What kind of message we expect (e.g. warning, error, suggestion). + /// `None` if not specified or unknown message kind. + pub kind: Option<ErrorKind>, pub msg: String, } @@ -84,8 +124,9 @@ fn parse_expected(last_nonfollow_error: Option<usize>, let letters = line[kind_start..].chars(); let kind = letters.skip_while(|c| c.is_whitespace()) .take_while(|c| !c.is_whitespace()) - .flat_map(|c| c.to_lowercase()) - .collect::<String>(); + .collect::<String>() + .parse::<ErrorKind>() + .ok(); let letters = line[kind_start..].chars(); let msg = letters.skip_while(|c| c.is_whitespace()) .skip_while(|c| !c.is_whitespace()) | 
