Convert the task-comm parts of compiletest to istrs. Issue #855

This reduces the amount of voodoo in compiletest considerably.
This commit is contained in:
Brian Anderson 2011-08-24 18:01:10 -07:00
parent c2eafd268b
commit 3a5f4e7a74
4 changed files with 108 additions and 61 deletions

View File

@ -16,17 +16,17 @@ type config =
// for running under valgrind
// Flags to pass to the compiler
// Explain what's going on
{compile_lib_path: str,
run_lib_path: str,
rustc_path: str,
src_base: str,
build_base: str,
stage_id: str,
{compile_lib_path: istr,
run_lib_path: istr,
rustc_path: istr,
src_base: istr,
build_base: istr,
stage_id: istr,
mode: mode,
run_ignored: bool,
filter: option::t<str>,
runtool: option::t<str>,
rustcflags: option::t<str>,
filter: option::t<istr>,
runtool: option::t<istr>,
rustcflags: option::t<istr>,
verbose: bool};
type cx = {config: config, procsrv: procsrv::handle};

View File

@ -46,32 +46,41 @@ fn parse_config(args: &[str]) -> config {
getopts::failure(f) { fail getopts::fail_str(f) }
};
ret {compile_lib_path: getopts::opt_str(match, "compile-lib-path"),
run_lib_path: getopts::opt_str(match, "run-lib-path"),
rustc_path: getopts::opt_str(match, "rustc-path"),
src_base: getopts::opt_str(match, "src-base"),
build_base: getopts::opt_str(match, "build-base"),
stage_id: getopts::opt_str(match, "stage-id"),
let cnv = istr::from_estr;
let cnvo = fn(o: &option::t<str>) -> option::t<istr> {
alt o {
option::some(s) { option::some(istr::from_estr(s)) }
option::none. { option::none }
}
};
ret {compile_lib_path: cnv(getopts::opt_str(match, "compile-lib-path")),
run_lib_path: cnv(getopts::opt_str(match, "run-lib-path")),
rustc_path: cnv(getopts::opt_str(match, "rustc-path")),
src_base: cnv(getopts::opt_str(match, "src-base")),
build_base: cnv(getopts::opt_str(match, "build-base")),
stage_id: cnv(getopts::opt_str(match, "stage-id")),
mode: str_mode(getopts::opt_str(match, "mode")),
run_ignored: getopts::opt_present(match, "ignored"),
filter:
if vec::len(match.free) > 0u {
option::some(match.free[0])
option::some(cnv(match.free[0]))
} else { option::none },
runtool: getopts::opt_maybe_str(match, "runtool"),
rustcflags: getopts::opt_maybe_str(match, "rustcflags"),
runtool: cnvo(getopts::opt_maybe_str(match, "runtool")),
rustcflags: cnvo(getopts::opt_maybe_str(match, "rustcflags")),
verbose: getopts::opt_present(match, "verbose")};
}
fn log_config(config: &config) {
let c = config;
logv(c, #fmt["configuration:"]);
logv(c, #fmt["compile_lib_path: %s", config.compile_lib_path]);
logv(c, #fmt["run_lib_path: %s", config.run_lib_path]);
logv(c, #fmt["rustc_path: %s", config.rustc_path]);
logv(c, #fmt["src_base: %s", config.src_base]);
logv(c, #fmt["build_base: %s", config.build_base]);
logv(c, #fmt["stage_id: %s", config.stage_id]);
logv(c, #fmt["compile_lib_path: %s",
istr::to_estr(config.compile_lib_path)]);
logv(c, #fmt["run_lib_path: %s", istr::to_estr(config.run_lib_path)]);
logv(c, #fmt["rustc_path: %s", istr::to_estr(config.rustc_path)]);
logv(c, #fmt["src_base: %s", istr::to_estr(config.src_base)]);
logv(c, #fmt["build_base: %s", istr::to_estr(config.build_base)]);
logv(c, #fmt["stage_id: %s", istr::to_estr(config.stage_id)]);
logv(c, #fmt["mode: %s", mode_str(config.mode)]);
logv(c, #fmt["run_ignored: %b", config.run_ignored]);
logv(c, #fmt["filter: %s", opt_str(config.filter)]);
@ -81,12 +90,15 @@ fn log_config(config: &config) {
logv(c, #fmt["\n"]);
}
fn opt_str(maybestr: option::t<str>) -> str {
alt maybestr { option::some(s) { s } option::none. { "(none)" } }
fn opt_str(maybestr: option::t<istr>) -> str {
alt maybestr {
option::some(s) { istr::to_estr(s) }
option::none. { "(none)" }
}
}
fn str_opt(maybestr: str) -> option::t<str> {
if maybestr != "(none)" { option::some(maybestr) } else { option::none }
fn str_opt(maybestr: &istr) -> option::t<istr> {
if maybestr != ~"(none)" { option::some(maybestr) } else { option::none }
}
fn str_mode(s: str) -> mode {
@ -117,17 +129,23 @@ fn run_tests(config: &config) {
}
fn test_opts(config: &config) -> test::test_opts {
{filter: config.filter, run_ignored: config.run_ignored}
{
filter: alt config.filter {
option::some(s) { option::some(istr::to_estr(s)) }
option::none. { option::none }
},
run_ignored: config.run_ignored
}
}
type tests_and_conv_fn =
{tests: [test::test_desc], to_task: fn(&fn()) -> test::joinable};
fn make_tests(cx: &cx) -> tests_and_conv_fn {
log #fmt["making tests from %s", cx.config.src_base];
log #fmt["making tests from %s", istr::to_estr(cx.config.src_base)];
let configport = port::<[u8]>();
let tests = [];
for file: istr in fs::list_dir(istr::from_estr(cx.config.src_base)) {
for file: istr in fs::list_dir(cx.config.src_base) {
let file = istr::to_estr(file);
log #fmt["inspecting file %s", file];
if is_test(cx.config, file) {
@ -212,23 +230,43 @@ fn closure_to_task(cx: cx, configport: port<[u8]>, testfn: &fn()) ->
test::joinable {
testfn();
let testfile = recv(configport);
let compile_lib_path = cx.config.compile_lib_path;
let run_lib_path = cx.config.run_lib_path;
let rustc_path = cx.config.rustc_path;
let src_base = cx.config.src_base;
let build_base = cx.config.build_base;
let stage_id = cx.config.stage_id;
let mode = istr::from_estr(mode_str(cx.config.mode));
let run_ignored = cx.config.run_ignored;
let filter = istr::from_estr(opt_str(cx.config.filter));
let runtool = istr::from_estr(opt_str(cx.config.runtool));
let rustcflags = istr::from_estr(opt_str(cx.config.rustcflags));
let verbose = cx.config.verbose;
let chan = cx.procsrv.chan;
let testthunk =
bind run_test_task(cx.config.compile_lib_path, cx.config.run_lib_path,
cx.config.rustc_path, cx.config.src_base,
cx.config.build_base, cx.config.stage_id,
mode_str(cx.config.mode), cx.config.run_ignored,
opt_str(cx.config.filter),
opt_str(cx.config.runtool),
opt_str(cx.config.rustcflags), cx.config.verbose,
cx.procsrv.chan, testfile);
bind run_test_task(compile_lib_path, run_lib_path,
rustc_path, src_base,
build_base, stage_id,
mode,
run_ignored,
filter,
runtool,
rustcflags,
verbose,
chan,
testfile);
ret task::spawn_joinable(testthunk);
}
fn run_test_task(compile_lib_path: str, run_lib_path: str, rustc_path: str,
src_base: str, build_base: str, stage_id: str, mode: str,
run_ignored: bool, opt_filter: str, opt_runtool: str,
opt_rustcflags: str, verbose: bool,
procsrv_chan: procsrv::reqchan, testfile: -[u8]) {
fn run_test_task(compile_lib_path: -istr, run_lib_path: -istr,
rustc_path: -istr,
src_base: -istr, build_base: -istr, stage_id: -istr,
mode: -istr,
run_ignored: -bool, opt_filter: -istr, opt_runtool: -istr,
opt_rustcflags: -istr, verbose: -bool,
procsrv_chan: -procsrv::reqchan, testfile: -[u8]) {
test::configure_test_task();
@ -239,7 +277,7 @@ fn run_test_task(compile_lib_path: str, run_lib_path: str, rustc_path: str,
src_base: src_base,
build_base: build_base,
stage_id: stage_id,
mode: str_mode(mode),
mode: str_mode(istr::to_estr(mode)),
run_ignored: run_ignored,
filter: str_opt(opt_filter),
runtool: str_opt(opt_runtool),

View File

@ -60,7 +60,8 @@ fn is_test_ignored(config: &config, testfile: &str) -> bool {
for each ln: str in iter_header(testfile) {
// FIXME: Can't return or break from iterator
found = found
|| parse_name_directive(ln, "xfail-" + config.stage_id);
|| parse_name_directive(ln, "xfail-"
+ istr::to_estr(config.stage_id));
if (config.mode == common::mode_pretty) {
found = found
|| parse_name_directive(ln, "xfail-pretty");

View File

@ -139,7 +139,7 @@ fn run_pretty_test(cx: &cx, props: &test_props, testfile: &str) {
}
fn make_pp_args(config: &config, _testfile: &str) -> procargs {
let prog = config.rustc_path;
let prog = istr::to_estr(config.rustc_path);
let args = ["-", "--pretty", "normal"];
ret {prog: prog, args: args};
}
@ -170,7 +170,7 @@ actual:\n\
}
fn make_typecheck_args(config: &config, _testfile: &str) -> procargs {
let prog = config.rustc_path;
let prog = istr::to_estr(config.rustc_path);
let args = ["-", "--no-trans", "--lib"];
ret {prog: prog, args: args};
}
@ -230,7 +230,7 @@ fn exec_compiled_test(cx: &cx, props: &test_props, testfile: &str) ->
}
fn compose_and_run(cx: &cx, testfile: &str,
make_args: fn(&config, &str) -> procargs, lib_path: &str,
make_args: fn(&config, &str) -> procargs, lib_path: &istr,
input: option::t<str>) -> procres {
let procargs = make_args(cx.config, testfile);
ret program_output(cx, testfile, lib_path, procargs.prog, procargs.args,
@ -239,9 +239,13 @@ fn compose_and_run(cx: &cx, testfile: &str,
fn make_compile_args(config: &config, props: &test_props, testfile: &str) ->
procargs {
let prog = config.rustc_path;
let prog = istr::to_estr(config.rustc_path);
let args = [testfile, "-o", make_exe_name(config, testfile)];
args += split_maybe_args(config.rustcflags);
let rustcflags = alt config.rustcflags {
option::some(s) { option::some(istr::to_estr(s)) }
option::none. { option::none }
};
args += split_maybe_args(rustcflags);
args += split_maybe_args(props.compile_flags);
ret {prog: prog, args: args};
}
@ -252,13 +256,15 @@ fn make_exe_name(config: &config, testfile: &str) -> str {
fn make_run_args(config: &config, props: &test_props, testfile: &str) ->
procargs {
let toolargs =
if !props.no_valgrind {
// If we've got another tool to run under (valgrind),
// then split apart its command
split_maybe_args(config.runtool)
} else { [] };
let toolargs = if !props.no_valgrind {
// 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(istr::to_estr(s)) }
option::none. { option::none }
};
split_maybe_args(runtool)
} else { [] };
let args = toolargs + [make_exe_name(config, testfile)];
ret {prog: args[0], args: vec::slice(args, 1u, vec::len(args))};
@ -284,8 +290,9 @@ fn split_maybe_args(argstr: &option::t<str>) -> [str] {
}
}
fn program_output(cx: &cx, testfile: &str, lib_path: &str, prog: &str,
fn program_output(cx: &cx, testfile: &str, lib_path: &istr, prog: &str,
args: &[str], input: option::t<str>) -> procres {
let lib_path = istr::to_estr(lib_path);
let cmdline =
{
let cmdline = make_cmdline(lib_path, prog, args);
@ -337,7 +344,7 @@ fn make_out_name(config: &config, testfile: &str, extension: &str) -> str {
}
fn output_base_name(config: &config, testfile: &str) -> str {
let base = config.build_base;
let base = istr::to_estr(config.build_base);
let filename =
{
let parts = istr::split(fs::basename(istr::from_estr(testfile)),
@ -345,7 +352,8 @@ fn output_base_name(config: &config, testfile: &str) -> str {
parts = vec::slice(parts, 0u, vec::len(parts) - 1u);
istr::connect(parts, ~".")
};
#fmt["%s%s.%s", base, istr::to_estr(filename), config.stage_id]
#fmt["%s%s.%s", base, istr::to_estr(filename),
istr::to_estr(config.stage_id)]
}
fn maybe_dump_to_stdout(config: &config, out: &str, err: &str) {