]> git.lizzy.rs Git - rust.git/blob - src/compiletest/errors.rs
test: Make manual changes to deal with the fallout from removal of
[rust.git] / src / compiletest / errors.rs
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.
4 //
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.
10
11 use std::io::{BufferedReader, File};
12 use std::vec_ng::Vec;
13
14 pub struct ExpectedError { line: uint, kind: ~str, msg: ~str }
15
16 // Load any test directives embedded in the file
17 pub fn load_errors(testfile: &Path) -> Vec<ExpectedError> {
18
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()));
24         line_num += 1u;
25     }
26     return error_patterns;
27 }
28
29 fn parse_expected(line_num: uint, line: ~str) -> Vec<ExpectedError> {
30     let line = line.trim();
31     let error_tag = ~"//~";
32     let mut idx;
33     match line.find_str(error_tag) {
34       None => return Vec::new(),
35       Some(nn) => { idx = (nn as uint) + error_tag.len(); }
36     }
37
38     // "//~^^^ kind msg" denotes a message expected
39     // three lines above current line:
40     let mut adjust_line = 0u;
41     let len = line.len();
42     while idx < len && line[idx] == ('^' as u8) {
43         adjust_line += 1u;
44         idx += 1u;
45     }
46
47     // Extract kind:
48     while idx < len && line[idx] == (' ' as u8) { idx += 1u; }
49     let start_kind = idx;
50     while idx < len && line[idx] != (' ' as u8) { idx += 1u; }
51
52     let kind = line.slice(start_kind, idx);
53     let kind = kind.to_ascii().to_lower().into_str();
54
55     // Extract msg:
56     while idx < len && line[idx] == (' ' as u8) { idx += 1u; }
57     let msg = line.slice(idx, len).to_owned();
58
59     debug!("line={} kind={} msg={}", line_num - adjust_line, kind, msg);
60
61     return vec!(ExpectedError{line: line_num - adjust_line, kind: kind,
62                            msg: msg});
63 }