2011-07-30 23:11:14 -05:00
|
|
|
import std::option;
|
2011-09-01 19:27:58 -05:00
|
|
|
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-08-30 17:40:25 -05:00
|
|
|
error_patterns: [istr],
|
2011-08-01 16:10:59 -05:00
|
|
|
// Extra flags to pass to the compiler
|
2011-08-30 17:40:25 -05:00
|
|
|
compile_flags: option::t<istr>,
|
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-30 17:40:25 -05:00
|
|
|
pp_exact: option::t<istr>,
|
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
|
2011-08-30 17:40:25 -05:00
|
|
|
fn load_props(testfile: &istr) -> test_props {
|
2011-08-19 17:32:39 -05:00
|
|
|
let error_patterns = [];
|
2011-07-30 23:11:14 -05:00
|
|
|
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-30 17:40:25 -05:00
|
|
|
for each ln: istr in iter_header(testfile) {
|
2011-07-30 23:11:14 -05:00
|
|
|
alt parse_error_pattern(ln) {
|
2011-08-19 17:32:39 -05:00
|
|
|
option::some(ep) { error_patterns += [ep]; }
|
2011-07-30 23:11:14 -05:00
|
|
|
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 {
|
2011-08-30 17:40:25 -05:00
|
|
|
no_valgrind = parse_name_directive(ln, ~"no-valgrind");
|
2011-08-10 15:36:57 -05:00
|
|
|
}
|
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-30 17:40:25 -05:00
|
|
|
fn is_test_ignored(config: &config, testfile: &istr) -> bool {
|
2011-07-30 23:11:14 -05:00
|
|
|
let found = false;
|
2011-08-30 17:40:25 -05:00
|
|
|
for each ln: istr in iter_header(testfile) {
|
2011-07-30 23:11:14 -05:00
|
|
|
// FIXME: Can't return or break from iterator
|
2011-08-31 06:22:58 -05:00
|
|
|
found = found || parse_name_directive(ln, ~"xfail-test");
|
2011-08-01 13:23:58 -05:00
|
|
|
if (config.mode == common::mode_pretty) {
|
2011-08-31 06:22:58 -05:00
|
|
|
found = found || parse_name_directive(ln, ~"xfail-pretty");
|
2011-08-01 13:23:58 -05:00
|
|
|
}
|
2011-07-30 23:11:14 -05:00
|
|
|
}
|
|
|
|
ret found;
|
|
|
|
}
|
|
|
|
|
2011-08-30 17:40:25 -05:00
|
|
|
iter iter_header(testfile: &istr) -> istr {
|
|
|
|
let rdr = 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.
|
2011-09-01 19:27:58 -05:00
|
|
|
if str::starts_with(ln, ~"fn")
|
|
|
|
|| str::starts_with(ln, ~"mod") {
|
2011-07-30 23:11:14 -05:00
|
|
|
break;
|
|
|
|
} else { put ln; }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-08-30 17:40:25 -05:00
|
|
|
fn parse_error_pattern(line: &istr) -> option::t<istr> {
|
|
|
|
parse_name_value_directive(line, ~"error-pattern")
|
2011-07-30 23:11:14 -05:00
|
|
|
}
|
|
|
|
|
2011-08-30 17:40:25 -05:00
|
|
|
fn parse_compile_flags(line: &istr) -> option::t<istr> {
|
|
|
|
parse_name_value_directive(line, ~"compile-flags")
|
2011-07-30 23:11:14 -05:00
|
|
|
}
|
|
|
|
|
2011-08-30 17:40:25 -05:00
|
|
|
fn parse_pp_exact(line: &istr, testfile: &istr) -> option::t<istr> {
|
|
|
|
alt parse_name_value_directive(line, ~"pp-exact") {
|
2011-08-01 16:10:59 -05:00
|
|
|
option::some(s) { option::some(s) }
|
|
|
|
option::none. {
|
2011-08-30 17:40:25 -05:00
|
|
|
if parse_name_directive(line, ~"pp-exact") {
|
|
|
|
option::some(fs::basename(testfile))
|
2011-08-01 16:10:59 -05:00
|
|
|
} else {
|
|
|
|
option::none
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-08-30 17:40:25 -05:00
|
|
|
fn parse_name_directive(line: &istr, directive: &istr) -> bool {
|
2011-09-01 19:27:58 -05:00
|
|
|
str::find(line, directive) >= 0
|
2011-07-30 23:11:14 -05:00
|
|
|
}
|
|
|
|
|
2011-08-30 17:40:25 -05:00
|
|
|
fn parse_name_value_directive(line: &istr,
|
|
|
|
directive: &istr) -> option::t<istr> {
|
|
|
|
let keycolon = directive + ~":";
|
2011-09-01 19:27:58 -05:00
|
|
|
if str::find(line, keycolon) >= 0 {
|
|
|
|
let colon = str::find(line, keycolon) as uint;
|
2011-07-30 23:11:14 -05:00
|
|
|
let value =
|
2011-09-01 19:27:58 -05:00
|
|
|
str::slice(line, colon + str::byte_len(keycolon),
|
|
|
|
str::byte_len(line));
|
2011-09-01 20:49:10 -05:00
|
|
|
log #fmt("%s: %s", directive,
|
2011-08-28 02:24:28 -05:00
|
|
|
value);
|
2011-07-30 23:11:14 -05:00
|
|
|
option::some(value)
|
|
|
|
} else { option::none }
|
|
|
|
}
|