2011-07-30 23:11:14 -05:00
|
|
|
import std::option;
|
|
|
|
import std::str;
|
2011-08-11 21:14:38 -05:00
|
|
|
import std::io;
|
2011-08-01 16:10:59 -05:00
|
|
|
import std::fs;
|
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
|
2011-07-18 10:41:35 -05:00
|
|
|
error_patterns: [str],
|
2011-08-01 16:10:59 -05:00
|
|
|
// Extra flags to pass to the compiler
|
2011-08-10 11:27:22 -05:00
|
|
|
compile_flags: option::t<str>,
|
2011-08-01 16:10:59 -05:00
|
|
|
// If present, the name of a file that this test should match when
|
|
|
|
// pretty-printed
|
2011-08-10 11:27:22 -05:00
|
|
|
pp_exact: option::t<str>,
|
2011-08-10 15:36:57 -05:00
|
|
|
// FIXME: no-valgrind is a temporary directive until all of run-fail
|
|
|
|
// is valgrind-clean
|
|
|
|
no_valgrind: bool
|
2011-08-01 16:10:59 -05:00
|
|
|
};
|
2011-07-30 23:11:14 -05:00
|
|
|
|
|
|
|
// Load any test directives embedded in the file
|
|
|
|
fn load_props(testfile: &str) -> test_props {
|
|
|
|
let error_patterns = ~[];
|
|
|
|
let compile_flags = option::none;
|
2011-08-01 16:10:59 -05:00
|
|
|
let pp_exact = option::none;
|
2011-08-10 15:36:57 -05:00
|
|
|
let no_valgrind = false;
|
2011-08-15 23:54:52 -05:00
|
|
|
for each ln: str in iter_header(testfile) {
|
2011-07-30 23:11:14 -05:00
|
|
|
alt parse_error_pattern(ln) {
|
|
|
|
option::some(ep) { error_patterns += ~[ep]; }
|
|
|
|
option::none. { }
|
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
2011-08-10 15:36:57 -05:00
|
|
|
|
|
|
|
if no_valgrind == false {
|
|
|
|
no_valgrind = parse_name_directive(ln, "no-valgrind");
|
|
|
|
}
|
2011-07-30 23:11:14 -05:00
|
|
|
}
|
2011-08-01 16:10:59 -05:00
|
|
|
ret {
|
|
|
|
error_patterns: error_patterns,
|
|
|
|
compile_flags: compile_flags,
|
2011-08-10 15:36:57 -05:00
|
|
|
pp_exact: pp_exact,
|
|
|
|
no_valgrind: no_valgrind
|
2011-08-01 16:10:59 -05:00
|
|
|
};
|
2011-07-30 23:11:14 -05:00
|
|
|
}
|
|
|
|
|
2011-08-01 13:23:58 -05:00
|
|
|
fn is_test_ignored(config: &config, testfile: &str) -> bool {
|
2011-07-30 23:11:14 -05:00
|
|
|
let found = false;
|
2011-08-15 23:54:52 -05:00
|
|
|
for each ln: str in iter_header(testfile) {
|
2011-07-30 23:11:14 -05:00
|
|
|
// FIXME: Can't return or break from iterator
|
|
|
|
found = found
|
2011-08-01 13:23:58 -05:00
|
|
|
|| parse_name_directive(ln, "xfail-" + config.stage_id);
|
|
|
|
if (config.mode == common::mode_pretty) {
|
|
|
|
found = found
|
|
|
|
|| parse_name_directive(ln, "xfail-pretty");
|
|
|
|
}
|
2011-07-30 23:11:14 -05:00
|
|
|
}
|
|
|
|
ret found;
|
|
|
|
}
|
|
|
|
|
|
|
|
iter iter_header(testfile: &str) -> str {
|
2011-08-11 21:14:38 -05:00
|
|
|
let rdr = io::file_reader(testfile);
|
2011-07-30 23:11:14 -05:00
|
|
|
while !rdr.eof() {
|
|
|
|
let ln = rdr.read_line();
|
|
|
|
|
|
|
|
// 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.
|
|
|
|
if str::starts_with(ln, "fn") || str::starts_with(ln, "mod") {
|
|
|
|
break;
|
|
|
|
} else { put ln; }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-08-10 11:27:22 -05:00
|
|
|
fn parse_error_pattern(line: &str) -> option::t<str> {
|
2011-07-30 23:11:14 -05:00
|
|
|
parse_name_value_directive(line, "error-pattern")
|
|
|
|
}
|
|
|
|
|
2011-08-10 11:27:22 -05:00
|
|
|
fn parse_compile_flags(line: &str) -> option::t<str> {
|
2011-07-30 23:11:14 -05:00
|
|
|
parse_name_value_directive(line, "compile-flags")
|
|
|
|
}
|
|
|
|
|
2011-08-10 11:27:22 -05:00
|
|
|
fn parse_pp_exact(line: &str, testfile: &str) -> option::t<str> {
|
2011-08-01 16:10:59 -05:00
|
|
|
alt parse_name_value_directive(line, "pp-exact") {
|
|
|
|
option::some(s) { option::some(s) }
|
|
|
|
option::none. {
|
|
|
|
if parse_name_directive(line, "pp-exact") {
|
|
|
|
option::some(fs::basename(testfile))
|
|
|
|
} else {
|
|
|
|
option::none
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-07-30 23:11:14 -05:00
|
|
|
fn parse_name_directive(line: &str, directive: &str) -> bool {
|
|
|
|
str::find(line, directive) >= 0
|
|
|
|
}
|
|
|
|
|
|
|
|
fn parse_name_value_directive(line: &str,
|
2011-08-10 11:27:22 -05:00
|
|
|
directive: &str) -> option::t<str> {
|
2011-07-30 23:11:14 -05:00
|
|
|
let keycolon = directive + ":";
|
|
|
|
if str::find(line, keycolon) >= 0 {
|
|
|
|
let colon = str::find(line, keycolon) as uint;
|
|
|
|
let value =
|
|
|
|
str::slice(line, colon + str::byte_len(keycolon),
|
|
|
|
str::byte_len(line));
|
|
|
|
log #fmt("%s: %s", directive, value);
|
|
|
|
option::some(value)
|
|
|
|
} else { option::none }
|
|
|
|
}
|