From b3680a5baf91d6889f1dad6a649a67dea6f809f3 Mon Sep 17 00:00:00 2001 From: Joseph Crail Date: Fri, 25 Nov 2016 14:14:46 -0500 Subject: [PATCH 1/3] 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() { From 78d2e8db27bab9e39abf70003ad487acf53c2290 Mon Sep 17 00:00:00 2001 From: Joseph Crail Date: Fri, 25 Nov 2016 14:36:56 -0500 Subject: [PATCH 2/3] Fix comment spelling --- src/dircolors/dircolors.rs | 2 +- src/env/env.rs | 2 +- src/factor/factor.rs | 2 +- src/fmt/parasplit.rs | 2 +- src/install/install.rs | 2 +- src/mkdir/mkdir.rs | 2 +- src/mktemp/mktemp.rs | 2 +- src/nl/nl.rs | 2 +- src/od/inputdecoder.rs | 2 +- src/od/od.rs | 2 +- src/od/output_info.rs | 4 ++-- src/od/parse_formats.rs | 2 +- src/od/prn_float.rs | 2 +- src/pathchk/pathchk.rs | 4 ++-- .../tokenize/num_format/formatters/cninetyninehexfloatf.rs | 4 ++-- src/printf/tokenize/num_format/num_format.rs | 2 +- src/printf/tokenize/token.rs | 2 +- src/printf/tokenize/unescaped_text.rs | 2 +- src/uucore/utmpx.rs | 2 +- tests/test_od.rs | 6 +++--- 20 files changed, 25 insertions(+), 25 deletions(-) diff --git a/src/dircolors/dircolors.rs b/src/dircolors/dircolors.rs index c5a0ae29f..23d9717b7 100644 --- a/src/dircolors/dircolors.rs +++ b/src/dircolors/dircolors.rs @@ -137,7 +137,7 @@ pub fn uumain(args: Vec) -> i32 { } pub trait StrUtils { - /// Remove comments and trim whitespaces + /// Remove comments and trim whitespace fn purify(&self) -> &Self; /// Like split_whitespace() but only produce 2 components fn split_two(&self) -> (&str, &str); diff --git a/src/env/env.rs b/src/env/env.rs index eb57d69f1..90618a415 100644 --- a/src/env/env.rs +++ b/src/env/env.rs @@ -63,7 +63,7 @@ pub fn uumain(args: Vec) -> i32 { let mut item = iter.next(); // the for loop doesn't work here, - // because we need sometines to read 2 items forward, + // because we need sometimes to read 2 items forward, // and the iter can't be borrowed twice while item != None { let opt = item.unwrap(); diff --git a/src/factor/factor.rs b/src/factor/factor.rs index 134acf6ca..9b1524f71 100644 --- a/src/factor/factor.rs +++ b/src/factor/factor.rs @@ -64,7 +64,7 @@ fn rho_pollard_find_divisor(num: u64) -> u64 { y = rho_pollard_pseudorandom_function(y, a, b, num); let d = gcd(num, max(x, y) - min(x, y)); if d == num { - // Failure, retry with diffrent function + // Failure, retry with different function x = range.ind_sample(&mut rng); y = x; a = range.ind_sample(&mut rng); diff --git a/src/fmt/parasplit.rs b/src/fmt/parasplit.rs index 857a9b0f2..68ec74d0c 100644 --- a/src/fmt/parasplit.rs +++ b/src/fmt/parasplit.rs @@ -332,7 +332,7 @@ impl<'a> Iterator for ParagraphStream<'a> { // in tagged mode, add 4 spaces of additional indenting by default // (gnu fmt's behavior is different: it seems to find the closest column to - // indent_end that is divisible by 3. But honesly that behavior seems + // indent_end that is divisible by 3. But honestly that behavior seems // pretty arbitrary. // Perhaps a better default would be 1 TABWIDTH? But ugh that's so big. if self.opts.tagged { diff --git a/src/install/install.rs b/src/install/install.rs index 2f00d6281..53fe7b23a 100644 --- a/src/install/install.rs +++ b/src/install/install.rs @@ -94,7 +94,7 @@ pub fn uumain(args: Vec) -> i32 { } } -/// Build a specification of the comamnd line. +/// Build a specification of the command line. /// /// Returns a getopts::Options struct. /// diff --git a/src/mkdir/mkdir.rs b/src/mkdir/mkdir.rs index 57c29f34d..4b52b531b 100644 --- a/src/mkdir/mkdir.rs +++ b/src/mkdir/mkdir.rs @@ -29,7 +29,7 @@ pub fn uumain(args: Vec) -> i32 { let mut opts = getopts::Options::new(); // Linux-specific options, not implemented - // opts.optflag("Z", "context", "set SELinux secutiry context" + + // opts.optflag("Z", "context", "set SELinux security context" + // " of each created directory to CTX"), opts.optopt("m", "mode", "set file mode", "755"); opts.optflag("p", "parents", "make parent directories as needed"); diff --git a/src/mktemp/mktemp.rs b/src/mktemp/mktemp.rs index 990edeb74..c790124bd 100644 --- a/src/mktemp/mktemp.rs +++ b/src/mktemp/mktemp.rs @@ -214,7 +214,7 @@ fn exec(tmpdir: PathBuf, prefix: &str, rand: usize, suffix: &str, make_dir: bool println!("{}", tmpname); // CAUTION: Not to call `drop` of tmpfile, which removes the tempfile, - // I call a dengeros function `forget`. + // I call a dangerous function `forget`. forget(tmpfile); 0 diff --git a/src/nl/nl.rs b/src/nl/nl.rs index 8d54b6115..fc7105f66 100644 --- a/src/nl/nl.rs +++ b/src/nl/nl.rs @@ -52,7 +52,7 @@ pub struct Settings { number_separator: String } -// NumberingStyle stores which lines are to be numberd. +// NumberingStyle stores which lines are to be numbered. // The possible options are: // 1. Number all lines // 2. Number only nonempty lines diff --git a/src/od/inputdecoder.rs b/src/od/inputdecoder.rs index e58cf79f3..feec673bb 100644 --- a/src/od/inputdecoder.rs +++ b/src/od/inputdecoder.rs @@ -13,7 +13,7 @@ pub struct InputDecoder<'a, I> where I: 'a { /// A memory buffer, it's size is set in `new`. data: Vec, - /// The numer of bytes in the buffer reserved for the peek data from `PeekRead`. + /// The number of bytes in the buffer reserved for the peek data from `PeekRead`. reserved_peek_length: usize, /// The number of (valid) bytes in the buffer. diff --git a/src/od/od.rs b/src/od/od.rs index 4228fe032..488897a40 100644 --- a/src/od/od.rs +++ b/src/od/od.rs @@ -427,7 +427,7 @@ fn print_bytes(prefix: &str, input_decoder: &MemoryDecoder, output_info: &Output /// returns a reader implementing `PeekRead + Read + HasError` providing the combined input /// /// `skip_bytes` is the number of bytes skipped from the input -/// `read_bytes` is an optinal limit to the number of bytes to read +/// `read_bytes` is an optional limit to the number of bytes to read fn open_input_peek_reader<'a>(input_strings: &'a Vec, skip_bytes: usize, read_bytes: Option) -> PeekReader>> { // should return "impl PeekRead + Read + HasError" when supported in (stable) rust diff --git a/src/od/output_info.rs b/src/od/output_info.rs index 5f8d8733e..b8c464284 100644 --- a/src/od/output_info.rs +++ b/src/od/output_info.rs @@ -92,7 +92,7 @@ impl OutputInfo { /// ``` /// In this example is additional spacing before the first and third decimal number, /// and there is additional spacing before the 1st, 3rd, 5th and 7th hexadecimal number. - /// This way both the octal and decimal, aswell the decimal and hexadecimal numbers + /// This way both the octal and decimal, as well as the decimal and hexadecimal numbers /// left align. Note that the alignment below both octal numbers is identical. /// /// This function calculates the required spacing for a single line, given the size @@ -110,7 +110,7 @@ impl OutputInfo { /// If the blocksize is 8, and the size of the type is 2, the spacing will be /// spread across position 0, 2, 4, 6. All 4 positions will get an additional /// space as long as there are more then 4 spaces available. If there are 2 - /// spaces available, they will be assigend to position 0 and 4. If there is + /// spaces available, they will be assigned to position 0 and 4. If there is /// 1 space available, it will be assigned to position 0. This will be combined, /// For example 7 spaces will be assigned to position 0, 2, 4, 6 like: 3, 1, 2, 1. /// And 7 spaces with 2 positions will be assigned to position 0 and 4 like 4, 3. diff --git a/src/od/parse_formats.rs b/src/od/parse_formats.rs index 472208e5a..6669b09bb 100644 --- a/src/od/parse_formats.rs +++ b/src/od/parse_formats.rs @@ -317,7 +317,7 @@ pub fn parse_format_flags_str(args_str: &Vec<&'static str>) -> Result Err(e), Ok(v) => { - // tests using this function asume add_ascii_dump is not set + // tests using this function assume add_ascii_dump is not set Ok(v.into_iter() .inspect(|f| assert!(!f.add_ascii_dump)) .map(|f| f.formatter_item_info) diff --git a/src/od/prn_float.rs b/src/od/prn_float.rs index 26037c8b4..5162fbc29 100644 --- a/src/od/prn_float.rs +++ b/src/od/prn_float.rs @@ -39,7 +39,7 @@ fn format_flo16(f: f16) -> String { } // formats float with 8 significant digits, eg 12345678 or -1.2345678e+12 -// always retuns a string of 14 characters +// always returns a string of 14 characters fn format_flo32(f: f32) -> String { let width: usize = 14; let precision: usize = 8; diff --git a/src/pathchk/pathchk.rs b/src/pathchk/pathchk.rs index 7f320cfe5..085c92c92 100644 --- a/src/pathchk/pathchk.rs +++ b/src/pathchk/pathchk.rs @@ -33,7 +33,7 @@ enum Mode { static NAME: &'static str = "pathchk"; static VERSION: &'static str = env!("CARGO_PKG_VERSION"); -// a few global constants as used in the GNU implememntation +// a few global constants as used in the GNU implementation static POSIX_PATH_MAX: usize = 256; static POSIX_NAME_MAX: usize = 14; @@ -207,7 +207,7 @@ fn check_searchable(path: &String) -> bool { } } -// check for a hypthen at the beginning of a path segment +// check for a hyphen at the beginning of a path segment fn no_leading_hyphen(path_segment: &String) -> bool { !path_segment.starts_with('-') } diff --git a/src/printf/tokenize/num_format/formatters/cninetyninehexfloatf.rs b/src/printf/tokenize/num_format/formatters/cninetyninehexfloatf.rs index 3c65d436e..8dcd93187 100644 --- a/src/printf/tokenize/num_format/formatters/cninetyninehexfloatf.rs +++ b/src/printf/tokenize/num_format/formatters/cninetyninehexfloatf.rs @@ -41,7 +41,7 @@ impl Formatter for CninetyNineHexFloatf { // c99 hex has unique requirements of all floating point subs in pretty much every part of building a primitive, from prefix and suffix to need for base conversion (in all other cases if you don't have decimal you must have decimal, here it's the other way around) -// on the todo list is to have a trait for get_primitive that is implemented by each float formatter and can override a default. when that happens we can take the parts of get_primitive_dec specific to dec and spin them out to their own functions that can be overriden. +// on the todo list is to have a trait for get_primitive that is implemented by each float formatter and can override a default. when that happens we can take the parts of get_primitive_dec specific to dec and spin them out to their own functions that can be overridden. #[allow(unused_variables)] #[allow(unused_assignments)] fn get_primitive_hex(inprefix: &InPrefix, @@ -93,7 +93,7 @@ fn get_primitive_hex(inprefix: &InPrefix, // the addition or subtraction of 4 (2**4, because 4 bits in a hex digit) // to the exponent. // decimal's going to be a little more complicated. correct simulation - // of glibc will require after-decimal division to a specified precisino. + // of glibc will require after-decimal division to a specified precision. // the difficult part of this (arrnum_int_div_step) is already implemented. // the hex float name may be a bit misleading in terms of how to go about the diff --git a/src/printf/tokenize/num_format/num_format.rs b/src/printf/tokenize/num_format/num_format.rs index 77a4ef62a..dd2185cb0 100644 --- a/src/printf/tokenize/num_format/num_format.rs +++ b/src/printf/tokenize/num_format/num_format.rs @@ -16,7 +16,7 @@ pub fn warn_expected_numeric(pf_arg: &String) { cli::err_msg(&format!("{}: expected a numeric value", pf_arg)); } -// when character costant arguments have excess characters +// when character constant arguments have excess characters // issue a warning when POSIXLY_CORRECT is not set fn warn_char_constant_ign(remaining_bytes: Vec) { match env::var("POSIXLY_CORRECT") { diff --git a/src/printf/tokenize/token.rs b/src/printf/tokenize/token.rs index 996151cd1..378702682 100644 --- a/src/printf/tokenize/token.rs +++ b/src/printf/tokenize/token.rs @@ -17,7 +17,7 @@ pub trait Token { // at a position in a format string, and sees whether // it can return a token of a type it knows how to produce // if so, return the token, move the iterator past the -// format string text the token repsresents, and if an +// format string text the token represents, and if an // argument is used move the argument iter forward one // creating token of a format string segment should also cause diff --git a/src/printf/tokenize/unescaped_text.rs b/src/printf/tokenize/unescaped_text.rs index 4053d6bba..45f006fdf 100644 --- a/src/printf/tokenize/unescaped_text.rs +++ b/src/printf/tokenize/unescaped_text.rs @@ -170,7 +170,7 @@ impl UnescapedText { } - // take an iteratator to a string, + // take an iterator to a string, // and return a wrapper around a Vec of unescaped bytes // break on encounter of sub symbol ('%[^%]') unless called // through %b subst. diff --git a/src/uucore/utmpx.rs b/src/uucore/utmpx.rs index 8ce06df3e..ddf976ab9 100644 --- a/src/uucore/utmpx.rs +++ b/src/uucore/utmpx.rs @@ -55,7 +55,7 @@ pub unsafe extern "C" fn utmpxname(_file: *const libc::c_char) -> libc::c_int { 0 } -// In case the c_char array doesn' t end with NULL +// In case the c_char array doesn't end with NULL macro_rules! chars2string { ($arr:expr) => ( $arr.iter().take_while(|i| **i > 0).map(|&i| i as u8 as char).collect::() diff --git a/tests/test_od.rs b/tests/test_od.rs index e732de55d..b0de215e2 100644 --- a/tests/test_od.rs +++ b/tests/test_od.rs @@ -16,8 +16,8 @@ static ALPHA_OUT: &'static str = " 0000033 "; -// XXX We could do a better job of ensuring that we have a fresh temp dir to ourself, -// not a general one ful of other proc's leftovers. +// XXX We could do a better job of ensuring that we have a fresh temp dir to ourselves, +// not a general one full of other proc's leftovers. // Test that od can read one file and dump with default format #[test] @@ -72,7 +72,7 @@ fn test_2files() { let _ = remove_file(file2); } -// Test that od gives non-0 exit val for filename that dosen't exist. +// Test that od gives non-0 exit val for filename that doesn't exist. #[test] fn test_no_file() { let temp = env::temp_dir(); From 45ebfdf35faae4266f146e9b2105e797b02f03c2 Mon Sep 17 00:00:00 2001 From: Joseph Crail Date: Fri, 25 Nov 2016 14:58:42 -0500 Subject: [PATCH 3/3] Fix test --- tests/test_who.rs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tests/test_who.rs b/tests/test_who.rs index 79f774a57..c32adac19 100644 --- a/tests/test_who.rs +++ b/tests/test_who.rs @@ -1,3 +1,7 @@ +use common::util::*; + + + #[cfg(target_os = "linux")] #[test] fn test_count() {