Skip to content

refactored compiletest following clippy's suggestions #28152

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 1 commit into from
Sep 1, 2015
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
31 changes: 13 additions & 18 deletions src/compiletest/compiletest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ pub fn log_config(config: &Config) {
logv(c, format!("filter: {}",
opt_str(&config.filter
.as_ref()
.map(|re| re.to_string()))));
.map(|re| re.to_owned()))));
logv(c, format!("runtool: {}", opt_str(&config.runtool)));
logv(c, format!("host-rustcflags: {}",
opt_str(&config.host_rustcflags)));
Expand All @@ -205,19 +205,16 @@ pub fn opt_str<'a>(maybestr: &'a Option<String>) -> &'a str {

pub fn opt_str2(maybestr: Option<String>) -> String {
match maybestr {
None => "(none)".to_string(),
None => "(none)".to_owned(),
Some(s) => s,
}
}

pub fn run_tests(config: &Config) {
if config.target.contains("android") {
match config.mode {
DebugInfoGdb => {
println!("{} debug-info test uses tcp 5039 port.\
please reserve it", config.target);
}
_ =>{}
if let DebugInfoGdb = config.mode {
println!("{} debug-info test uses tcp 5039 port.\
please reserve it", config.target);
}

// android debug-info test uses remote debugger
Expand Down Expand Up @@ -289,10 +286,10 @@ pub fn is_test(config: &Config, testfile: &Path) -> bool {
// Pretty-printer does not work with .rc files yet
let valid_extensions =
match config.mode {
Pretty => vec!(".rs".to_string()),
_ => vec!(".rc".to_string(), ".rs".to_string())
Pretty => vec!(".rs".to_owned()),
_ => vec!(".rc".to_owned(), ".rs".to_owned())
};
let invalid_prefixes = vec!(".".to_string(), "#".to_string(), "~".to_string());
let invalid_prefixes = vec!(".".to_owned(), "#".to_owned(), "~".to_owned());
let name = testfile.file_name().unwrap().to_str().unwrap();

let mut valid = false;
Expand Down Expand Up @@ -364,7 +361,7 @@ fn extract_gdb_version(full_version_line: Option<String>) -> Option<String> {
full_version_line.char_at(pos + 3).is_digit(10) {
continue
}
return Some(full_version_line[pos..pos+3].to_string());
return Some(full_version_line[pos..pos+3].to_owned());
}
println!("Could not extract GDB version from line '{}'",
full_version_line);
Expand All @@ -386,9 +383,8 @@ fn extract_lldb_version(full_version_line: Option<String>) -> Option<String> {
// We are only interested in the major version number, so this function
// will return `Some("179")` and `Some("300")` respectively.

match full_version_line {
Some(ref full_version_line)
if !full_version_line.trim().is_empty() => {
if let Some(ref full_version_line) = full_version_line {
if !full_version_line.trim().is_empty() {
let full_version_line = full_version_line.trim();

for (pos, l) in full_version_line.char_indices() {
Expand All @@ -410,8 +406,7 @@ fn extract_lldb_version(full_version_line: Option<String>) -> Option<String> {
}
println!("Could not extract LLDB version from line '{}'",
full_version_line);
None
},
_ => None
}
}
None
}
2 changes: 1 addition & 1 deletion src/compiletest/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ fn parse_expected(last_nonfollow_error: Option<usize>,
let letters = line[kind_start..].chars();
let msg = letters.skip_while(|c| c.is_whitespace())
.skip_while(|c| !c.is_whitespace())
.collect::<String>().trim().to_string();
.collect::<String>().trim().to_owned();

let (which, line) = if follow {
assert!(adjusts == 0, "use either //~| or //~^, not both.");
Expand Down
121 changes: 56 additions & 65 deletions src/compiletest/header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,9 @@ pub fn load_props(testfile: &Path) -> TestProps {
let mut pretty_compare_only = false;
let mut forbid_output = Vec::new();
iter_header(testfile, &mut |ln| {
match parse_error_pattern(ln) {
Some(ep) => error_patterns.push(ep),
None => ()
};
if let Some(ep) = parse_error_pattern(ln) {
error_patterns.push(ep);
}

if compile_flags.is_none() {
compile_flags = parse_compile_flags(ln);
Expand Down Expand Up @@ -108,24 +107,20 @@ pub fn load_props(testfile: &Path) -> TestProps {
pretty_compare_only = parse_pretty_compare_only(ln);
}

match parse_aux_build(ln) {
Some(ab) => { aux_builds.push(ab); }
None => {}
if let Some(ab) = parse_aux_build(ln) {
aux_builds.push(ab);
}

match parse_exec_env(ln) {
Some(ee) => { exec_env.push(ee); }
None => {}
if let Some(ee) = parse_exec_env(ln) {
exec_env.push(ee);
}

match parse_check_line(ln) {
Some(cl) => check_lines.push(cl),
None => ()
};
if let Some(cl) = parse_check_line(ln) {
check_lines.push(cl);
}

match parse_forbid_output(ln) {
Some(of) => forbid_output.push(of),
None => (),
if let Some(of) = parse_forbid_output(ln) {
forbid_output.push(of);
}

true
Expand All @@ -134,8 +129,8 @@ pub fn load_props(testfile: &Path) -> TestProps {
for key in vec!["RUST_TEST_NOCAPTURE", "RUST_TEST_THREADS"] {
match env::var(key) {
Ok(val) =>
if exec_env.iter().find(|&&(ref x, _)| *x == key.to_string()).is_none() {
exec_env.push((key.to_string(), val))
if exec_env.iter().find(|&&(ref x, _)| *x == key).is_none() {
exec_env.push((key.to_owned(), val))
},
Err(..) => {}
}
Expand All @@ -153,7 +148,7 @@ pub fn load_props(testfile: &Path) -> TestProps {
check_stdout: check_stdout,
no_prefer_dynamic: no_prefer_dynamic,
pretty_expanded: pretty_expanded,
pretty_mode: pretty_mode.unwrap_or("normal".to_string()),
pretty_mode: pretty_mode.unwrap_or("normal".to_owned()),
pretty_compare_only: pretty_compare_only,
forbid_output: forbid_output,
}
Expand Down Expand Up @@ -182,22 +177,21 @@ pub fn is_test_ignored(config: &Config, testfile: &Path) -> bool {
return true;
}

match config.gdb_version {
Some(ref actual_version) => {
if line.contains("min-gdb-version") {
let min_version = line.trim()
.split(' ')
.last()
.expect("Malformed GDB version directive");
// Ignore if actual version is smaller the minimum required
// version
gdb_version_to_int(actual_version) <
gdb_version_to_int(min_version)
} else {
false
}
if let Some(ref actual_version) = config.gdb_version {
if line.contains("min-gdb-version") {
let min_version = line.trim()
.split(' ')
.last()
.expect("Malformed GDB version directive");
// Ignore if actual version is smaller the minimum required
// version
gdb_version_to_int(actual_version) <
gdb_version_to_int(min_version)
} else {
false
}
None => false
} else {
false
}
}

Expand All @@ -210,22 +204,21 @@ pub fn is_test_ignored(config: &Config, testfile: &Path) -> bool {
return true;
}

match config.lldb_version {
Some(ref actual_version) => {
if line.contains("min-lldb-version") {
let min_version = line.trim()
.split(' ')
.last()
.expect("Malformed lldb version directive");
// Ignore if actual version is smaller the minimum required
// version
lldb_version_to_int(actual_version) <
lldb_version_to_int(min_version)
} else {
false
}
if let Some(ref actual_version) = config.lldb_version {
if line.contains("min-lldb-version") {
let min_version = line.trim()
.split(' ')
.last()
.expect("Malformed lldb version directive");
// Ignore if actual version is smaller the minimum required
// version
lldb_version_to_int(actual_version) <
lldb_version_to_int(min_version)
} else {
false
}
None => false
} else {
false
}
}

Expand Down Expand Up @@ -316,11 +309,11 @@ fn parse_exec_env(line: &str) -> Option<(String, String)> {
// nv is either FOO or FOO=BAR
let mut strs: Vec<String> = nv
.splitn(2, '=')
.map(|s| s.to_string())
.map(str::to_owned)
.collect();

match strs.len() {
1 => (strs.pop().unwrap(), "".to_string()),
1 => (strs.pop().unwrap(), "".to_owned()),
2 => {
let end = strs.pop().unwrap();
(strs.pop().unwrap(), end)
Expand All @@ -331,33 +324,31 @@ fn parse_exec_env(line: &str) -> Option<(String, String)> {
}

fn parse_pp_exact(line: &str, testfile: &Path) -> Option<PathBuf> {
match parse_name_value_directive(line, "pp-exact") {
Some(s) => Some(PathBuf::from(&s)),
None => {
if let Some(s) = parse_name_value_directive(line, "pp-exact") {
Some(PathBuf::from(&s))
} else {
if parse_name_directive(line, "pp-exact") {
testfile.file_name().map(|s| PathBuf::from(s))
testfile.file_name().map(PathBuf::from)
} else {
None
}
}
}
}

fn parse_name_directive(line: &str, directive: &str) -> bool {
// This 'no-' rule is a quick hack to allow pretty-expanded and no-pretty-expanded to coexist
line.contains(directive) && !line.contains(&("no-".to_string() + directive))
line.contains(directive) && !line.contains(&("no-".to_owned() + directive))
}

pub fn parse_name_value_directive(line: &str, directive: &str)
-> Option<String> {
let keycolon = format!("{}:", directive);
match line.find(&keycolon) {
Some(colon) => {
let value = line[(colon + keycolon.len()) .. line.len()].to_string();
debug!("{}: {}", directive, value);
Some(value)
}
None => None
if let Some(colon) = line.find(&keycolon) {
let value = line[(colon + keycolon.len()) .. line.len()].to_owned();
debug!("{}: {}", directive, value);
Some(value)
} else {
None
}
}

Expand Down
5 changes: 2 additions & 3 deletions src/compiletest/procsrv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,8 @@ fn add_target_env(cmd: &mut Command, lib_path: &str, aux_path: Option<&str>) {
// Need to be sure to put both the lib_path and the aux path in the dylib
// search path for the child.
let mut path = DynamicLibrary::search_path();
match aux_path {
Some(p) => path.insert(0, PathBuf::from(p)),
None => {}
if let Some(p) = aux_path {
path.insert(0, PathBuf::from(p))
}
path.insert(0, PathBuf::from(lib_path));

Expand Down
Loading