2013-02-09 12:09:19 -06:00
|
|
|
// Copyright 2012-2013 The Rust Project Developers. See the
|
|
|
|
// COPYRIGHT file at the top-level directory of this distribution and at
|
2012-12-03 18:48:01 -06:00
|
|
|
// http://rust-lang.org/COPYRIGHT.
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
|
|
|
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
|
|
|
// option. This file may not be copied, modified, or distributed
|
|
|
|
// except according to those terms.
|
|
|
|
|
2013-01-08 21:37:25 -06:00
|
|
|
use core::prelude::*;
|
|
|
|
|
2012-12-28 10:50:27 -06:00
|
|
|
use common;
|
2012-09-07 20:08:21 -05:00
|
|
|
use common::config;
|
2013-03-01 12:44:43 -06:00
|
|
|
|
|
|
|
use core::io::ReaderUtil;
|
|
|
|
use core::io;
|
|
|
|
use core::os;
|
|
|
|
use core::str;
|
2011-08-01 13:23:58 -05:00
|
|
|
|
2013-01-30 16:10:03 -06:00
|
|
|
pub struct TestProps {
|
2011-08-01 16:10:59 -05:00
|
|
|
// Lines that should be expected, in order, on standard out
|
2012-07-14 00:57:48 -05:00
|
|
|
error_patterns: ~[~str],
|
2011-08-01 16:10:59 -05:00
|
|
|
// Extra flags to pass to the compiler
|
2012-08-20 14:23:37 -05:00
|
|
|
compile_flags: Option<~str>,
|
2011-08-01 16:10:59 -05:00
|
|
|
// If present, the name of a file that this test should match when
|
|
|
|
// pretty-printed
|
2012-08-20 14:23:37 -05:00
|
|
|
pp_exact: Option<Path>,
|
2012-02-27 23:23:49 -06:00
|
|
|
// Modules from aux directory that should be compiled
|
2012-07-14 00:57:48 -05:00
|
|
|
aux_builds: ~[~str],
|
2012-04-13 11:19:07 -05:00
|
|
|
// Environment settings to use during execution
|
2013-02-09 12:09:19 -06:00
|
|
|
exec_env: ~[(~str,~str)],
|
|
|
|
// Commands to be given to the debugger, when testing debug info
|
|
|
|
debugger_cmds: ~[~str],
|
|
|
|
// Lines to check if they appear in the expected debugger output
|
|
|
|
check_lines: ~[~str],
|
2013-01-26 00:51:32 -06:00
|
|
|
}
|
2011-07-30 23:11:14 -05:00
|
|
|
|
|
|
|
// Load any test directives embedded in the file
|
2013-01-30 16:10:03 -06:00
|
|
|
pub fn load_props(testfile: &Path) -> TestProps {
|
2012-06-29 18:26:56 -05:00
|
|
|
let mut error_patterns = ~[];
|
|
|
|
let mut aux_builds = ~[];
|
|
|
|
let mut exec_env = ~[];
|
2012-12-28 10:28:36 -06:00
|
|
|
let mut compile_flags = None;
|
|
|
|
let mut pp_exact = None;
|
2013-02-09 12:09:19 -06:00
|
|
|
let mut debugger_cmds = ~[];
|
|
|
|
let mut check_lines = ~[];
|
2012-06-30 18:19:07 -05:00
|
|
|
for iter_header(testfile) |ln| {
|
2012-08-06 14:34:08 -05:00
|
|
|
match parse_error_pattern(ln) {
|
2012-12-28 10:28:36 -06:00
|
|
|
Some(ep) => error_patterns.push(ep),
|
|
|
|
None => ()
|
2011-10-21 06:14:28 -05:00
|
|
|
};
|
2011-07-30 23:11:14 -05:00
|
|
|
|
2012-09-21 21:37:57 -05:00
|
|
|
if compile_flags.is_none() {
|
2011-07-30 23:11:14 -05:00
|
|
|
compile_flags = parse_compile_flags(ln);
|
|
|
|
}
|
2011-08-01 16:10:59 -05:00
|
|
|
|
2012-09-21 21:37:57 -05:00
|
|
|
if pp_exact.is_none() {
|
2011-08-01 16:10:59 -05:00
|
|
|
pp_exact = parse_pp_exact(ln, testfile);
|
|
|
|
}
|
2012-02-27 23:23:49 -06:00
|
|
|
|
2013-03-03 06:33:39 -06:00
|
|
|
for parse_aux_build(ln).each |ab| {
|
2012-09-27 19:01:28 -05:00
|
|
|
aux_builds.push(*ab);
|
2012-02-27 23:23:49 -06:00
|
|
|
}
|
2012-04-13 11:19:07 -05:00
|
|
|
|
2013-03-03 06:33:39 -06:00
|
|
|
for parse_exec_env(ln).each |ee| {
|
2012-09-27 19:01:28 -05:00
|
|
|
exec_env.push(*ee);
|
2012-04-13 11:19:07 -05:00
|
|
|
}
|
2013-02-09 12:09:19 -06:00
|
|
|
|
|
|
|
match parse_debugger_cmd(ln) {
|
|
|
|
Some(dc) => debugger_cmds.push(dc),
|
|
|
|
None => ()
|
|
|
|
};
|
|
|
|
|
|
|
|
match parse_check_line(ln) {
|
|
|
|
Some(cl) => check_lines.push(cl),
|
|
|
|
None => ()
|
|
|
|
};
|
2011-10-21 06:14:28 -05:00
|
|
|
};
|
2013-01-26 00:51:32 -06:00
|
|
|
return TestProps {
|
2011-08-01 16:10:59 -05:00
|
|
|
error_patterns: error_patterns,
|
|
|
|
compile_flags: compile_flags,
|
2012-02-27 23:23:49 -06:00
|
|
|
pp_exact: pp_exact,
|
2012-04-13 11:19:07 -05:00
|
|
|
aux_builds: aux_builds,
|
2013-02-09 12:09:19 -06:00
|
|
|
exec_env: exec_env,
|
|
|
|
debugger_cmds: debugger_cmds,
|
|
|
|
check_lines: check_lines
|
2011-08-01 16:10:59 -05:00
|
|
|
};
|
2011-07-30 23:11:14 -05:00
|
|
|
}
|
|
|
|
|
2013-01-30 16:10:03 -06:00
|
|
|
pub fn is_test_ignored(config: config, testfile: &Path) -> bool {
|
2012-03-22 10:39:41 -05:00
|
|
|
let mut found = false;
|
2012-06-30 18:19:07 -05:00
|
|
|
for iter_header(testfile) |ln| {
|
2012-08-01 19:30:05 -05:00
|
|
|
if parse_name_directive(ln, ~"xfail-test") { return true; }
|
|
|
|
if parse_name_directive(ln, xfail_target()) { return true; }
|
2012-05-03 19:41:02 -05:00
|
|
|
if config.mode == common::mode_pretty &&
|
2012-08-01 19:30:05 -05:00
|
|
|
parse_name_directive(ln, ~"xfail-pretty") { return true; }
|
2011-10-21 06:14:28 -05:00
|
|
|
};
|
2012-08-01 19:30:05 -05:00
|
|
|
return found;
|
2011-09-09 15:24:06 -05:00
|
|
|
|
2012-07-14 00:57:48 -05:00
|
|
|
fn xfail_target() -> ~str {
|
2012-12-20 03:26:27 -06:00
|
|
|
~"xfail-" + str::from_slice(os::SYSNAME)
|
2011-09-09 15:24:06 -05:00
|
|
|
}
|
2011-07-30 23:11:14 -05:00
|
|
|
}
|
|
|
|
|
2013-03-07 16:38:38 -06:00
|
|
|
fn iter_header(testfile: &Path, it: &fn(~str) -> bool) -> bool {
|
2012-09-25 18:23:04 -05:00
|
|
|
let rdr = io::file_reader(testfile).get();
|
2011-07-30 23:11:14 -05:00
|
|
|
while !rdr.eof() {
|
2011-08-30 17:40:25 -05:00
|
|
|
let ln = rdr.read_line();
|
2011-07-30 23:11:14 -05:00
|
|
|
|
|
|
|
// Assume that any directives will be found before the first
|
|
|
|
// module or function. This doesn't seem to be an optimization
|
|
|
|
// with a warm page cache. Maybe with a cold one.
|
2012-07-14 00:57:48 -05:00
|
|
|
if str::starts_with(ln, ~"fn")
|
|
|
|
|| str::starts_with(ln, ~"mod") {
|
2012-08-01 19:30:05 -05:00
|
|
|
return false;
|
|
|
|
} else { if !(it(ln)) { return false; } }
|
2011-07-30 23:11:14 -05:00
|
|
|
}
|
2012-08-01 19:30:05 -05:00
|
|
|
return true;
|
2011-07-30 23:11:14 -05:00
|
|
|
}
|
|
|
|
|
2012-08-20 14:23:37 -05:00
|
|
|
fn parse_error_pattern(line: ~str) -> Option<~str> {
|
2012-07-14 00:57:48 -05:00
|
|
|
parse_name_value_directive(line, ~"error-pattern")
|
2011-07-30 23:11:14 -05:00
|
|
|
}
|
|
|
|
|
2012-08-20 14:23:37 -05:00
|
|
|
fn parse_aux_build(line: ~str) -> Option<~str> {
|
2012-07-14 00:57:48 -05:00
|
|
|
parse_name_value_directive(line, ~"aux-build")
|
2012-02-27 23:23:49 -06:00
|
|
|
}
|
|
|
|
|
2012-08-20 14:23:37 -05:00
|
|
|
fn parse_compile_flags(line: ~str) -> Option<~str> {
|
2012-07-14 00:57:48 -05:00
|
|
|
parse_name_value_directive(line, ~"compile-flags")
|
2011-07-30 23:11:14 -05:00
|
|
|
}
|
|
|
|
|
2013-02-09 12:09:19 -06:00
|
|
|
fn parse_debugger_cmd(line: ~str) -> Option<~str> {
|
|
|
|
parse_name_value_directive(line, ~"debugger")
|
|
|
|
}
|
|
|
|
|
|
|
|
fn parse_check_line(line: ~str) -> Option<~str> {
|
|
|
|
parse_name_value_directive(line, ~"check")
|
|
|
|
}
|
|
|
|
|
2012-08-20 14:23:37 -05:00
|
|
|
fn parse_exec_env(line: ~str) -> Option<(~str, ~str)> {
|
2012-07-14 00:57:48 -05:00
|
|
|
do parse_name_value_directive(line, ~"exec-env").map |nv| {
|
2012-04-13 11:19:07 -05:00
|
|
|
// nv is either FOO or FOO=BAR
|
2013-03-25 22:39:10 -05:00
|
|
|
let mut strs = ~[];
|
|
|
|
for str::each_splitn_char(*nv, '=', 1u) |s| { strs.push(s.to_owned()); }
|
2012-08-06 14:34:08 -05:00
|
|
|
match strs.len() {
|
2012-08-03 21:59:04 -05:00
|
|
|
1u => (strs[0], ~""),
|
|
|
|
2u => (strs[0], strs[1]),
|
2013-02-11 21:26:38 -06:00
|
|
|
n => fail!(fmt!("Expected 1 or 2 strings, not %u", n))
|
2012-04-13 11:19:07 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-08-20 14:23:37 -05:00
|
|
|
fn parse_pp_exact(line: ~str, testfile: &Path) -> Option<Path> {
|
2012-08-06 14:34:08 -05:00
|
|
|
match parse_name_value_directive(line, ~"pp-exact") {
|
2012-12-28 10:28:36 -06:00
|
|
|
Some(s) => Some(Path(s)),
|
|
|
|
None => {
|
2012-07-14 00:57:48 -05:00
|
|
|
if parse_name_directive(line, ~"pp-exact") {
|
2012-12-28 10:28:36 -06:00
|
|
|
Some(testfile.file_path())
|
2011-08-01 16:10:59 -05:00
|
|
|
} else {
|
2012-12-28 10:28:36 -06:00
|
|
|
None
|
2011-08-01 16:10:59 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-07-14 00:57:48 -05:00
|
|
|
fn parse_name_directive(line: ~str, directive: ~str) -> bool {
|
2012-02-13 00:00:56 -06:00
|
|
|
str::contains(line, directive)
|
2011-07-30 23:11:14 -05:00
|
|
|
}
|
|
|
|
|
2012-07-14 00:57:48 -05:00
|
|
|
fn parse_name_value_directive(line: ~str,
|
2013-01-23 13:43:58 -06:00
|
|
|
directive: ~str) -> Option<~str> {
|
2013-04-09 01:08:16 -05:00
|
|
|
let keycolon = directive + ~":";
|
|
|
|
match str::find_str(line, keycolon) {
|
|
|
|
Some(colon) => {
|
|
|
|
let value = str::slice(line, colon + str::len(keycolon),
|
|
|
|
str::len(line)).to_owned();
|
|
|
|
debug!("%s: %s", directive, value);
|
|
|
|
Some(value)
|
2012-02-13 00:00:56 -06:00
|
|
|
}
|
2013-04-09 01:08:16 -05:00
|
|
|
None => None
|
2012-02-13 00:00:56 -06:00
|
|
|
}
|
2011-07-30 23:11:14 -05:00
|
|
|
}
|