1 // Copyright 2012 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
11 use std::io::{BufferedReader, File};
14 pub struct ExpectedError { line: uint, kind: ~str, msg: ~str }
16 // Load any test directives embedded in the file
17 pub fn load_errors(testfile: &Path) -> Vec<ExpectedError> {
19 let mut error_patterns = Vec::new();
20 let mut rdr = BufferedReader::new(File::open(testfile).unwrap());
21 let mut line_num = 1u;
22 for ln in rdr.lines() {
23 error_patterns.push_all_move(parse_expected(line_num, ln.unwrap()));
26 return error_patterns;
29 fn parse_expected(line_num: uint, line: ~str) -> Vec<ExpectedError> {
30 let line = line.trim();
31 let error_tag = ~"//~";
33 match line.find_str(error_tag) {
34 None => return Vec::new(),
35 Some(nn) => { idx = (nn as uint) + error_tag.len(); }
38 // "//~^^^ kind msg" denotes a message expected
39 // three lines above current line:
40 let mut adjust_line = 0u;
42 while idx < len && line[idx] == ('^' as u8) {
48 while idx < len && line[idx] == (' ' as u8) { idx += 1u; }
50 while idx < len && line[idx] != (' ' as u8) { idx += 1u; }
52 let kind = line.slice(start_kind, idx);
53 let kind = kind.to_ascii().to_lower().into_str();
56 while idx < len && line[idx] == (' ' as u8) { idx += 1u; }
57 let msg = line.slice(idx, len).to_owned();
59 debug!("line={} kind={} msg={}", line_num - adjust_line, kind, msg);
61 return vec!(ExpectedError{line: line_num - adjust_line, kind: kind,