2011-08-11 21:14:38 -05:00
|
|
|
import std::io;
|
2011-09-01 19:27:58 -05:00
|
|
|
import std::str;
|
2011-07-30 23:11:14 -05:00
|
|
|
import std::option;
|
|
|
|
import std::fs;
|
|
|
|
import std::os;
|
2011-08-15 18:38:23 -05:00
|
|
|
import std::vec;
|
2011-07-30 23:11:14 -05:00
|
|
|
import std::test;
|
|
|
|
|
|
|
|
import common::mode_run_pass;
|
|
|
|
import common::mode_run_fail;
|
|
|
|
import common::mode_compile_fail;
|
2011-07-30 23:44:30 -05:00
|
|
|
import common::mode_pretty;
|
2011-07-30 23:11:14 -05:00
|
|
|
import common::cx;
|
|
|
|
import common::config;
|
|
|
|
import header::load_props;
|
|
|
|
import header::test_props;
|
|
|
|
import util::logv;
|
|
|
|
|
|
|
|
export run;
|
|
|
|
|
2011-09-12 05:39:38 -05:00
|
|
|
fn run(cx: cx, -_testfile: [u8]) {
|
2011-09-01 19:27:58 -05:00
|
|
|
let testfile = str::unsafe_from_bytes(_testfile);
|
2011-08-19 17:16:48 -05:00
|
|
|
if cx.config.verbose {
|
2011-07-30 23:11:14 -05:00
|
|
|
// We're going to be dumping a lot of info. Start on a new line.
|
2011-09-02 17:34:58 -05:00
|
|
|
io::stdout().write_str("\n\n");
|
2011-07-30 23:11:14 -05:00
|
|
|
}
|
2011-09-01 20:49:10 -05:00
|
|
|
log #fmt["running %s", testfile];
|
2011-07-30 23:11:14 -05:00
|
|
|
let props = load_props(testfile);
|
|
|
|
alt cx.config.mode {
|
|
|
|
mode_compile_fail. { run_cfail_test(cx, props, testfile); }
|
|
|
|
mode_run_fail. { run_rfail_test(cx, props, testfile); }
|
|
|
|
mode_run_pass. { run_rpass_test(cx, props, testfile); }
|
2011-07-30 23:44:30 -05:00
|
|
|
mode_pretty. { run_pretty_test(cx, props, testfile); }
|
2011-07-30 23:11:14 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-09-12 04:27:30 -05:00
|
|
|
fn run_cfail_test(cx: cx, props: test_props, testfile: str) {
|
2011-07-30 23:11:14 -05:00
|
|
|
let procres = compile_test(cx, props, testfile);
|
|
|
|
|
|
|
|
if procres.status == 0 {
|
2011-09-02 17:34:58 -05:00
|
|
|
fatal_procres("compile-fail test compiled successfully!", procres);
|
2011-07-30 23:11:14 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
check_error_patterns(props, testfile, procres);
|
|
|
|
}
|
|
|
|
|
2011-09-12 04:27:30 -05:00
|
|
|
fn run_rfail_test(cx: cx, props: test_props, testfile: str) {
|
2011-07-30 23:11:14 -05:00
|
|
|
let procres = compile_test(cx, props, testfile);
|
|
|
|
|
2011-09-02 17:34:58 -05:00
|
|
|
if procres.status != 0 { fatal_procres("compilation failed!", procres); }
|
2011-07-30 23:11:14 -05:00
|
|
|
|
2011-08-10 15:36:57 -05:00
|
|
|
procres = exec_compiled_test(cx, props, testfile);
|
2011-07-30 23:11:14 -05:00
|
|
|
|
2011-09-08 15:42:04 -05:00
|
|
|
// The value our Makefile configures valgrind to return on failure
|
2011-09-08 15:28:03 -05:00
|
|
|
const valgrind_err: int = 100;
|
2011-08-10 15:36:57 -05:00
|
|
|
if procres.status == valgrind_err {
|
2011-09-02 17:34:58 -05:00
|
|
|
fatal_procres("run-fail test isn't valgrind-clean!", procres);
|
2011-08-10 15:36:57 -05:00
|
|
|
}
|
|
|
|
|
2011-09-08 15:42:04 -05:00
|
|
|
// The value the rust runtime returns on failure
|
|
|
|
const rust_err: int = 101;
|
|
|
|
if procres.status != rust_err {
|
|
|
|
fatal_procres(
|
2011-09-19 18:08:06 -05:00
|
|
|
#fmt("run-fail test produced the wrong error code: %d",
|
2011-09-08 15:42:04 -05:00
|
|
|
procres.status),
|
|
|
|
procres);
|
|
|
|
}
|
2011-09-19 18:08:06 -05:00
|
|
|
|
|
|
|
check_error_patterns(props, testfile, procres);
|
2011-07-30 23:11:14 -05:00
|
|
|
}
|
|
|
|
|
2011-09-12 04:27:30 -05:00
|
|
|
fn run_rpass_test(cx: cx, props: test_props, testfile: str) {
|
2011-07-30 23:11:14 -05:00
|
|
|
let procres = compile_test(cx, props, testfile);
|
|
|
|
|
2011-09-02 17:34:58 -05:00
|
|
|
if procres.status != 0 { fatal_procres("compilation failed!", procres); }
|
2011-07-30 23:11:14 -05:00
|
|
|
|
2011-08-10 15:36:57 -05:00
|
|
|
procres = exec_compiled_test(cx, props, testfile);
|
2011-07-30 23:11:14 -05:00
|
|
|
|
|
|
|
|
2011-09-02 17:34:58 -05:00
|
|
|
if procres.status != 0 { fatal_procres("test run failed!", procres); }
|
2011-07-30 23:11:14 -05:00
|
|
|
}
|
|
|
|
|
2011-09-12 04:27:30 -05:00
|
|
|
fn run_pretty_test(cx: cx, props: test_props, testfile: str) {
|
2011-08-01 16:10:59 -05:00
|
|
|
if option::is_some(props.pp_exact) {
|
2011-09-02 17:34:58 -05:00
|
|
|
logv(cx.config, "testing for exact pretty-printing");
|
|
|
|
} else { logv(cx.config, "testing for converging pretty-printing"); }
|
2011-08-01 16:10:59 -05:00
|
|
|
|
2011-08-19 17:16:48 -05:00
|
|
|
let rounds =
|
|
|
|
alt props.pp_exact { option::some(_) { 1 } option::none. { 2 } };
|
2011-07-31 17:33:40 -05:00
|
|
|
|
2011-08-30 17:40:25 -05:00
|
|
|
let srcs = [io::read_whole_file_str(testfile)];
|
2011-07-31 17:33:40 -05:00
|
|
|
|
|
|
|
let round = 0;
|
|
|
|
while round < rounds {
|
2011-09-01 20:49:10 -05:00
|
|
|
logv(cx.config, #fmt["pretty-printing round %d", round]);
|
2011-08-19 17:16:48 -05:00
|
|
|
let procres = print_source(cx, testfile, srcs[round]);
|
2011-07-31 17:33:40 -05:00
|
|
|
|
|
|
|
if procres.status != 0 {
|
2011-09-02 17:34:58 -05:00
|
|
|
fatal_procres(#fmt["pretty-printing failed in round %d", round],
|
|
|
|
procres);
|
2011-07-31 17:33:40 -05:00
|
|
|
}
|
|
|
|
|
2011-08-19 17:16:48 -05:00
|
|
|
srcs += [procres.stdout];
|
2011-07-31 17:33:40 -05:00
|
|
|
round += 1;
|
|
|
|
}
|
|
|
|
|
2011-08-19 17:16:48 -05:00
|
|
|
let expected =
|
|
|
|
alt props.pp_exact {
|
|
|
|
option::some(file) {
|
2011-08-30 17:40:25 -05:00
|
|
|
let filepath = fs::connect(fs::dirname(testfile), file);
|
|
|
|
io::read_whole_file_str(filepath)
|
2011-08-19 17:16:48 -05:00
|
|
|
}
|
|
|
|
option::none. { srcs[vec::len(srcs) - 2u] }
|
|
|
|
};
|
|
|
|
let actual = srcs[vec::len(srcs) - 1u];
|
2011-08-03 18:25:38 -05:00
|
|
|
|
2011-08-03 17:36:45 -05:00
|
|
|
if option::is_some(props.pp_exact) {
|
|
|
|
// Now we have to care about line endings
|
2011-09-02 17:34:58 -05:00
|
|
|
let cr = "\r";
|
2011-09-01 19:27:58 -05:00
|
|
|
check (str::is_not_empty(cr));
|
2011-09-02 17:34:58 -05:00
|
|
|
actual = str::replace(actual, cr, "");
|
|
|
|
expected = str::replace(expected, cr, "");
|
2011-08-03 17:36:45 -05:00
|
|
|
}
|
2011-07-31 17:33:40 -05:00
|
|
|
|
|
|
|
compare_source(expected, actual);
|
|
|
|
|
|
|
|
// Finally, let's make sure it actually appears to remain valid code
|
2011-07-31 21:12:33 -05:00
|
|
|
let procres = typecheck_source(cx, testfile, actual);
|
2011-07-31 17:33:40 -05:00
|
|
|
|
|
|
|
if procres.status != 0 {
|
2011-09-02 17:34:58 -05:00
|
|
|
fatal_procres("pretty-printed source does not typecheck", procres);
|
2011-07-31 17:33:40 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
ret;
|
|
|
|
|
2011-09-12 04:27:30 -05:00
|
|
|
fn print_source(cx: cx, testfile: str, src: str) -> procres {
|
2011-07-31 17:33:40 -05:00
|
|
|
compose_and_run(cx, testfile, make_pp_args,
|
|
|
|
cx.config.compile_lib_path, option::some(src))
|
|
|
|
}
|
|
|
|
|
2011-09-12 04:27:30 -05:00
|
|
|
fn make_pp_args(config: config, _testfile: str) -> procargs {
|
2011-08-30 17:40:25 -05:00
|
|
|
let prog = config.rustc_path;
|
2011-09-02 17:34:58 -05:00
|
|
|
let args = ["-", "--pretty", "normal"];
|
2011-07-31 17:33:40 -05:00
|
|
|
ret {prog: prog, args: args};
|
|
|
|
}
|
|
|
|
|
2011-09-12 04:27:30 -05:00
|
|
|
fn compare_source(expected: str, actual: str) {
|
2011-07-31 17:33:40 -05:00
|
|
|
if expected != actual {
|
2011-09-02 17:34:58 -05:00
|
|
|
error("pretty-printed source does match expected source");
|
2011-08-19 17:16:48 -05:00
|
|
|
let msg =
|
2011-09-01 20:49:10 -05:00
|
|
|
#fmt["\n\
|
2011-07-31 17:33:40 -05:00
|
|
|
expected:\n\
|
|
|
|
------------------------------------------\n\
|
|
|
|
%s\n\
|
|
|
|
------------------------------------------\n\
|
|
|
|
actual:\n\
|
|
|
|
------------------------------------------\n\
|
|
|
|
%s\n\
|
|
|
|
------------------------------------------\n\
|
|
|
|
\n",
|
2011-09-02 17:34:58 -05:00
|
|
|
expected, actual];
|
2011-08-28 02:24:28 -05:00
|
|
|
io::stdout().write_str(msg);
|
2011-07-31 17:33:40 -05:00
|
|
|
fail;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-09-12 04:27:30 -05:00
|
|
|
fn typecheck_source(cx: cx, testfile: str, src: str) -> procres {
|
2011-07-31 21:12:33 -05:00
|
|
|
compose_and_run(cx, testfile, make_typecheck_args,
|
|
|
|
cx.config.compile_lib_path, option::some(src))
|
|
|
|
}
|
|
|
|
|
2011-09-12 04:27:30 -05:00
|
|
|
fn make_typecheck_args(config: config, _testfile: str) -> procargs {
|
2011-08-30 17:40:25 -05:00
|
|
|
let prog = config.rustc_path;
|
2011-09-02 17:34:58 -05:00
|
|
|
let args = ["-", "--no-trans", "--lib"];
|
2011-07-31 21:12:33 -05:00
|
|
|
ret {prog: prog, args: args};
|
2011-07-31 17:33:40 -05:00
|
|
|
}
|
2011-07-30 23:44:30 -05:00
|
|
|
}
|
|
|
|
|
2011-09-12 04:27:30 -05:00
|
|
|
fn check_error_patterns(props: test_props, testfile: str, procres: procres) {
|
2011-08-15 18:38:23 -05:00
|
|
|
if vec::is_empty(props.error_patterns) {
|
2011-09-02 17:34:58 -05:00
|
|
|
fatal("no error pattern specified in " + testfile);
|
2011-07-30 23:11:14 -05:00
|
|
|
}
|
|
|
|
|
2011-08-24 15:24:03 -05:00
|
|
|
if procres.status == 0 {
|
2011-09-02 17:34:58 -05:00
|
|
|
fatal("process did not return an error status");
|
2011-08-24 15:24:03 -05:00
|
|
|
}
|
|
|
|
|
2011-07-30 23:11:14 -05:00
|
|
|
let next_err_idx = 0u;
|
2011-08-19 17:16:48 -05:00
|
|
|
let next_err_pat = props.error_patterns[next_err_idx];
|
2011-09-02 17:34:58 -05:00
|
|
|
for line: str in str::split(procres.stdout, '\n' as u8) {
|
2011-09-01 19:27:58 -05:00
|
|
|
if str::find(line, next_err_pat) > 0 {
|
2011-09-02 17:34:58 -05:00
|
|
|
log #fmt["found error pattern %s", next_err_pat];
|
2011-07-30 23:11:14 -05:00
|
|
|
next_err_idx += 1u;
|
2011-08-15 18:38:23 -05:00
|
|
|
if next_err_idx == vec::len(props.error_patterns) {
|
2011-07-30 23:11:14 -05:00
|
|
|
log "found all error patterns";
|
|
|
|
ret;
|
|
|
|
}
|
2011-08-19 17:16:48 -05:00
|
|
|
next_err_pat = props.error_patterns[next_err_idx];
|
2011-07-30 23:11:14 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
let missing_patterns =
|
2011-08-15 18:38:23 -05:00
|
|
|
vec::slice(props.error_patterns, next_err_idx,
|
2011-08-19 17:16:48 -05:00
|
|
|
vec::len(props.error_patterns));
|
2011-08-15 18:38:23 -05:00
|
|
|
if vec::len(missing_patterns) == 1u {
|
2011-09-02 17:34:58 -05:00
|
|
|
fatal_procres(#fmt["error pattern '%s' not found!",
|
|
|
|
missing_patterns[0]], procres);
|
2011-07-30 23:11:14 -05:00
|
|
|
} else {
|
2011-09-02 17:34:58 -05:00
|
|
|
for pattern: str in missing_patterns {
|
|
|
|
error(#fmt["error pattern '%s' not found!", pattern]);
|
2011-07-30 23:11:14 -05:00
|
|
|
}
|
2011-09-02 17:34:58 -05:00
|
|
|
fatal_procres("multiple error patterns not found", procres);
|
2011-07-30 23:11:14 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-09-02 17:34:58 -05:00
|
|
|
type procargs = {prog: str, args: [str]};
|
2011-07-30 23:11:14 -05:00
|
|
|
|
2011-09-02 17:34:58 -05:00
|
|
|
type procres = {status: int, stdout: str, stderr: str, cmdline: str};
|
2011-07-30 23:11:14 -05:00
|
|
|
|
2011-09-12 04:27:30 -05:00
|
|
|
fn compile_test(cx: cx, props: test_props, testfile: str) -> procres {
|
2011-07-30 23:11:14 -05:00
|
|
|
compose_and_run(cx, testfile, bind make_compile_args(_, props, _),
|
2011-07-31 17:33:40 -05:00
|
|
|
cx.config.compile_lib_path, option::none)
|
2011-07-30 23:11:14 -05:00
|
|
|
}
|
|
|
|
|
2011-09-12 04:27:30 -05:00
|
|
|
fn exec_compiled_test(cx: cx, props: test_props, testfile: str) -> procres {
|
2011-08-10 15:36:57 -05:00
|
|
|
compose_and_run(cx, testfile, bind make_run_args(_, props, _),
|
2011-07-31 17:33:40 -05:00
|
|
|
cx.config.run_lib_path, option::none)
|
2011-07-30 23:11:14 -05:00
|
|
|
}
|
|
|
|
|
2011-09-12 04:27:30 -05:00
|
|
|
fn compose_and_run(cx: cx, testfile: str,
|
|
|
|
make_args: fn(config, str) -> procargs, lib_path: str,
|
2011-09-02 17:34:58 -05:00
|
|
|
input: option::t<str>) -> procres {
|
2011-07-30 23:11:14 -05:00
|
|
|
let procargs = make_args(cx.config, testfile);
|
2011-08-19 17:16:48 -05:00
|
|
|
ret program_output(cx, testfile, lib_path, procargs.prog, procargs.args,
|
2011-07-31 17:33:40 -05:00
|
|
|
input);
|
2011-07-30 23:11:14 -05:00
|
|
|
}
|
|
|
|
|
2011-09-12 04:27:30 -05:00
|
|
|
fn make_compile_args(config: config, props: test_props, testfile: str) ->
|
2011-08-19 17:16:48 -05:00
|
|
|
procargs {
|
2011-08-30 17:40:25 -05:00
|
|
|
let prog = config.rustc_path;
|
2011-09-02 17:34:58 -05:00
|
|
|
let args = [testfile, "-o", make_exe_name(config, testfile)];
|
|
|
|
let rustcflags =
|
|
|
|
alt config.rustcflags {
|
|
|
|
option::some(s) { option::some(s) }
|
|
|
|
option::none. { option::none }
|
|
|
|
};
|
2011-08-24 20:01:10 -05:00
|
|
|
args += split_maybe_args(rustcflags);
|
2011-07-30 23:11:14 -05:00
|
|
|
args += split_maybe_args(props.compile_flags);
|
|
|
|
ret {prog: prog, args: args};
|
|
|
|
}
|
|
|
|
|
2011-09-12 04:27:30 -05:00
|
|
|
fn make_exe_name(config: config, testfile: str) -> str {
|
2011-08-30 17:40:25 -05:00
|
|
|
output_base_name(config, testfile) + os::exec_suffix()
|
2011-07-30 23:11:14 -05:00
|
|
|
}
|
|
|
|
|
2011-09-12 11:36:51 -05:00
|
|
|
fn make_run_args(config: config, _props: test_props, testfile: str) ->
|
2011-08-19 17:16:48 -05:00
|
|
|
procargs {
|
2011-09-07 19:16:04 -05:00
|
|
|
let toolargs = {
|
2011-09-02 17:34:58 -05:00
|
|
|
// If we've got another tool to run under (valgrind),
|
|
|
|
// then split apart its command
|
|
|
|
let runtool =
|
|
|
|
alt config.runtool {
|
|
|
|
option::some(s) { option::some(s) }
|
|
|
|
option::none. { option::none }
|
|
|
|
};
|
|
|
|
split_maybe_args(runtool)
|
2011-09-07 19:16:04 -05:00
|
|
|
};
|
2011-08-19 17:16:48 -05:00
|
|
|
|
|
|
|
let args = toolargs + [make_exe_name(config, testfile)];
|
|
|
|
ret {prog: args[0], args: vec::slice(args, 1u, vec::len(args))};
|
2011-07-30 23:11:14 -05:00
|
|
|
}
|
|
|
|
|
2011-09-12 04:27:30 -05:00
|
|
|
fn split_maybe_args(argstr: option::t<str>) -> [str] {
|
|
|
|
fn rm_whitespace(v: [str]) -> [str] {
|
|
|
|
fn flt(s: str) -> option::t<str> {
|
2011-08-19 17:16:48 -05:00
|
|
|
if !is_whitespace(s) { option::some(s) } else { option::none }
|
2011-07-30 23:11:14 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// FIXME: This should be in std
|
2011-09-12 04:27:30 -05:00
|
|
|
fn is_whitespace(s: str) -> bool {
|
2011-08-19 17:16:48 -05:00
|
|
|
for c: u8 in s { if c != ' ' as u8 { ret false; } }
|
2011-07-30 23:11:14 -05:00
|
|
|
ret true;
|
|
|
|
}
|
2011-08-15 18:38:23 -05:00
|
|
|
vec::filter_map(flt, v)
|
2011-07-30 23:11:14 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
alt argstr {
|
2011-09-01 19:27:58 -05:00
|
|
|
option::some(s) { rm_whitespace(str::split(s, ' ' as u8)) }
|
2011-08-19 17:16:48 -05:00
|
|
|
option::none. { [] }
|
2011-07-30 23:11:14 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-09-12 04:27:30 -05:00
|
|
|
fn program_output(cx: cx, testfile: str, lib_path: str, prog: str,
|
|
|
|
args: [str], input: option::t<str>) -> procres {
|
2011-07-30 23:11:14 -05:00
|
|
|
let cmdline =
|
2011-08-19 17:16:48 -05:00
|
|
|
{
|
|
|
|
let cmdline = make_cmdline(lib_path, prog, args);
|
2011-09-02 17:34:58 -05:00
|
|
|
logv(cx.config, #fmt["executing %s", cmdline]);
|
2011-08-19 17:16:48 -05:00
|
|
|
cmdline
|
|
|
|
};
|
|
|
|
let res = procsrv::run(cx.procsrv, lib_path, prog, args, input);
|
2011-07-30 23:11:14 -05:00
|
|
|
dump_output(cx.config, testfile, res.out, res.err);
|
2011-08-19 17:16:48 -05:00
|
|
|
ret {status: res.status,
|
|
|
|
stdout: res.out,
|
|
|
|
stderr: res.err,
|
|
|
|
cmdline: cmdline};
|
2011-07-30 23:11:14 -05:00
|
|
|
}
|
|
|
|
|
2011-09-12 04:27:30 -05:00
|
|
|
fn make_cmdline(libpath: str, prog: str, args: [str]) -> str {
|
2011-09-02 17:34:58 -05:00
|
|
|
#fmt["%s %s %s", lib_path_cmd_prefix(libpath), prog,
|
|
|
|
str::connect(args, " ")]
|
2011-07-30 23:11:14 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// Build the LD_LIBRARY_PATH variable as it would be seen on the command line
|
|
|
|
// for diagnostic purposes
|
2011-09-12 04:27:30 -05:00
|
|
|
fn lib_path_cmd_prefix(path: str) -> str {
|
2011-09-02 17:34:58 -05:00
|
|
|
#fmt["%s=\"%s\"", util::lib_path_env_var(), util::make_new_path(path)]
|
2011-07-30 23:11:14 -05:00
|
|
|
}
|
|
|
|
|
2011-09-12 04:27:30 -05:00
|
|
|
fn dump_output(config: config, testfile: str, out: str, err: str) {
|
2011-09-02 17:34:58 -05:00
|
|
|
dump_output_file(config, testfile, out, "out");
|
|
|
|
dump_output_file(config, testfile, err, "err");
|
2011-07-30 23:11:14 -05:00
|
|
|
maybe_dump_to_stdout(config, out, err);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[cfg(target_os = "win32")]
|
|
|
|
#[cfg(target_os = "linux")]
|
2011-09-12 04:27:30 -05:00
|
|
|
fn dump_output_file(config: config, testfile: str, out: str, extension: str) {
|
2011-07-30 23:11:14 -05:00
|
|
|
let outfile = make_out_name(config, testfile, extension);
|
2011-09-02 17:34:58 -05:00
|
|
|
let writer = io::file_writer(outfile, [io::create, io::truncate]);
|
2011-08-30 17:40:25 -05:00
|
|
|
writer.write_str(out);
|
2011-07-30 23:11:14 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// FIXME (726): Can't use file_writer on mac
|
|
|
|
#[cfg(target_os = "macos")]
|
2011-09-12 04:27:30 -05:00
|
|
|
fn dump_output_file(config: config, testfile: str, out: str, extension: str) {
|
2011-07-30 23:11:14 -05:00
|
|
|
}
|
|
|
|
|
2011-09-12 04:27:30 -05:00
|
|
|
fn make_out_name(config: config, testfile: str, extension: str) -> str {
|
2011-09-02 17:34:58 -05:00
|
|
|
output_base_name(config, testfile) + "." + extension
|
2011-07-30 23:11:14 -05:00
|
|
|
}
|
|
|
|
|
2011-09-12 04:27:30 -05:00
|
|
|
fn output_base_name(config: config, testfile: str) -> str {
|
2011-08-30 17:40:25 -05:00
|
|
|
let base = config.build_base;
|
2011-07-30 23:11:14 -05:00
|
|
|
let filename =
|
|
|
|
{
|
2011-09-02 17:34:58 -05:00
|
|
|
let parts = str::split(fs::basename(testfile), '.' as u8);
|
2011-08-15 18:38:23 -05:00
|
|
|
parts = vec::slice(parts, 0u, vec::len(parts) - 1u);
|
2011-09-02 17:34:58 -05:00
|
|
|
str::connect(parts, ".")
|
2011-07-30 23:11:14 -05:00
|
|
|
};
|
2011-09-02 17:34:58 -05:00
|
|
|
#fmt["%s%s.%s", base, filename, config.stage_id]
|
2011-07-30 23:11:14 -05:00
|
|
|
}
|
|
|
|
|
2011-09-12 04:27:30 -05:00
|
|
|
fn maybe_dump_to_stdout(config: config, out: str, err: str) {
|
2011-07-30 23:11:14 -05:00
|
|
|
if config.verbose {
|
2011-09-02 17:34:58 -05:00
|
|
|
let sep1 = #fmt["------%s------------------------------", "stdout"];
|
|
|
|
let sep2 = #fmt["------%s------------------------------", "stderr"];
|
|
|
|
let sep3 = "------------------------------------------";
|
2011-08-28 02:24:28 -05:00
|
|
|
io::stdout().write_line(sep1);
|
2011-08-30 17:40:25 -05:00
|
|
|
io::stdout().write_line(out);
|
2011-08-28 02:24:28 -05:00
|
|
|
io::stdout().write_line(sep2);
|
2011-08-30 17:40:25 -05:00
|
|
|
io::stdout().write_line(err);
|
|
|
|
io::stdout().write_line(sep3);
|
2011-07-30 23:11:14 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-09-12 04:27:30 -05:00
|
|
|
fn error(err: str) { io::stdout().write_line(#fmt["\nerror: %s", err]); }
|
2011-07-30 23:11:14 -05:00
|
|
|
|
2011-09-12 04:27:30 -05:00
|
|
|
fn fatal(err: str) -> ! { error(err); fail; }
|
2011-07-30 23:11:14 -05:00
|
|
|
|
2011-09-12 04:27:30 -05:00
|
|
|
fn fatal_procres(err: str, procres: procres) -> ! {
|
2011-07-30 23:11:14 -05:00
|
|
|
let msg =
|
2011-09-01 20:49:10 -05:00
|
|
|
#fmt["\n\
|
2011-07-30 23:11:14 -05:00
|
|
|
error: %s\n\
|
|
|
|
command: %s\n\
|
|
|
|
stdout:\n\
|
|
|
|
------------------------------------------\n\
|
|
|
|
%s\n\
|
|
|
|
------------------------------------------\n\
|
|
|
|
stderr:\n\
|
|
|
|
------------------------------------------\n\
|
|
|
|
%s\n\
|
|
|
|
------------------------------------------\n\
|
|
|
|
\n",
|
2011-09-02 17:34:58 -05:00
|
|
|
err, procres.cmdline, procres.stdout, procres.stderr];
|
2011-08-11 21:14:38 -05:00
|
|
|
io::stdout().write_str(msg);
|
2011-07-30 23:11:14 -05:00
|
|
|
fail;
|
|
|
|
}
|