2011-12-13 16:25:51 -08:00
|
|
|
import option;
|
|
|
|
import str;
|
2012-01-11 15:15:54 +01:00
|
|
|
import io::reader_util;
|
2011-07-30 21:11:14 -07:00
|
|
|
|
2011-08-01 11:23:58 -07:00
|
|
|
import common::config;
|
|
|
|
|
2011-07-30 21:11:14 -07:00
|
|
|
export test_props;
|
|
|
|
export load_props;
|
|
|
|
export is_test_ignored;
|
|
|
|
|
2011-08-01 14:10:59 -07:00
|
|
|
type test_props = {
|
|
|
|
// Lines that should be expected, in order, on standard out
|
2011-09-02 15:34:58 -07:00
|
|
|
error_patterns: [str],
|
2011-08-01 14:10:59 -07:00
|
|
|
// Extra flags to pass to the compiler
|
2012-01-31 17:05:20 -08: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-02-27 21:23:49 -08:00
|
|
|
pp_exact: option<str>,
|
|
|
|
// Modules from aux directory that should be compiled
|
2012-04-13 09:19:07 -07:00
|
|
|
aux_builds: [str],
|
|
|
|
// Environment settings to use during execution
|
|
|
|
exec_env: [(str,str)]
|
2011-08-01 14:10:59 -07:00
|
|
|
};
|
2011-07-30 21:11:14 -07:00
|
|
|
|
|
|
|
// Load any test directives embedded in the file
|
2011-09-12 11:27:30 +02:00
|
|
|
fn load_props(testfile: str) -> test_props {
|
2012-03-22 08:39:41 -07:00
|
|
|
let mut error_patterns = [];
|
|
|
|
let mut aux_builds = [];
|
2012-04-13 09:19:07 -07:00
|
|
|
let mut exec_env = [];
|
2012-03-22 08:39:41 -07:00
|
|
|
let mut compile_flags = option::none;
|
|
|
|
let mut pp_exact = option::none;
|
2012-05-03 17:41:02 -07:00
|
|
|
for iter_header(testfile) {|ln|
|
2011-07-30 21:11:14 -07:00
|
|
|
alt parse_error_pattern(ln) {
|
2011-08-19 15:32:39 -07:00
|
|
|
option::some(ep) { error_patterns += [ep]; }
|
2012-01-18 22:37:22 -08:00
|
|
|
option::none { }
|
2011-10-21 13:14:28 +02:00
|
|
|
};
|
2011-07-30 21:11:14 -07:00
|
|
|
|
|
|
|
if option::is_none(compile_flags) {
|
|
|
|
compile_flags = parse_compile_flags(ln);
|
|
|
|
}
|
2011-08-01 14:10:59 -07:00
|
|
|
|
|
|
|
if option::is_none(pp_exact) {
|
|
|
|
pp_exact = parse_pp_exact(ln, testfile);
|
|
|
|
}
|
2012-02-27 21:23:49 -08:00
|
|
|
|
2012-04-06 12:14:09 -07:00
|
|
|
option::iter(parse_aux_build(ln)) {|ab|
|
2012-02-27 21:23:49 -08:00
|
|
|
aux_builds += [ab];
|
|
|
|
}
|
2012-04-13 09:19:07 -07:00
|
|
|
|
|
|
|
option::iter(parse_exec_env(ln)) {|ee|
|
|
|
|
exec_env += [ee];
|
|
|
|
}
|
2011-10-21 13:14:28 +02:00
|
|
|
};
|
2011-08-01 14:10:59 -07:00
|
|
|
ret {
|
|
|
|
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,
|
|
|
|
exec_env: exec_env
|
2011-08-01 14:10:59 -07:00
|
|
|
};
|
2011-07-30 21:11:14 -07:00
|
|
|
}
|
|
|
|
|
2011-09-12 11:27:30 +02:00
|
|
|
fn is_test_ignored(config: config, testfile: str) -> bool {
|
2012-03-22 08:39:41 -07:00
|
|
|
let mut found = false;
|
2012-05-03 17:41:02 -07:00
|
|
|
for iter_header(testfile) {|ln|
|
|
|
|
if parse_name_directive(ln, "xfail-test") { ret true; }
|
|
|
|
if parse_name_directive(ln, xfail_target()) { ret true; }
|
|
|
|
if config.mode == common::mode_pretty &&
|
|
|
|
parse_name_directive(ln, "xfail-pretty") { ret true; }
|
2011-10-21 13:14:28 +02:00
|
|
|
};
|
2011-07-30 21:11:14 -07:00
|
|
|
ret found;
|
2011-09-09 13:24:06 -07:00
|
|
|
|
|
|
|
fn xfail_target() -> str {
|
2012-03-12 20:04:27 -07:00
|
|
|
"xfail-" + os::sysname()
|
2011-09-09 13:24:06 -07:00
|
|
|
}
|
2011-07-30 21:11:14 -07:00
|
|
|
}
|
|
|
|
|
2012-05-03 17:41:02 -07:00
|
|
|
fn iter_header(testfile: str, it: fn(str) -> bool) -> bool {
|
2011-12-13 16:25:51 -08:00
|
|
|
let rdr = result::get(io::file_reader(testfile));
|
2011-07-30 21:11:14 -07:00
|
|
|
while !rdr.eof() {
|
2011-08-30 15:40:25 -07:00
|
|
|
let ln = rdr.read_line();
|
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.
|
2011-09-02 15:34:58 -07:00
|
|
|
if str::starts_with(ln, "fn")
|
|
|
|
|| str::starts_with(ln, "mod") {
|
2012-05-03 17:41:02 -07:00
|
|
|
ret false;
|
|
|
|
} else { if !(it(ln)) { ret false; } }
|
2011-07-30 21:11:14 -07:00
|
|
|
}
|
2012-05-03 17:41:02 -07:00
|
|
|
ret true;
|
2011-07-30 21:11:14 -07:00
|
|
|
}
|
|
|
|
|
2012-01-31 17:05:20 -08:00
|
|
|
fn parse_error_pattern(line: str) -> option<str> {
|
2011-09-02 15:34:58 -07:00
|
|
|
parse_name_value_directive(line, "error-pattern")
|
2011-07-30 21:11:14 -07:00
|
|
|
}
|
|
|
|
|
2012-02-27 21:23:49 -08:00
|
|
|
fn parse_aux_build(line: str) -> option<str> {
|
|
|
|
parse_name_value_directive(line, "aux-build")
|
|
|
|
}
|
|
|
|
|
2012-01-31 17:05:20 -08:00
|
|
|
fn parse_compile_flags(line: str) -> option<str> {
|
2011-09-02 15:34:58 -07:00
|
|
|
parse_name_value_directive(line, "compile-flags")
|
2011-07-30 21:11:14 -07:00
|
|
|
}
|
|
|
|
|
2012-04-13 09:19:07 -07:00
|
|
|
fn parse_exec_env(line: str) -> option<(str, str)> {
|
|
|
|
parse_name_value_directive(line, "exec-env").map {|nv|
|
|
|
|
// nv is either FOO or FOO=BAR
|
|
|
|
let strs = str::splitn_char(nv, '=', 1u);
|
|
|
|
alt strs.len() {
|
|
|
|
1u { (strs[0], "") }
|
|
|
|
2u { (strs[0], strs[1]) }
|
|
|
|
n { fail #fmt["Expected 1 or 2 strings, not %u", n]; }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-01-31 17:05:20 -08:00
|
|
|
fn parse_pp_exact(line: str, testfile: str) -> option<str> {
|
2011-09-02 15:34:58 -07:00
|
|
|
alt parse_name_value_directive(line, "pp-exact") {
|
2011-08-01 14:10:59 -07:00
|
|
|
option::some(s) { option::some(s) }
|
2012-01-18 22:37:22 -08:00
|
|
|
option::none {
|
2011-09-02 15:34:58 -07:00
|
|
|
if parse_name_directive(line, "pp-exact") {
|
2012-03-12 20:04:27 -07:00
|
|
|
option::some(path::basename(testfile))
|
2011-08-01 14:10:59 -07:00
|
|
|
} else {
|
|
|
|
option::none
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-09-12 11:27:30 +02:00
|
|
|
fn parse_name_directive(line: str, directive: str) -> bool {
|
2012-02-12 22:00:56 -08:00
|
|
|
str::contains(line, directive)
|
2011-07-30 21:11:14 -07:00
|
|
|
}
|
|
|
|
|
2011-09-12 11:27:30 +02:00
|
|
|
fn parse_name_value_directive(line: str,
|
2012-02-01 03:45:44 -08:00
|
|
|
directive: str) -> option<str> unsafe {
|
2011-09-02 15:34:58 -07:00
|
|
|
let keycolon = directive + ":";
|
2012-02-23 16:59:30 +01:00
|
|
|
alt str::find_str(line, keycolon) {
|
2012-02-12 22:00:56 -08:00
|
|
|
option::some(colon) {
|
2012-02-23 01:44:04 -08:00
|
|
|
let value = str::slice(line, colon + str::len(keycolon),
|
|
|
|
str::len(line));
|
2012-02-12 22:00:56 -08:00
|
|
|
#debug("%s: %s", directive, value);
|
|
|
|
option::some(value)
|
|
|
|
}
|
|
|
|
option::none { option::none }
|
|
|
|
}
|
2011-07-30 21:11:14 -07:00
|
|
|
}
|