From b3680a5baf91d6889f1dad6a649a67dea6f809f3 Mon Sep 17 00:00:00 2001 From: Joseph Crail Date: Fri, 25 Nov 2016 14:14:46 -0500 Subject: [PATCH] Fix clippy warnings --- tests/common/util.rs | 22 ++++++++++------------ tests/test_cat.rs | 2 +- tests/test_nl.rs | 20 ++++++++++---------- tests/test_od.rs | 17 +++++++---------- tests/test_split.rs | 2 +- tests/test_who.rs | 4 ---- 6 files changed, 29 insertions(+), 38 deletions(-) diff --git a/tests/common/util.rs b/tests/common/util.rs index d5b5ac476..91d472986 100644 --- a/tests/common/util.rs +++ b/tests/common/util.rs @@ -321,13 +321,12 @@ impl AtPath { pub fn cleanup(&self, path: &'static str) { let p = &self.plus(path); - match fs::metadata(p) { - Ok(m) => if m.is_file() { + if let Ok(m) = fs::metadata(p) { + if m.is_file() { fs::remove_file(&p).unwrap(); } else { fs::remove_dir(&p).unwrap(); - }, - Err(_) => {} + } } } @@ -376,21 +375,20 @@ impl TestScenario { // directory, use Cargo's OUT_DIR to find path to executable. // This allows tests to be run using profiles other than debug. let target_dir = path_concat!(env::var("OUT_DIR").unwrap(), "..", "..", "..", PROGNAME); - PathBuf::from(AtPath::new(&Path::new(&target_dir)).root_dir_resolved()) + PathBuf::from(AtPath::new(Path::new(&target_dir)).root_dir_resolved()) }, util_name: String::from(util_name), - fixtures: AtPath::new(&tmpd.as_ref().path()), + fixtures: AtPath::new(tmpd.as_ref().path()), tmpd: tmpd, }; let mut fixture_path_builder = env::current_dir().unwrap(); fixture_path_builder.push(TESTS_DIR); fixture_path_builder.push(FIXTURES_DIR); fixture_path_builder.push(util_name); - match fs::metadata(&fixture_path_builder) { - Ok(m) => if m.is_dir() { + if let Ok(m) = fs::metadata(&fixture_path_builder) { + if m.is_dir() { recursive_copy(&fixture_path_builder, &ts.fixtures.subdir).unwrap(); - }, - Err(_) => {} + } } ts } @@ -418,7 +416,7 @@ impl TestScenario { } } -/// A UCommand is a wrapper around an individual Command that provides several additional features +/// A `UCommand` is a wrapper around an individual Command that provides several additional features /// 1. it has convenience functions that are more ergonomic to use for piping in stdin, spawning the command /// and asserting on the results. /// 2. it tracks arguments provided so that in test cases which may provide variations of an arg in loops @@ -542,7 +540,7 @@ impl UCommand { .unwrap_or_else( || panic!( "Could not take child process stdin")) - .write_all(&input) + .write_all(input) .unwrap_or_else(|e| panic!("{}", e)); } diff --git a/tests/test_cat.rs b/tests/test_cat.rs index ae2615511..6394356bc 100644 --- a/tests/test_cat.rs +++ b/tests/test_cat.rs @@ -23,7 +23,7 @@ fn test_output_multi_files_print_all_chars() { fn test_stdin_show_nonprinting() { for same_param in vec!["-v", "--show-nonprinting"] { new_ucmd!() - .args(&vec![same_param]) + .args(&[same_param]) .pipe_in("\t\0\n") .succeeds() .stdout_only("\t^@"); diff --git a/tests/test_nl.rs b/tests/test_nl.rs index 83bd202a0..782087ff3 100644 --- a/tests/test_nl.rs +++ b/tests/test_nl.rs @@ -35,16 +35,16 @@ fn test_padding_with_overflow() { #[test] fn test_sections_and_styles() { - for &(fixture, output) in [("section.txt", - "\nHEADER1\nHEADER2\n\n1 |BODY1\n2 \ - |BODY2\n\nFOOTER1\nFOOTER2\n\nNEXTHEADER1\nNEXTHEADER2\n\n1 \ - |NEXTBODY1\n2 |NEXTBODY2\n\nNEXTFOOTER1\nNEXTFOOTER2\n"), - ("joinblanklines.txt", - "1 |Nonempty\n2 |Nonempty\n3 |Followed by 10x empty\n\n\n\n\n4 \ - |\n\n\n\n\n5 |\n6 |Followed by 5x empty\n\n\n\n\n7 |\n8 \ - |Followed by 4x empty\n\n\n\n\n9 |Nonempty\n10 |Nonempty\n11 \ - |Nonempty.\n")] - .iter() { + for &(fixture, output) in &[("section.txt", + "\nHEADER1\nHEADER2\n\n1 |BODY1\n2 \ + |BODY2\n\nFOOTER1\nFOOTER2\n\nNEXTHEADER1\nNEXTHEADER2\n\n1 \ + |NEXTBODY1\n2 |NEXTBODY2\n\nNEXTFOOTER1\nNEXTFOOTER2\n"), + ("joinblanklines.txt", + "1 |Nonempty\n2 |Nonempty\n3 |Followed by 10x empty\n\n\n\n\n4 \ + |\n\n\n\n\n5 |\n6 |Followed by 5x empty\n\n\n\n\n7 |\n8 \ + |Followed by 4x empty\n\n\n\n\n9 |Nonempty\n10 |Nonempty\n11 \ + |Nonempty.\n")] + { new_ucmd!() .args(&["-s", "|", "-n", "ln", "-w", "3", "-b", "a", "-l", "5", fixture]) .run() diff --git a/tests/test_od.rs b/tests/test_od.rs index a10022a75..e732de55d 100644 --- a/tests/test_od.rs +++ b/tests/test_od.rs @@ -29,9 +29,8 @@ fn test_file() { { let mut f = File::create(&file).unwrap(); - match f.write_all(b"abcdefghijklmnopqrstuvwxyz\n") { - Err(_) => panic!("Test setup failed - could not write file"), - _ => {} + if f.write_all(b"abcdefghijklmnopqrstuvwxyz\n").is_err() { + panic!("Test setup failed - could not write file"); } } @@ -52,15 +51,14 @@ fn test_2files() { let file1 = tmpdir.join("test1"); let file2 = tmpdir.join("test2"); - for &(n,a) in [(1,"a"), (2,"b")].iter() { + for &(n,a) in &[(1,"a"), (2,"b")] { println!("number: {} letter:{}", n, a); } for &(path,data)in &[(&file1, "abcdefghijklmnop"),(&file2, "qrstuvwxyz\n")] { let mut f = File::create(&path).unwrap(); - match f.write_all(data.as_bytes()) { - Err(_) => panic!("Test setup failed - could not write file"), - _ => {} + if f.write_all(data.as_bytes()).is_err() { + panic!("Test setup failed - could not write file"); } } @@ -108,9 +106,8 @@ fn test_from_mixed() { let (data1, data2, data3) = ("abcdefg","hijklmnop","qrstuvwxyz\n"); for &(path,data)in &[(&file1, data1),(&file3, data3)] { let mut f = File::create(&path).unwrap(); - match f.write_all(data.as_bytes()) { - Err(_) => panic!("Test setup failed - could not write file"), - _ => {} + if f.write_all(data.as_bytes()).is_err() { + panic!("Test setup failed - could not write file"); } } diff --git a/tests/test_split.rs b/tests/test_split.rs index fa84443c7..5903485e2 100644 --- a/tests/test_split.rs +++ b/tests/test_split.rs @@ -49,7 +49,7 @@ impl Glob { let mut files = self.collect(); files.sort(); let mut data: Vec = vec![]; - for name in files.iter() { + for name in &files { data.extend(self.directory.read(name).into_bytes()); } data diff --git a/tests/test_who.rs b/tests/test_who.rs index c32adac19..79f774a57 100644 --- a/tests/test_who.rs +++ b/tests/test_who.rs @@ -1,7 +1,3 @@ -use common::util::*; - - - #[cfg(target_os = "linux")] #[test] fn test_count() {