2014-01-04 21:16:57 +01: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 16:48:01 -08: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.
|
|
|
|
|
2012-09-07 18:08:21 -07:00
|
|
|
use common::config;
|
2013-05-24 19:35:29 -07:00
|
|
|
use common;
|
2013-09-03 19:34:23 +09:00
|
|
|
use util;
|
2013-05-24 19:35:29 -07:00
|
|
|
|
2013-01-30 14:10:03 -08:00
|
|
|
pub struct TestProps {
|
2011-08-01 14:10:59 -07:00
|
|
|
// Lines that should be expected, in order, on standard out
|
2012-07-13 22:57:48 -07:00
|
|
|
error_patterns: ~[~str],
|
2011-08-01 14:10:59 -07:00
|
|
|
// Extra flags to pass to the compiler
|
2012-08-20 12:23:37 -07:00
|
|
|
compile_flags: Option<~str>,
|
2011-08-01 14:10:59 -07:00
|
|
|
// If present, the name of a file that this test should match when
|
|
|
|
// pretty-printed
|
2012-08-20 12:23:37 -07:00
|
|
|
pp_exact: Option<Path>,
|
2012-02-27 21:23:49 -08:00
|
|
|
// Modules from aux directory that should be compiled
|
2012-07-13 22:57:48 -07:00
|
|
|
aux_builds: ~[~str],
|
2012-04-13 09:19:07 -07:00
|
|
|
// Environment settings to use during execution
|
2013-02-09 13:09:19 -05: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-25 22:51:32 -08:00
|
|
|
}
|
2011-07-30 21:11:14 -07:00
|
|
|
|
|
|
|
// Load any test directives embedded in the file
|
2013-01-30 14:10:03 -08:00
|
|
|
pub fn load_props(testfile: &Path) -> TestProps {
|
2012-06-29 16:26:56 -07:00
|
|
|
let mut error_patterns = ~[];
|
|
|
|
let mut aux_builds = ~[];
|
|
|
|
let mut exec_env = ~[];
|
2012-12-28 11:28:36 -05:00
|
|
|
let mut compile_flags = None;
|
|
|
|
let mut pp_exact = None;
|
2013-02-09 13:09:19 -05:00
|
|
|
let mut debugger_cmds = ~[];
|
|
|
|
let mut check_lines = ~[];
|
2013-11-21 17:23:21 -08:00
|
|
|
iter_header(testfile, |ln| {
|
2012-08-06 12:34:08 -07:00
|
|
|
match parse_error_pattern(ln) {
|
2012-12-28 11:28:36 -05:00
|
|
|
Some(ep) => error_patterns.push(ep),
|
|
|
|
None => ()
|
2011-10-21 13:14:28 +02:00
|
|
|
};
|
2011-07-30 21:11:14 -07:00
|
|
|
|
2012-09-21 19:37:57 -07:00
|
|
|
if compile_flags.is_none() {
|
2011-07-30 21:11:14 -07:00
|
|
|
compile_flags = parse_compile_flags(ln);
|
|
|
|
}
|
2011-08-01 14:10:59 -07:00
|
|
|
|
2012-09-21 19:37:57 -07:00
|
|
|
if pp_exact.is_none() {
|
2011-08-01 14:10:59 -07:00
|
|
|
pp_exact = parse_pp_exact(ln, testfile);
|
|
|
|
}
|
2012-02-27 21:23:49 -08:00
|
|
|
|
2013-05-11 22:45:28 -04:00
|
|
|
match parse_aux_build(ln) {
|
|
|
|
Some(ab) => { aux_builds.push(ab); }
|
|
|
|
None => {}
|
2012-02-27 21:23:49 -08:00
|
|
|
}
|
2012-04-13 09:19:07 -07:00
|
|
|
|
2013-05-11 22:45:28 -04:00
|
|
|
match parse_exec_env(ln) {
|
|
|
|
Some(ee) => { exec_env.push(ee); }
|
|
|
|
None => {}
|
2012-04-13 09:19:07 -07:00
|
|
|
}
|
2013-02-09 13:09:19 -05: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 => ()
|
|
|
|
};
|
2013-08-02 02:17:20 -04:00
|
|
|
|
|
|
|
true
|
2013-11-21 17:23:21 -08:00
|
|
|
});
|
2013-01-25 22:51:32 -08:00
|
|
|
return TestProps {
|
2011-08-01 14:10:59 -07:00
|
|
|
error_patterns: error_patterns,
|
|
|
|
compile_flags: compile_flags,
|
2012-02-27 21:23:49 -08:00
|
|
|
pp_exact: pp_exact,
|
2012-04-13 09:19:07 -07:00
|
|
|
aux_builds: aux_builds,
|
2013-02-09 13:09:19 -05:00
|
|
|
exec_env: exec_env,
|
|
|
|
debugger_cmds: debugger_cmds,
|
|
|
|
check_lines: check_lines
|
2011-08-01 14:10:59 -07:00
|
|
|
};
|
2011-07-30 21:11:14 -07:00
|
|
|
}
|
|
|
|
|
2013-05-11 22:45:28 -04:00
|
|
|
pub fn is_test_ignored(config: &config, testfile: &Path) -> bool {
|
2013-09-03 19:34:23 +09:00
|
|
|
fn xfail_target(config: &config) -> ~str {
|
|
|
|
~"xfail-" + util::get_os(config.target)
|
2011-09-09 13:24:06 -07:00
|
|
|
}
|
2013-08-02 02:17:20 -04:00
|
|
|
|
2013-11-21 17:23:21 -08:00
|
|
|
let val = iter_header(testfile, |ln| {
|
2013-08-02 02:17:20 -04:00
|
|
|
if parse_name_directive(ln, "xfail-test") { false }
|
2013-09-03 19:34:23 +09:00
|
|
|
else if parse_name_directive(ln, xfail_target(config)) { false }
|
2013-08-02 02:17:20 -04:00
|
|
|
else if config.mode == common::mode_pretty &&
|
|
|
|
parse_name_directive(ln, "xfail-pretty") { false }
|
|
|
|
else { true }
|
2013-11-21 17:23:21 -08:00
|
|
|
});
|
2013-08-02 02:17:20 -04:00
|
|
|
|
|
|
|
!val
|
2011-07-30 21:11:14 -07:00
|
|
|
}
|
|
|
|
|
2013-11-19 18:15:10 -08:00
|
|
|
fn iter_header(testfile: &Path, it: |&str| -> bool) -> bool {
|
2013-11-10 22:46:32 -08:00
|
|
|
use std::io::buffered::BufferedReader;
|
|
|
|
use std::io::File;
|
2013-10-06 16:08:56 -07:00
|
|
|
|
2013-10-29 23:31:07 -07:00
|
|
|
let mut rdr = BufferedReader::new(File::open(testfile).unwrap());
|
2013-12-08 16:12:07 +09:00
|
|
|
for ln in rdr.lines() {
|
2011-07-30 21:11:14 -07: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.
|
2013-06-11 01:03:16 +10:00
|
|
|
if ln.starts_with("fn") || ln.starts_with("mod") {
|
2013-08-02 02:17:20 -04:00
|
|
|
return true;
|
2013-10-06 16:08:56 -07:00
|
|
|
} else { if !(it(ln.trim())) { return false; } }
|
2011-07-30 21:11:14 -07:00
|
|
|
}
|
2012-08-01 17:30:05 -07:00
|
|
|
return true;
|
2011-07-30 21:11:14 -07:00
|
|
|
}
|
|
|
|
|
2013-05-11 22:45:28 -04:00
|
|
|
fn parse_error_pattern(line: &str) -> Option<~str> {
|
2012-07-13 22:57:48 -07:00
|
|
|
parse_name_value_directive(line, ~"error-pattern")
|
2011-07-30 21:11:14 -07:00
|
|
|
}
|
|
|
|
|
2013-05-11 22:45:28 -04:00
|
|
|
fn parse_aux_build(line: &str) -> Option<~str> {
|
2012-07-13 22:57:48 -07:00
|
|
|
parse_name_value_directive(line, ~"aux-build")
|
2012-02-27 21:23:49 -08:00
|
|
|
}
|
|
|
|
|
2013-05-11 22:45:28 -04:00
|
|
|
fn parse_compile_flags(line: &str) -> Option<~str> {
|
2012-07-13 22:57:48 -07:00
|
|
|
parse_name_value_directive(line, ~"compile-flags")
|
2011-07-30 21:11:14 -07:00
|
|
|
}
|
|
|
|
|
2013-05-11 22:45:28 -04:00
|
|
|
fn parse_debugger_cmd(line: &str) -> Option<~str> {
|
2013-02-09 13:09:19 -05:00
|
|
|
parse_name_value_directive(line, ~"debugger")
|
|
|
|
}
|
|
|
|
|
2013-05-11 22:45:28 -04:00
|
|
|
fn parse_check_line(line: &str) -> Option<~str> {
|
2013-02-09 13:09:19 -05:00
|
|
|
parse_name_value_directive(line, ~"check")
|
|
|
|
}
|
|
|
|
|
2013-05-11 22:45:28 -04:00
|
|
|
fn parse_exec_env(line: &str) -> Option<(~str, ~str)> {
|
2013-11-21 17:23:21 -08:00
|
|
|
parse_name_value_directive(line, ~"exec-env").map(|nv| {
|
2012-04-13 09:19:07 -07:00
|
|
|
// nv is either FOO or FOO=BAR
|
2013-11-23 11:18:51 +01:00
|
|
|
let mut strs: ~[~str] = nv.splitn('=', 1).map(|s| s.to_owned()).collect();
|
2013-06-09 23:10:50 +10:00
|
|
|
|
2012-08-06 12:34:08 -07:00
|
|
|
match strs.len() {
|
2013-05-11 22:45:28 -04:00
|
|
|
1u => (strs.pop(), ~""),
|
|
|
|
2u => {
|
|
|
|
let end = strs.pop();
|
|
|
|
(strs.pop(), end)
|
|
|
|
}
|
2013-10-21 13:08:31 -07:00
|
|
|
n => fail!("Expected 1 or 2 strings, not {}", n)
|
2012-04-13 09:19:07 -07:00
|
|
|
}
|
2013-11-21 17:23:21 -08:00
|
|
|
})
|
2012-04-13 09:19:07 -07:00
|
|
|
}
|
|
|
|
|
2013-05-11 22:45:28 -04:00
|
|
|
fn parse_pp_exact(line: &str, testfile: &Path) -> Option<Path> {
|
2012-08-06 12:34:08 -07:00
|
|
|
match parse_name_value_directive(line, ~"pp-exact") {
|
2013-12-03 19:15:12 -08:00
|
|
|
Some(s) => Some(Path::new(s)),
|
2012-12-28 11:28:36 -05:00
|
|
|
None => {
|
2013-05-11 22:45:28 -04:00
|
|
|
if parse_name_directive(line, "pp-exact") {
|
2013-12-03 19:15:12 -08:00
|
|
|
testfile.filename().map(|s| Path::new(s))
|
2011-08-01 14:10:59 -07:00
|
|
|
} else {
|
2012-12-28 11:28:36 -05:00
|
|
|
None
|
2011-08-01 14:10:59 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-05-11 22:45:28 -04:00
|
|
|
fn parse_name_directive(line: &str, directive: &str) -> bool {
|
2013-06-10 17:32:36 +10:00
|
|
|
line.contains(directive)
|
2011-07-30 21:11:14 -07:00
|
|
|
}
|
|
|
|
|
2013-05-11 22:45:28 -04:00
|
|
|
fn parse_name_value_directive(line: &str,
|
2013-01-23 11:43:58 -08:00
|
|
|
directive: ~str) -> Option<~str> {
|
2013-05-29 20:10:16 +02:00
|
|
|
let keycolon = directive + ":";
|
2013-06-10 16:23:05 +10:00
|
|
|
match line.find_str(keycolon) {
|
2013-04-09 02:08:16 -04:00
|
|
|
Some(colon) => {
|
2013-06-10 00:44:58 +10:00
|
|
|
let value = line.slice(colon + keycolon.len(),
|
|
|
|
line.len()).to_owned();
|
2013-10-21 13:08:31 -07:00
|
|
|
debug!("{}: {}", directive, value);
|
2013-04-09 02:08:16 -04:00
|
|
|
Some(value)
|
2012-02-12 22:00:56 -08:00
|
|
|
}
|
2013-04-09 02:08:16 -04:00
|
|
|
None => None
|
2012-02-12 22:00:56 -08:00
|
|
|
}
|
2011-07-30 21:11:14 -07:00
|
|
|
}
|