tests: fix some clippy warnings

This commit is contained in:
Sylvestre Ledru 2024-05-25 09:02:54 +02:00
parent 4534f359f2
commit 09e53f3d2d
9 changed files with 52 additions and 72 deletions

View file

@ -318,13 +318,13 @@ fn test_invalid_substr() {
.stdout_only("\n");
new_ucmd!()
.args(&["substr", "abc", &(std::usize::MAX.to_string() + "0"), "1"])
.args(&["substr", "abc", &(usize::MAX.to_string() + "0"), "1"])
.fails()
.code_is(1)
.stdout_only("\n");
new_ucmd!()
.args(&["substr", "abc", "0", &(std::usize::MAX.to_string() + "0")])
.args(&["substr", "abc", "0", &(usize::MAX.to_string() + "0")])
.fails()
.code_is(1)
.stdout_only("\n");

View file

@ -472,7 +472,7 @@ fn test_with_escape_filename() {
at.touch(filename);
let result = scene.ccmd("md5sum").arg("--text").arg(filename).succeeds();
let stdout = result.stdout_str();
println!("stdout {}", stdout);
println!("stdout {stdout}");
assert!(stdout.starts_with('\\'));
assert!(stdout.trim().ends_with("a\\nb"));
}
@ -492,7 +492,7 @@ fn test_with_escape_filename_zero_text() {
.arg(filename)
.succeeds();
let stdout = result.stdout_str();
println!("stdout {}", stdout);
println!("stdout {stdout}");
assert!(!stdout.starts_with('\\'));
assert!(stdout.contains("a\nb"));
}
@ -526,7 +526,7 @@ fn test_check_with_escape_filename() {
at.touch(filename);
let result = scene.ccmd("md5sum").arg("--tag").arg(filename).succeeds();
let stdout = result.stdout_str();
println!("stdout {}", stdout);
println!("stdout {stdout}");
assert!(stdout.starts_with("\\MD5"));
assert!(stdout.contains("a\\nb"));
at.write("check.md5", stdout);

View file

@ -159,7 +159,7 @@ fn get_filesystem_type(scene: &TestScenario, path: &Path) -> String {
cmd.args(&["-PT"]).arg(path);
let output = cmd.succeeds();
let stdout_str = String::from_utf8_lossy(output.stdout());
println!("output of stat call ({:?}):\n{}", cmd, stdout_str);
println!("output of stat call ({cmd:?}):\n{stdout_str}");
let regex_str = r#"Filesystem\s+Type\s+.+[\r\n]+([^\s]+)\s+(?<fstype>[^\s]+)\s+"#;
let regex = Regex::new(regex_str).unwrap();
let m = regex.captures(&stdout_str).unwrap();
@ -2243,7 +2243,7 @@ fn test_ls_color() {
.arg("-w=15")
.arg("-C")
.succeeds();
let expected = format!("{} test-color\x0ab {}", a_with_colors, z_with_colors);
let expected = format!("{a_with_colors} test-color\x0ab {z_with_colors}");
assert_eq!(
result.stdout_str().escape_default().to_string(),
expected.escape_default().to_string()
@ -3888,7 +3888,7 @@ fn test_device_number() {
let blk_dev_meta = metadata(blk_dev_path.as_path()).unwrap();
let blk_dev_number = blk_dev_meta.rdev() as dev_t;
let (major, minor) = unsafe { (major(blk_dev_number), minor(blk_dev_number)) };
let major_minor_str = format!("{}, {}", major, minor);
let major_minor_str = format!("{major}, {minor}");
let scene = TestScenario::new(util_name!());
scene
@ -4000,7 +4000,7 @@ fn test_ls_dired_recursive_multiple() {
.skip(1)
.map(|s| s.parse().unwrap())
.collect();
println!("Parsed byte positions: {:?}", positions);
println!("Parsed byte positions: {positions:?}");
assert_eq!(positions.len() % 2, 0); // Ensure there's an even number of positions
let filenames: Vec<String> = positions
@ -4017,7 +4017,7 @@ fn test_ls_dired_recursive_multiple() {
})
.collect();
println!("Extracted filenames: {:?}", filenames);
println!("Extracted filenames: {filenames:?}");
assert_eq!(filenames, vec!["d1", "d2", "f1", "file-long", "a", "c2"]);
}
@ -4087,7 +4087,7 @@ fn test_ls_dired_complex() {
}
let output = result.stdout_str().to_string();
println!("Output:\n{}", output);
println!("Output:\n{output}");
let dired_line = output
.lines()

View file

@ -93,7 +93,7 @@ fn test_very_large_range() {
let num_samples = 10;
let result = new_ucmd!()
.arg("-n")
.arg(&num_samples.to_string())
.arg(num_samples.to_string())
.arg("-i0-1234567890")
.succeeds();
result.no_stderr();
@ -117,7 +117,7 @@ fn test_very_large_range_offset() {
let num_samples = 10;
let result = new_ucmd!()
.arg("-n")
.arg(&num_samples.to_string())
.arg(num_samples.to_string())
.arg("-i1234567890-2147483647")
.succeeds();
result.no_stderr();
@ -140,7 +140,7 @@ fn test_very_large_range_offset() {
#[test]
fn test_range_repeat_no_overflow_1_max() {
let upper_bound = std::usize::MAX;
let upper_bound = usize::MAX;
let result = new_ucmd!()
.arg("-rn1")
.arg(&format!("-i1-{upper_bound}"))
@ -255,7 +255,7 @@ fn test_range_repeat() {
let result = new_ucmd!()
.arg("-r")
.arg("-n")
.arg(&num_samples.to_string())
.arg(num_samples.to_string())
.arg("-i12-34")
.succeeds();
result.no_stderr();
@ -472,9 +472,9 @@ fn test_head_count_multi_big_then_small() {
let result = new_ucmd!()
.arg("-n")
.arg(&(repeat_limit + 1).to_string())
.arg((repeat_limit + 1).to_string())
.arg("-n")
.arg(&repeat_limit.to_string())
.arg(repeat_limit.to_string())
.pipe_in(input.as_bytes())
.succeeds();
result.no_stderr();
@ -505,9 +505,9 @@ fn test_head_count_multi_small_then_big() {
let result = new_ucmd!()
.arg("-n")
.arg(&repeat_limit.to_string())
.arg(repeat_limit.to_string())
.arg("-n")
.arg(&(repeat_limit + 1).to_string())
.arg((repeat_limit + 1).to_string())
.pipe_in(input.as_bytes())
.succeeds();
result.no_stderr();

View file

@ -4307,18 +4307,14 @@ fn test_follow_when_file_and_symlink_are_pointing_to_same_file_and_append_data()
at.append(path_name, more_data);
let expected_stdout = format!(
"==> {0} <==\n\
{1}\n\
==> {2} <==\n\
{1}\n\
==> {0} <==\n\
{3}\n\
==> {2} <==\n\
{3}",
path_name, // 0
file_data, // 1
link_name, // 2
more_data, // 3
"==> {path_name} <==\n\
{file_data}\n\
==> {link_name} <==\n\
{file_data}\n\
==> {path_name} <==\n\
{more_data}\n\
==> {link_name} <==\n\
{more_data}"
);
child.make_assertion_with_delay(500).is_alive();
@ -4345,18 +4341,14 @@ fn test_follow_when_file_and_symlink_are_pointing_to_same_file_and_append_data()
at.append(path_name, more_data);
let expected_stdout = format!(
"==> {0} <==\n\
{1}\n\
==> {2} <==\n\
{1}\n\
==> {0} <==\n\
{3}\n\
==> {2} <==\n\
{3}",
link_name, // 0
file_data, // 1
path_name, // 2
more_data, // 3
"==> {link_name} <==\n\
{file_data}\n\
==> {path_name} <==\n\
{file_data}\n\
==> {link_name} <==\n\
{more_data}\n\
==> {path_name} <==\n\
{more_data}"
);
child.make_assertion_with_delay(500).is_alive();
@ -4375,9 +4367,8 @@ fn test_args_when_directory_given_shorthand_big_f_together_with_retry() {
let dirname = "dir";
at.mkdir(dirname);
let expected_stderr = format!(
"tail: error reading '{0}': Is a directory\n\
tail: {0}: cannot follow end of this type of file\n",
dirname
"tail: error reading '{dirname}': Is a directory\n\
tail: {dirname}: cannot follow end of this type of file\n"
);
let mut child = scene.ucmd().args(&["-F", "--retry", "dir"]).run_no_wait();

View file

@ -245,7 +245,7 @@ fn test_is_directory() {
ucmd.arg(dir_name)
.fails()
.stderr_contains(format!("unexpand: {}: Is a directory", dir_name));
.stderr_contains(format!("unexpand: {dir_name}: Is a directory"));
}
#[test]

View file

@ -446,7 +446,7 @@ fn test_files_from_pseudo_filesystem() {
let actual = at.read("/sys/kernel/profiling").len();
assert_eq!(
result.stdout_str(),
format!("{} /sys/kernel/profiling\n", actual)
format!("{actual} /sys/kernel/profiling\n")
);
}
}

View file

@ -77,9 +77,9 @@ fn read_scenario_fixture<S: AsRef<OsStr>>(tmpd: &Option<Rc<TempDir>>, 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<String>,
//tmpd is used for convenience functions for asserts against fixtures
tmpd: Option<Rc<TempDir>>,
@ -1446,7 +1446,7 @@ impl UCommand {
/// This is useful to test behavior that is only active if e.g. [`stdout.is_terminal()`] is [`true`].
/// This function uses default terminal size and attaches stdin, stdout and stderr to that terminal.
/// For more control over the terminal simulation, use `terminal_sim_stdio`
/// (unix: pty, windows: ConPTY[not yet supported])
/// (unix: pty, windows: `ConPTY`[not yet supported])
#[cfg(unix)]
pub fn terminal_simulation(&mut self, enable: bool) -> &mut Self {
if enable {
@ -1483,7 +1483,7 @@ impl UCommand {
// Input/output error (os error 5) is returned due to pipe closes. Buffer gets content anyway.
Err(e) if e.raw_os_error().unwrap_or_default() == 5 => {}
Err(e) => {
eprintln!("Unexpected error: {:?}", e);
eprintln!("Unexpected error: {e:?}");
panic!("error forwarding output of pty");
}
}
@ -1754,7 +1754,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()
}
@ -1762,7 +1762,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<T: Into<Vec<u8>>>(&mut self, input: T) -> CmdResult {
self.pipe_in(input).run()
}
@ -3840,7 +3840,7 @@ mod tests {
std::assert_eq!(
String::from_utf8_lossy(out.stdout()),
format!("{}\r\n", message)
format!("{message}\r\n")
);
std::assert_eq!(String::from_utf8_lossy(out.stderr()), "");
}

View file

@ -114,15 +114,10 @@ fn util_invalid_name_help() {
assert_eq!(output.status.code(), Some(0));
assert_eq!(output.stderr, b"");
let output_str = String::from_utf8(output.stdout).unwrap();
assert!(
output_str.contains("(multi-call binary)"),
"{:?}",
output_str
);
assert!(output_str.contains("(multi-call binary)"), "{output_str:?}");
assert!(
output_str.contains("Usage: invalid_name [function "),
"{:?}",
output_str
"{output_str:?}"
);
}
@ -155,15 +150,10 @@ fn util_non_utf8_name_help() {
assert_eq!(output.status.code(), Some(0));
assert_eq!(output.stderr, b"");
let output_str = String::from_utf8(output.stdout).unwrap();
assert!(
output_str.contains("(multi-call binary)"),
"{:?}",
output_str
);
assert!(output_str.contains("(multi-call binary)"), "{output_str:?}");
assert!(
output_str.contains("Usage: <unknown binary name> [function "),
"{:?}",
output_str
"{output_str:?}"
);
}
@ -217,8 +207,7 @@ fn util_completion() {
let output_str = String::from_utf8(output.stdout).unwrap();
assert!(
output_str.contains("using namespace System.Management.Automation"),
"{:?}",
output_str
"{output_str:?}"
);
}
@ -243,5 +232,5 @@ fn util_manpage() {
assert_eq!(output.status.code(), Some(0));
assert_eq!(output.stderr, b"");
let output_str = String::from_utf8(output.stdout).unwrap();
assert!(output_str.contains("\n.TH true 1 "), "{:?}", output_str);
assert!(output_str.contains("\n.TH true 1 "), "{output_str:?}");
}