about summary refs log tree commit diff
path: root/src/compiletest/errors.rs
diff options
context:
space:
mode:
authorBrian Anderson <banderson@mozilla.com>2015-01-24 09:15:42 -0800
committerBrian Anderson <banderson@mozilla.com>2015-01-25 01:20:55 -0800
commit63fcbcf3ce8f0ca391c18b2d61833ae6beb3ac70 (patch)
treec732033c0822f25f2aebcdf193de1b257bac1855 /src/compiletest/errors.rs
parentb44ee371b8beea77aa1364460acbba14a8516559 (diff)
parent0430a43d635841db44978bb648e9cf7e7cfa1bba (diff)
downloadrust-63fcbcf3ce8f0ca391c18b2d61833ae6beb3ac70.tar.gz
rust-63fcbcf3ce8f0ca391c18b2d61833ae6beb3ac70.zip
Merge remote-tracking branch 'rust-lang/master'
Conflicts:
	mk/tests.mk
	src/liballoc/arc.rs
	src/liballoc/boxed.rs
	src/liballoc/rc.rs
	src/libcollections/bit.rs
	src/libcollections/btree/map.rs
	src/libcollections/btree/set.rs
	src/libcollections/dlist.rs
	src/libcollections/ring_buf.rs
	src/libcollections/slice.rs
	src/libcollections/str.rs
	src/libcollections/string.rs
	src/libcollections/vec.rs
	src/libcollections/vec_map.rs
	src/libcore/any.rs
	src/libcore/array.rs
	src/libcore/borrow.rs
	src/libcore/error.rs
	src/libcore/fmt/mod.rs
	src/libcore/iter.rs
	src/libcore/marker.rs
	src/libcore/ops.rs
	src/libcore/result.rs
	src/libcore/slice.rs
	src/libcore/str/mod.rs
	src/libregex/lib.rs
	src/libregex/re.rs
	src/librustc/lint/builtin.rs
	src/libstd/collections/hash/map.rs
	src/libstd/collections/hash/set.rs
	src/libstd/sync/mpsc/mod.rs
	src/libstd/sync/mutex.rs
	src/libstd/sync/poison.rs
	src/libstd/sync/rwlock.rs
	src/libsyntax/feature_gate.rs
	src/libsyntax/test.rs
Diffstat (limited to 'src/compiletest/errors.rs')
-rw-r--r--src/compiletest/errors.rs73
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, }))
 }