From 1c77f97535f41a61016667f4414080b88f393dd6 Mon Sep 17 00:00:00 2001 From: Sylvestre Ledru Date: Tue, 9 Apr 2024 23:05:07 +0200 Subject: [PATCH 1/2] Some clippy fixes in tests done with: cargo +nightly clippy --tests --fix --allow-dirty -- -W clippy::pedantic --- tests/by-util/test_free.rs | 6 +++--- tests/by-util/test_w.rs | 4 ++-- tests/common/util.rs | 8 ++++---- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/tests/by-util/test_free.rs b/tests/by-util/test_free.rs index 507a260..90f5cd1 100644 --- a/tests/by-util/test_free.rs +++ b/tests/by-util/test_free.rs @@ -17,7 +17,7 @@ fn test_invalid_arg() { #[test] fn test_free() { let result = new_ucmd!().succeeds(); - assert!(result.stdout_str().contains("Mem:")) + assert!(result.stdout_str().contains("Mem:")); } #[test] @@ -44,7 +44,7 @@ fn test_free_column_format() { assert_eq!(free_result.len(), 207); // Check the format for each line output - let mut free_lines = free_result.split("\n"); + let mut free_lines = free_result.split('\n'); for re in re_list { assert!(re.is_match(free_lines.next().unwrap())); } @@ -69,7 +69,7 @@ fn test_free_wide_column_format() { assert_eq!(free_result.len(), 231); // Check the format for each line output - let mut free_lines = free_result.split("\n"); + let mut free_lines = free_result.split('\n'); for re in re_list { assert!(re.is_match(free_lines.next().unwrap())); } diff --git a/tests/by-util/test_w.rs b/tests/by-util/test_w.rs index b5580be..76e893a 100644 --- a/tests/by-util/test_w.rs +++ b/tests/by-util/test_w.rs @@ -27,13 +27,13 @@ fn test_output_format() { let output_lines = cmd.stdout_str().lines(); for line in output_lines { - let line_vec: Vec = line.split_whitespace().map(|s| String::from(s)).collect(); + let line_vec: Vec = line.split_whitespace().map(String::from).collect(); // Check the time formatting, this should be the third entry in list // For now, we are just going to check that that length of time is 5 and it has a colon, else // it is possible that a time can look like Fri13, so it can start with a letter and end // with a number assert!( - (line_vec[2].contains(":") && line_vec[2].chars().count() == 5) + (line_vec[2].contains(':') && line_vec[2].chars().count() == 5) || (line_vec[2].starts_with(char::is_alphabetic) && line_vec[2].ends_with(char::is_numeric) && line_vec[2].chars().count() == 5) diff --git a/tests/common/util.rs b/tests/common/util.rs index 78c43a3..95aa284 100644 --- a/tests/common/util.rs +++ b/tests/common/util.rs @@ -66,9 +66,9 @@ fn read_scenario_fixture>(tmpd: &Option>, file_rel_p /// within a struct which has convenience assertion functions about those outputs #[derive(Debug, Clone)] pub struct CmdResult { - /// bin_path provided by `TestScenario` or `UCommand` + /// `bin_path` provided by `TestScenario` or `UCommand` bin_path: PathBuf, - /// util_name provided by `TestScenario` or `UCommand` + /// `util_name` provided by `TestScenario` or `UCommand` util_name: Option, //tmpd is used for convenience functions for asserts against fixtures tmpd: Option>, @@ -1563,7 +1563,7 @@ impl UCommand { /// Spawns the command, feeds the stdin if any, waits for the result /// and returns a command result. - /// It is recommended that you instead use succeeds() or fails() + /// It is recommended that you instead use `succeeds()` or `fails()` pub fn run(&mut self) -> CmdResult { self.run_no_wait().wait().unwrap() } @@ -1571,7 +1571,7 @@ impl UCommand { /// Spawns the command, feeding the passed in stdin, waits for the result /// and returns a command result. /// It is recommended that, instead of this, you use a combination of `pipe_in()` - /// with succeeds() or fails() + /// with `succeeds()` or `fails()` pub fn run_piped_stdin>>(&mut self, input: T) -> CmdResult { self.pipe_in(input).run() } From dc35e90d89dd97bcc8b05b21b7b6e5279246a82e Mon Sep 17 00:00:00 2001 From: Sylvestre Ledru Date: Tue, 9 Apr 2024 23:09:36 +0200 Subject: [PATCH 2/2] Fix more clippy warnings by hand --- src/bin/procps.rs | 10 ++++------ src/uu/w/src/w.rs | 2 +- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/src/bin/procps.rs b/src/bin/procps.rs index 9a6b157..7d603f4 100644 --- a/src/bin/procps.rs +++ b/src/bin/procps.rs @@ -85,9 +85,8 @@ fn main() { process::exit(1); } - let util = match util_os.to_str() { - Some(util) => util, - None => not_found(&util_os), + let Some(util) = util_os.to_str() else { + not_found(&util_os) }; if util == "completion" { @@ -106,9 +105,8 @@ fn main() { if util == "--help" || util == "-h" { // see if they want help on a specific util if let Some(util_os) = args.next() { - let util = match util_os.to_str() { - Some(util) => util, - None => not_found(&util_os), + let Some(util) = util_os.to_str() else { + not_found(&util_os) }; match utils.get(util) { diff --git a/src/uu/w/src/w.rs b/src/uu/w/src/w.rs index 5b7df7b..6e994ff 100644 --- a/src/uu/w/src/w.rs +++ b/src/uu/w/src/w.rs @@ -4,7 +4,7 @@ // file that was distributed with this source code. #[cfg(not(windows))] -use chrono::{self, Datelike}; +use chrono::Datelike; use clap::crate_version; use clap::{Arg, ArgAction, Command}; use std::process;