Skip to content

Remove ~str from compiletest, librustuv, libfmt_macros, libserialize, libgetopts, and the docs #14233

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
May 16, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 11 additions & 11 deletions src/compiletest/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,10 @@ impl fmt::Show for Mode {
#[deriving(Clone)]
pub struct Config {
// The library paths required for running the compiler
pub compile_lib_path: ~str,
pub compile_lib_path: StrBuf,

// The library paths required for running compiled programs
pub run_lib_path: ~str,
pub run_lib_path: StrBuf,

// The rustc executable
pub rustc_path: Path,
Expand All @@ -80,7 +80,7 @@ pub struct Config {
pub aux_base: Path,

// The name of the stage being built (stage1, etc)
pub stage_id: ~str,
pub stage_id: StrBuf,

// The test mode, compile-fail, run-fail, run-pass
pub mode: Mode,
Expand Down Expand Up @@ -110,37 +110,37 @@ pub struct Config {

// A command line to prefix program execution with,
// for running under valgrind
pub runtool: Option<~str>,
pub runtool: Option<StrBuf>,

// Flags to pass to the compiler when building for the host
pub host_rustcflags: Option<~str>,
pub host_rustcflags: Option<StrBuf>,

// Flags to pass to the compiler when building for the target
pub target_rustcflags: Option<~str>,
pub target_rustcflags: Option<StrBuf>,

// Run tests using the JIT
pub jit: bool,

// Target system to be tested
pub target: ~str,
pub target: StrBuf,

// Host triple for the compiler being invoked
pub host: ~str,
pub host: StrBuf,

// Path to the android tools
pub android_cross_path: Path,

// Extra parameter to run adb on arm-linux-androideabi
pub adb_path: ~str,
pub adb_path: StrBuf,

// Extra parameter to run test sute on arm-linux-androideabi
pub adb_test_dir: ~str,
pub adb_test_dir: StrBuf,

// status whether android device available or not
pub adb_device_status: bool,

// the path containing LLDB's Python module
pub lldb_python_dir: Option<~str>,
pub lldb_python_dir: Option<StrBuf>,

// Explain what's going on
pub verbose: bool
Expand Down
143 changes: 85 additions & 58 deletions src/compiletest/compiletest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand Down Expand Up @@ -91,15 +93,15 @@ 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!("");
fail!()
}

let matches =
&match getopts::getopts(args_, groups.as_slice()) {
&match getopts::getopts(args_.as_slice(), groups.as_slice()) {
Ok(m) => m,
Err(f) => fail!("{}", f.to_err_msg())
};
Expand Down Expand Up @@ -129,39 +131,53 @@ 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(),
mode: FromStr::from_str(matches.opt_str("mode").unwrap()).expect("invalid mode"),
stage_id: matches.opt_str("stage-id").unwrap().to_strbuf(),
mode: FromStr::from_str(matches.opt_str("mode")
.unwrap()
.as_slice()).expect("invalid mode"),
run_ignored: matches.opt_present("ignored"),
filter: filter,
logfile: matches.opt_str("logfile").map(|s| Path::new(s)),
save_metrics: matches.opt_str("save-metrics").map(|s| Path::new(s)),
ratchet_metrics:
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"),
matches.opt_str("ratchet-noise-percent")
.and_then(|s| from_str::<f64>(s.as_slice())),
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")
Expand All @@ -170,50 +186,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 \
Expand Down Expand Up @@ -321,11 +346,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!("[{}] {}",
Expand All @@ -336,14 +361,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)
})
Expand Down
42 changes: 26 additions & 16 deletions src/compiletest/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ use std::io::{BufferedReader, File};

pub struct ExpectedError {
pub line: uint,
pub kind: ~str,
pub msg: ~str,
pub kind: StrBuf,
pub msg: StrBuf,
}

// Load any test directives embedded in the file
Expand All @@ -23,17 +23,18 @@ pub fn load_errors(testfile: &Path) -> Vec<ExpectedError> {
let mut rdr = BufferedReader::new(File::open(testfile).unwrap());
let mut line_num = 1u;
for ln in rdr.lines() {
error_patterns.push_all_move(parse_expected(line_num, ln.unwrap()));
error_patterns.push_all_move(parse_expected(line_num,
ln.unwrap().to_strbuf()));
line_num += 1u;
}
return error_patterns;
}

fn parse_expected(line_num: uint, line: ~str) -> Vec<ExpectedError> {
let line = line.trim();
let error_tag = "//~".to_owned();
fn parse_expected(line_num: uint, line: StrBuf) -> Vec<ExpectedError> {
let line = line.as_slice().trim().to_strbuf();
let error_tag = "//~".to_strbuf();
let mut idx;
match line.find_str(error_tag) {
match line.as_slice().find_str(error_tag.as_slice()) {
None => return Vec::new(),
Some(nn) => { idx = (nn as uint) + error_tag.len(); }
}
Expand All @@ -42,25 +43,34 @@ fn parse_expected(line_num: uint, line: ~str) -> Vec<ExpectedError> {
// three lines above current line:
let mut adjust_line = 0u;
let len = line.len();
while idx < len && line[idx] == ('^' as u8) {
while idx < len && line.as_slice()[idx] == ('^' as u8) {
adjust_line += 1u;
idx += 1u;
}

// Extract kind:
while idx < len && line[idx] == (' ' as u8) { idx += 1u; }
while idx < len && line.as_slice()[idx] == (' ' as u8) {
idx += 1u;
}
let start_kind = idx;
while idx < len && line[idx] != (' ' as u8) { idx += 1u; }
while idx < len && line.as_slice()[idx] != (' ' as u8) {
idx += 1u;
}

let kind = line.slice(start_kind, idx);
let kind = kind.to_ascii().to_lower().into_str();
let kind = line.as_slice().slice(start_kind, idx);
let kind = kind.to_ascii().to_lower().into_str().to_strbuf();

// Extract msg:
while idx < len && line[idx] == (' ' as u8) { idx += 1u; }
let msg = line.slice(idx, len).to_owned();
while idx < len && line.as_slice()[idx] == (' ' as u8) {
idx += 1u;
}
let msg = line.as_slice().slice(idx, len).to_strbuf();

debug!("line={} kind={} msg={}", line_num - adjust_line, kind, msg);

return vec!(ExpectedError{line: line_num - adjust_line, kind: kind,
msg: msg});
return vec!(ExpectedError{
line: line_num - adjust_line,
kind: kind,
msg: msg,
});
}
Loading