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-09-02 17:34:58 -05:00
|
|
|
error_patterns: [str],
|
2011-08-01 16:10:59 -05:00
|
|
|
// Extra flags to pass to the compiler
|
2011-09-02 17:34:58 -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-09-07 19:16:04 -05:00
|
|
|
pp_exact: option::t<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
|
2011-09-12 04:27:30 -05:00
|
|
|
fn load_props(testfile: str) -> 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-10-21 06:14:28 -05:00
|
|
|
iter_header(testfile) {|ln|
|
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. { }
|
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);
|
|
|
|
}
|
2011-10-21 06:14:28 -05:00
|
|
|
};
|
2011-08-01 16:10:59 -05:00
|
|
|
ret {
|
|
|
|
error_patterns: error_patterns,
|
|
|
|
compile_flags: compile_flags,
|
2011-09-07 19:16:04 -05:00
|
|
|
pp_exact: pp_exact
|
2011-08-01 16:10:59 -05:00
|
|
|
};
|
2011-07-30 23:11:14 -05:00
|
|
|
}
|
|
|
|
|
2011-09-12 04:27:30 -05:00
|
|
|
fn is_test_ignored(config: config, testfile: str) -> bool {
|
2011-07-30 23:11:14 -05:00
|
|
|
let found = false;
|
2011-10-21 06:14:28 -05:00
|
|
|
iter_header(testfile) {|ln|
|
2011-07-30 23:11:14 -05:00
|
|
|
// FIXME: Can't return or break from iterator
|
2011-09-02 17:34:58 -05:00
|
|
|
found = found || parse_name_directive(ln, "xfail-test");
|
2011-09-09 15:24:06 -05:00
|
|
|
found = found || parse_name_directive(ln, xfail_target());
|
2011-08-01 13:23:58 -05:00
|
|
|
if (config.mode == common::mode_pretty) {
|
2011-09-02 17:34:58 -05:00
|
|
|
found = found || parse_name_directive(ln, "xfail-pretty");
|
2011-08-01 13:23:58 -05:00
|
|
|
}
|
2011-10-21 06:14:28 -05:00
|
|
|
};
|
2011-07-30 23:11:14 -05:00
|
|
|
ret found;
|
2011-09-09 15:24:06 -05:00
|
|
|
|
|
|
|
fn xfail_target() -> str {
|
|
|
|
"xfail-" + std::os::target_os()
|
|
|
|
}
|
2011-07-30 23:11:14 -05:00
|
|
|
}
|
|
|
|
|
2011-10-21 06:14:28 -05:00
|
|
|
fn iter_header(testfile: str, it: block(str)) {
|
2011-10-28 23:19:59 -05:00
|
|
|
let rdr = std::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.
|
2011-09-02 17:34:58 -05:00
|
|
|
if str::starts_with(ln, "fn")
|
|
|
|
|| str::starts_with(ln, "mod") {
|
2011-07-30 23:11:14 -05:00
|
|
|
break;
|
2011-10-21 06:14:28 -05:00
|
|
|
} else { it(ln); }
|
2011-07-30 23:11:14 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-09-12 04:27:30 -05:00
|
|
|
fn parse_error_pattern(line: str) -> option::t<str> {
|
2011-09-02 17:34:58 -05:00
|
|
|
parse_name_value_directive(line, "error-pattern")
|
2011-07-30 23:11:14 -05:00
|
|
|
}
|
|
|
|
|
2011-09-12 04:27:30 -05:00
|
|
|
fn parse_compile_flags(line: str) -> option::t<str> {
|
2011-09-02 17:34:58 -05:00
|
|
|
parse_name_value_directive(line, "compile-flags")
|
2011-07-30 23:11:14 -05:00
|
|
|
}
|
|
|
|
|
2011-09-12 04:27:30 -05:00
|
|
|
fn parse_pp_exact(line: str, testfile: str) -> option::t<str> {
|
2011-09-02 17:34:58 -05:00
|
|
|
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-09-02 17:34:58 -05:00
|
|
|
if parse_name_directive(line, "pp-exact") {
|
2011-08-30 17:40:25 -05:00
|
|
|
option::some(fs::basename(testfile))
|
2011-08-01 16:10:59 -05:00
|
|
|
} else {
|
|
|
|
option::none
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-09-12 04:27:30 -05:00
|
|
|
fn parse_name_directive(line: str, directive: str) -> bool {
|
2011-09-01 19:27:58 -05:00
|
|
|
str::find(line, directive) >= 0
|
2011-07-30 23:11:14 -05:00
|
|
|
}
|
|
|
|
|
2011-09-12 04:27:30 -05:00
|
|
|
fn parse_name_value_directive(line: str,
|
|
|
|
directive: str) -> option::t<str> {
|
2011-09-02 17:34:58 -05:00
|
|
|
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 }
|
|
|
|
}
|