1
Fork 0

compiletest: Remove all uses of ~str from compiletest

This commit is contained in:
Patrick Walton 2014-05-14 20:47:24 -07:00
parent bbd034c3a6
commit 78bc758c94
7 changed files with 696 additions and 422 deletions

View file

@ -48,12 +48,14 @@ fn start(argc: int, argv: **u8) -> int {
pub fn main() {
let args = os::args();
let config = parse_config(args.move_iter().collect());
let config = parse_config(args.move_iter()
.map(|x| x.to_strbuf())
.collect());
log_config(&config);
run_tests(&config);
}
pub fn parse_config(args: Vec<~str> ) -> Config {
pub fn parse_config(args: Vec<StrBuf> ) -> Config {
let groups : Vec<getopts::OptGroup> =
vec!(reqopt("", "compile-lib-path", "path to host shared libraries", "PATH"),
@ -91,7 +93,7 @@ pub fn parse_config(args: Vec<~str> ) -> Config {
assert!(!args.is_empty());
let argv0 = (*args.get(0)).clone();
let args_ = args.tail();
if *args.get(1) == "-h".to_owned() || *args.get(1) == "--help".to_owned() {
if args.get(1).as_slice() == "-h" || args.get(1).as_slice() == "--help" {
let message = format!("Usage: {} [OPTIONS] [TESTNAME...]", argv0);
println!("{}", getopts::usage(message, groups.as_slice()));
println!("");
@ -99,7 +101,11 @@ pub fn parse_config(args: Vec<~str> ) -> Config {
}
let matches =
&match getopts::getopts(args_, groups.as_slice()) {
&match getopts::getopts(args_.iter()
.map(|x| x.to_owned())
.collect::<Vec<_>>()
.as_slice(),
groups.as_slice()) {
Ok(m) => m,
Err(f) => fail!("{}", f.to_err_msg())
};
@ -129,15 +135,17 @@ pub fn parse_config(args: Vec<~str> ) -> Config {
};
Config {
compile_lib_path: matches.opt_str("compile-lib-path").unwrap(),
run_lib_path: matches.opt_str("run-lib-path").unwrap(),
compile_lib_path: matches.opt_str("compile-lib-path")
.unwrap()
.to_strbuf(),
run_lib_path: matches.opt_str("run-lib-path").unwrap().to_strbuf(),
rustc_path: opt_path(matches, "rustc-path"),
clang_path: matches.opt_str("clang-path").map(|s| Path::new(s)),
llvm_bin_path: matches.opt_str("llvm-bin-path").map(|s| Path::new(s)),
src_base: opt_path(matches, "src-base"),
build_base: opt_path(matches, "build-base"),
aux_base: opt_path(matches, "aux-base"),
stage_id: matches.opt_str("stage-id").unwrap(),
stage_id: matches.opt_str("stage-id").unwrap().to_strbuf(),
mode: FromStr::from_str(matches.opt_str("mode").unwrap()).expect("invalid mode"),
run_ignored: matches.opt_present("ignored"),
filter: filter,
@ -147,21 +155,30 @@ pub fn parse_config(args: Vec<~str> ) -> Config {
matches.opt_str("ratchet-metrics").map(|s| Path::new(s)),
ratchet_noise_percent:
matches.opt_str("ratchet-noise-percent").and_then(|s| from_str::<f64>(s)),
runtool: matches.opt_str("runtool"),
host_rustcflags: matches.opt_str("host-rustcflags"),
target_rustcflags: matches.opt_str("target-rustcflags"),
runtool: matches.opt_str("runtool").map(|x| x.to_strbuf()),
host_rustcflags: matches.opt_str("host-rustcflags")
.map(|x| x.to_strbuf()),
target_rustcflags: matches.opt_str("target-rustcflags")
.map(|x| x.to_strbuf()),
jit: matches.opt_present("jit"),
target: opt_str2(matches.opt_str("target")).to_str(),
host: opt_str2(matches.opt_str("host")).to_str(),
target: opt_str2(matches.opt_str("target").map(|x| x.to_strbuf())),
host: opt_str2(matches.opt_str("host").map(|x| x.to_strbuf())),
android_cross_path: opt_path(matches, "android-cross-path"),
adb_path: opt_str2(matches.opt_str("adb-path")).to_str(),
adb_test_dir:
opt_str2(matches.opt_str("adb-test-dir")).to_str(),
adb_path: opt_str2(matches.opt_str("adb-path")
.map(|x| x.to_strbuf())),
adb_test_dir: opt_str2(matches.opt_str("adb-test-dir")
.map(|x| x.to_strbuf())),
adb_device_status:
"arm-linux-androideabi" == opt_str2(matches.opt_str("target")) &&
"(none)" != opt_str2(matches.opt_str("adb-test-dir")) &&
!opt_str2(matches.opt_str("adb-test-dir")).is_empty(),
lldb_python_dir: matches.opt_str("lldb-python-dir"),
"arm-linux-androideabi" ==
opt_str2(matches.opt_str("target")
.map(|x| x.to_strbuf())).as_slice() &&
"(none)" !=
opt_str2(matches.opt_str("adb-test-dir")
.map(|x| x.to_strbuf())).as_slice() &&
!opt_str2(matches.opt_str("adb-test-dir")
.map(|x| x.to_strbuf())).is_empty(),
lldb_python_dir: matches.opt_str("lldb-python-dir")
.map(|x| x.to_strbuf()),
test_shard: test::opt_shard(matches.opt_str("test-shard")
.map(|x| x.to_strbuf())),
verbose: matches.opt_present("verbose")
@ -170,50 +187,59 @@ pub fn parse_config(args: Vec<~str> ) -> Config {
pub fn log_config(config: &Config) {
let c = config;
logv(c, format!("configuration:"));
logv(c, format!("compile_lib_path: {}", config.compile_lib_path));
logv(c, format!("run_lib_path: {}", config.run_lib_path));
logv(c, format!("rustc_path: {}", config.rustc_path.display()));
logv(c, format!("src_base: {}", config.src_base.display()));
logv(c, format!("build_base: {}", config.build_base.display()));
logv(c, format!("stage_id: {}", config.stage_id));
logv(c, format!("mode: {}", config.mode));
logv(c, format!("run_ignored: {}", config.run_ignored));
logv(c, format!("filter: {}", opt_str(&config.filter.as_ref().map(|re| re.to_str()))));
logv(c, format!("runtool: {}", opt_str(&config.runtool)));
logv(c, format!("host-rustcflags: {}", opt_str(&config.host_rustcflags)));
logv(c, format!("target-rustcflags: {}", opt_str(&config.target_rustcflags)));
logv(c, format!("jit: {}", config.jit));
logv(c, format!("target: {}", config.target));
logv(c, format!("host: {}", config.host));
logv(c, format!("android-cross-path: {}", config.android_cross_path.display()));
logv(c, format!("adb_path: {}", config.adb_path));
logv(c, format!("adb_test_dir: {}", config.adb_test_dir));
logv(c, format!("adb_device_status: {}", config.adb_device_status));
logv(c, format_strbuf!("configuration:"));
logv(c, format_strbuf!("compile_lib_path: {}", config.compile_lib_path));
logv(c, format_strbuf!("run_lib_path: {}", config.run_lib_path));
logv(c, format_strbuf!("rustc_path: {}", config.rustc_path.display()));
logv(c, format_strbuf!("src_base: {}", config.src_base.display()));
logv(c, format_strbuf!("build_base: {}", config.build_base.display()));
logv(c, format_strbuf!("stage_id: {}", config.stage_id));
logv(c, format_strbuf!("mode: {}", config.mode));
logv(c, format_strbuf!("run_ignored: {}", config.run_ignored));
logv(c, format_strbuf!("filter: {}",
opt_str(&config.filter
.as_ref()
.map(|re| {
re.to_str().into_strbuf()
}))));
logv(c, format_strbuf!("runtool: {}", opt_str(&config.runtool)));
logv(c, format_strbuf!("host-rustcflags: {}",
opt_str(&config.host_rustcflags)));
logv(c, format_strbuf!("target-rustcflags: {}",
opt_str(&config.target_rustcflags)));
logv(c, format_strbuf!("jit: {}", config.jit));
logv(c, format_strbuf!("target: {}", config.target));
logv(c, format_strbuf!("host: {}", config.host));
logv(c, format_strbuf!("android-cross-path: {}",
config.android_cross_path.display()));
logv(c, format_strbuf!("adb_path: {}", config.adb_path));
logv(c, format_strbuf!("adb_test_dir: {}", config.adb_test_dir));
logv(c, format_strbuf!("adb_device_status: {}",
config.adb_device_status));
match config.test_shard {
None => logv(c, "test_shard: (all)".to_owned()),
Some((a,b)) => logv(c, format!("test_shard: {}.{}", a, b))
None => logv(c, "test_shard: (all)".to_strbuf()),
Some((a,b)) => logv(c, format_strbuf!("test_shard: {}.{}", a, b))
}
logv(c, format!("verbose: {}", config.verbose));
logv(c, format!("\n"));
logv(c, format_strbuf!("verbose: {}", config.verbose));
logv(c, format_strbuf!("\n"));
}
pub fn opt_str<'a>(maybestr: &'a Option<~str>) -> &'a str {
pub fn opt_str<'a>(maybestr: &'a Option<StrBuf>) -> &'a str {
match *maybestr {
None => "(none)",
Some(ref s) => {
let s: &'a str = *s;
s
}
Some(ref s) => s.as_slice(),
}
}
pub fn opt_str2(maybestr: Option<~str>) -> ~str {
match maybestr { None => "(none)".to_owned(), Some(s) => { s } }
pub fn opt_str2(maybestr: Option<StrBuf>) -> StrBuf {
match maybestr {
None => "(none)".to_strbuf(),
Some(s) => s,
}
}
pub fn run_tests(config: &Config) {
if config.target == "arm-linux-androideabi".to_owned() {
if config.target.as_slice() == "arm-linux-androideabi" {
match config.mode {
DebugInfoGdb => {
println!("arm-linux-androideabi debug-info \
@ -321,11 +347,11 @@ pub fn make_test(config: &Config, testfile: &Path, f: || -> test::TestFn)
pub fn make_test_name(config: &Config, testfile: &Path) -> test::TestName {
// Try to elide redundant long paths
fn shorten(path: &Path) -> ~str {
fn shorten(path: &Path) -> StrBuf {
let filename = path.filename_str();
let p = path.dir_path();
let dir = p.filename_str();
format!("{}/{}", dir.unwrap_or(""), filename.unwrap_or(""))
format_strbuf!("{}/{}", dir.unwrap_or(""), filename.unwrap_or(""))
}
test::DynTestName(format_strbuf!("[{}] {}",
@ -336,14 +362,16 @@ pub fn make_test_name(config: &Config, testfile: &Path) -> test::TestName {
pub fn make_test_closure(config: &Config, testfile: &Path) -> test::TestFn {
let config = (*config).clone();
// FIXME (#9639): This needs to handle non-utf8 paths
let testfile = testfile.as_str().unwrap().to_owned();
test::DynTestFn(proc() { runtest::run(config, testfile) })
let testfile = testfile.as_str().unwrap().to_strbuf();
test::DynTestFn(proc() {
runtest::run(config, testfile)
})
}
pub fn make_metrics_test_closure(config: &Config, testfile: &Path) -> test::TestFn {
let config = (*config).clone();
// FIXME (#9639): This needs to handle non-utf8 paths
let testfile = testfile.as_str().unwrap().to_owned();
let testfile = testfile.as_str().unwrap().to_strbuf();
test::DynMetricFn(proc(mm) {
runtest::run_metrics(config, testfile, mm)
})