2011-12-13 18:25:51 -06:00
|
|
|
import option;
|
|
|
|
import str;
|
2012-01-11 08:15:54 -06:00
|
|
|
import io::reader_util;
|
2011-07-30 23:11:14 -05:00
|
|
|
|
2011-08-01 13:23:58 -05:00
|
|
|
import common::config;
|
|
|
|
|
2011-07-30 23:11:14 -05:00
|
|
|
export test_props;
|
|
|
|
export load_props;
|
|
|
|
export is_test_ignored;
|
|
|
|
|
2011-08-01 16:10:59 -05:00
|
|
|
type test_props = {
|
|
|
|
// 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-07-14 00:57:48 -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-07-14 00:57:48 -05:00
|
|
|
pp_exact: option<~str>,
|
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
|
2012-07-14 00:57:48 -05:00
|
|
|
exec_env: ~[(~str,~str)]
|
2011-08-01 16:10:59 -05:00
|
|
|
};
|
2011-07-30 23:11:14 -05:00
|
|
|
|
|
|
|
// Load any test directives embedded in the file
|
2012-07-14 00:57:48 -05:00
|
|
|
fn load_props(testfile: ~str) -> test_props {
|
2012-06-29 18:26:56 -05:00
|
|
|
let mut error_patterns = ~[];
|
|
|
|
let mut aux_builds = ~[];
|
|
|
|
let mut exec_env = ~[];
|
2012-03-22 10:39:41 -05:00
|
|
|
let mut compile_flags = option::none;
|
|
|
|
let mut pp_exact = option::none;
|
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-08-03 21:59:04 -05:00
|
|
|
option::some(ep) => vec::push(error_patterns, ep),
|
|
|
|
option::none => ()
|
2011-10-21 06:14:28 -05:00
|
|
|
};
|
2011-07-30 23:11:14 -05:00
|
|
|
|
|
|
|
if option::is_none(compile_flags) {
|
|
|
|
compile_flags = parse_compile_flags(ln);
|
|
|
|
}
|
2011-08-01 16:10:59 -05:00
|
|
|
|
|
|
|
if option::is_none(pp_exact) {
|
|
|
|
pp_exact = parse_pp_exact(ln, testfile);
|
|
|
|
}
|
2012-02-27 23:23:49 -06:00
|
|
|
|
2012-06-30 18:19:07 -05:00
|
|
|
do option::iter(parse_aux_build(ln)) |ab| {
|
2012-06-15 20:16:42 -05:00
|
|
|
vec::push(aux_builds, ab);
|
2012-02-27 23:23:49 -06:00
|
|
|
}
|
2012-04-13 11:19:07 -05:00
|
|
|
|
2012-06-30 18:19:07 -05:00
|
|
|
do option::iter(parse_exec_env(ln)) |ee| {
|
2012-06-15 20:16:42 -05:00
|
|
|
vec::push(exec_env, ee);
|
2012-04-13 11:19:07 -05:00
|
|
|
}
|
2011-10-21 06:14:28 -05:00
|
|
|
};
|
2012-08-01 19:30:05 -05:00
|
|
|
return {
|
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,
|
|
|
|
exec_env: exec_env
|
2011-08-01 16:10:59 -05:00
|
|
|
};
|
2011-07-30 23:11:14 -05:00
|
|
|
}
|
|
|
|
|
2012-07-14 00:57:48 -05:00
|
|
|
fn is_test_ignored(config: config, testfile: ~str) -> 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 {
|
|
|
|
~"xfail-" + os::sysname()
|
2011-09-09 15:24:06 -05:00
|
|
|
}
|
2011-07-30 23:11:14 -05:00
|
|
|
}
|
|
|
|
|
2012-07-14 00:57:48 -05:00
|
|
|
fn iter_header(testfile: ~str, it: fn(~str) -> bool) -> bool {
|
2011-12-13 18:25:51 -06:00
|
|
|
let rdr = result::get(io::file_reader(testfile));
|
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-07-14 00:57:48 -05:00
|
|
|
fn parse_error_pattern(line: ~str) -> option<~str> {
|
|
|
|
parse_name_value_directive(line, ~"error-pattern")
|
2011-07-30 23:11:14 -05:00
|
|
|
}
|
|
|
|
|
2012-07-14 00:57:48 -05:00
|
|
|
fn parse_aux_build(line: ~str) -> option<~str> {
|
|
|
|
parse_name_value_directive(line, ~"aux-build")
|
2012-02-27 23:23:49 -06:00
|
|
|
}
|
|
|
|
|
2012-07-14 00:57:48 -05:00
|
|
|
fn parse_compile_flags(line: ~str) -> option<~str> {
|
|
|
|
parse_name_value_directive(line, ~"compile-flags")
|
2011-07-30 23:11:14 -05:00
|
|
|
}
|
|
|
|
|
2012-07-14 00:57:48 -05:00
|
|
|
fn parse_exec_env(line: ~str) -> option<(~str, ~str)> {
|
|
|
|
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
|
|
|
|
let strs = str::splitn_char(nv, '=', 1u);
|
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]),
|
|
|
|
n => fail fmt!{"Expected 1 or 2 strings, not %u", n}
|
2012-04-13 11:19:07 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-07-14 00:57:48 -05:00
|
|
|
fn parse_pp_exact(line: ~str, testfile: ~str) -> option<~str> {
|
2012-08-06 14:34:08 -05:00
|
|
|
match parse_name_value_directive(line, ~"pp-exact") {
|
2012-08-03 21:59:04 -05:00
|
|
|
option::some(s) => option::some(s),
|
|
|
|
option::none => {
|
2012-07-14 00:57:48 -05:00
|
|
|
if parse_name_directive(line, ~"pp-exact") {
|
2012-03-12 22:04:27 -05:00
|
|
|
option::some(path::basename(testfile))
|
2011-08-01 16:10:59 -05:00
|
|
|
} else {
|
|
|
|
option::none
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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,
|
|
|
|
directive: ~str) -> option<~str> unsafe {
|
|
|
|
let keycolon = directive + ~":";
|
2012-08-06 14:34:08 -05:00
|
|
|
match str::find_str(line, keycolon) {
|
2012-08-03 21:59:04 -05:00
|
|
|
option::some(colon) => {
|
2012-02-23 03:44:04 -06:00
|
|
|
let value = str::slice(line, colon + str::len(keycolon),
|
|
|
|
str::len(line));
|
2012-07-30 18:01:07 -05:00
|
|
|
debug!{"%s: %s", directive, value};
|
2012-02-13 00:00:56 -06:00
|
|
|
option::some(value)
|
|
|
|
}
|
2012-08-03 21:59:04 -05:00
|
|
|
option::none => option::none
|
2012-02-13 00:00:56 -06:00
|
|
|
}
|
2011-07-30 23:11:14 -05:00
|
|
|
}
|