1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-09-15 19:36:16 +00:00

Fix some clippy warnings

Fixed with `cargo clippy --features unix  --fix`
and manually
This commit is contained in:
Sylvestre Ledru 2022-10-12 22:04:21 +02:00
parent 32b1fc6420
commit 6e14dea73b
32 changed files with 122 additions and 126 deletions

View file

@ -76,9 +76,10 @@ fn test_wrap() {
#[test]
fn test_wrap_no_arg() {
for wrap_param in ["-w", "--wrap"] {
new_ucmd!().arg(wrap_param).fails().stderr_contains(
&"The argument '--wrap <wrap>' requires a value but none was supplied",
);
new_ucmd!()
.arg(wrap_param)
.fails()
.stderr_contains("The argument '--wrap <wrap>' requires a value but none was supplied");
}
}

View file

@ -8,7 +8,7 @@ use std::ffi::OsStr;
fn test_help() {
for help_flg in ["-h", "--help"] {
new_ucmd!()
.arg(&help_flg)
.arg(help_flg)
.succeeds()
.no_stderr()
.stdout_contains("USAGE:");
@ -19,7 +19,7 @@ fn test_help() {
fn test_version() {
for version_flg in ["-V", "--version"] {
assert!(new_ucmd!()
.arg(&version_flg)
.arg(version_flg)
.succeeds()
.no_stderr()
.stdout_str()

View file

@ -380,7 +380,7 @@ fn test_chmod_non_existing_file() {
.arg("-r,a+w")
.arg("does-not-exist")
.fails()
.stderr_contains(&"cannot access 'does-not-exist': No such file or directory");
.stderr_contains("cannot access 'does-not-exist': No such file or directory");
}
#[test]
@ -403,7 +403,7 @@ fn test_chmod_preserve_root() {
.arg("755")
.arg("/")
.fails()
.stderr_contains(&"chmod: it is dangerous to operate recursively on '/'");
.stderr_contains("chmod: it is dangerous to operate recursively on '/'");
}
#[test]

View file

@ -107,7 +107,7 @@ fn test_chown_only_owner() {
.arg("--verbose")
.arg(file1)
.run();
result.stderr_contains(&"retained as");
result.stderr_contains("retained as");
// try to change to another existing user, e.g. 'root'
scene
@ -116,7 +116,7 @@ fn test_chown_only_owner() {
.arg("--verbose")
.arg(file1)
.fails()
.stderr_contains(&"failed to change");
.stderr_contains("failed to change");
}
#[test]
@ -142,7 +142,7 @@ fn test_chown_only_owner_colon() {
.arg("--verbose")
.arg(file1)
.succeeds()
.stderr_contains(&"retained as");
.stderr_contains("retained as");
scene
.ucmd()
@ -150,7 +150,7 @@ fn test_chown_only_owner_colon() {
.arg("--verbose")
.arg(file1)
.succeeds()
.stderr_contains(&"retained as");
.stderr_contains("retained as");
scene
.ucmd()
@ -158,7 +158,7 @@ fn test_chown_only_owner_colon() {
.arg("--verbose")
.arg(file1)
.fails()
.stderr_contains(&"failed to change");
.stderr_contains("failed to change");
}
#[test]
@ -179,7 +179,7 @@ fn test_chown_only_colon() {
if skipping_test_is_okay(&result, "No such id") {
return;
}
result.stderr_contains(&"retained as"); // TODO: verbose is not printed to stderr in GNU chown
result.stderr_contains("retained as"); // TODO: verbose is not printed to stderr in GNU chown
// test chown : file.txt
// expected:
@ -192,7 +192,7 @@ fn test_chown_only_colon() {
.arg("--verbose")
.arg(file1)
.fails()
.stderr_contains(&"invalid group: '::'");
.stderr_contains("invalid group: '::'");
scene
.ucmd()
@ -200,7 +200,7 @@ fn test_chown_only_colon() {
.arg("--verbose")
.arg(file1)
.fails()
.stderr_contains(&"invalid group: '..'");
.stderr_contains("invalid group: '..'");
}
#[test]
@ -251,7 +251,7 @@ fn test_chown_owner_group() {
if skipping_test_is_okay(&result, "chown: invalid group:") {
return;
}
result.stderr_contains(&"retained as");
result.stderr_contains("retained as");
scene
.ucmd()
@ -259,7 +259,7 @@ fn test_chown_owner_group() {
.arg("--verbose")
.arg(file1)
.fails()
.stderr_contains(&"invalid group");
.stderr_contains("invalid group");
scene
.ucmd()
@ -267,7 +267,7 @@ fn test_chown_owner_group() {
.arg("--verbose")
.arg(file1)
.fails()
.stderr_contains(&"invalid group");
.stderr_contains("invalid group");
// TODO: on macos group name is not recognized correctly: "chown: invalid group: 'root:root'
#[cfg(any(windows, all(unix, not(target_os = "macos"))))]
@ -277,7 +277,7 @@ fn test_chown_owner_group() {
.arg("--verbose")
.arg(file1)
.fails()
.stderr_contains(&"failed to change");
.stderr_contains("failed to change");
}
#[test]
@ -316,7 +316,7 @@ fn test_chown_various_input() {
if skipping_test_is_okay(&result, "chown: invalid group:") {
return;
}
result.stderr_contains(&"retained as");
result.stderr_contains("retained as");
// check that username.groupname is understood
let result = scene
@ -328,7 +328,7 @@ fn test_chown_various_input() {
if skipping_test_is_okay(&result, "chown: invalid group:") {
return;
}
result.stderr_contains(&"retained as");
result.stderr_contains("retained as");
// Fails as user.name doesn't exist in the CI
// but it is valid
@ -338,7 +338,7 @@ fn test_chown_various_input() {
.arg("--verbose")
.arg(file1)
.fails()
.stderr_contains(&"chown: invalid user: 'user.name:groupname'");
.stderr_contains("chown: invalid user: 'user.name:groupname'");
}
#[test]
@ -377,7 +377,7 @@ fn test_chown_only_group() {
// With mac into the CI, we can get this answer
return;
}
result.stderr_contains(&"retained as");
result.stderr_contains("retained as");
result.success();
scene
@ -386,7 +386,7 @@ fn test_chown_only_group() {
.arg("--verbose")
.arg(file1)
.fails()
.stderr_contains(&"failed to change");
.stderr_contains("failed to change");
}
#[test]
@ -412,7 +412,7 @@ fn test_chown_only_user_id() {
// stderr: "chown: invalid user: '1001'
return;
}
result.stderr_contains(&"retained as");
result.stderr_contains("retained as");
scene
.ucmd()
@ -420,7 +420,7 @@ fn test_chown_only_user_id() {
.arg("--verbose")
.arg(file1)
.fails()
.stderr_contains(&"failed to change");
.stderr_contains("failed to change");
}
/// Test for setting the owner to a user ID for a user that does not exist.
@ -475,7 +475,7 @@ fn test_chown_only_group_id() {
// With mac into the CI, we can get this answer
return;
}
result.stderr_contains(&"retained as");
result.stderr_contains("retained as");
// Apparently on CI "macos-latest, x86_64-apple-darwin, feat_os_macos"
// the process has the rights to change from runner:staff to runner:wheel
@ -486,7 +486,7 @@ fn test_chown_only_group_id() {
.arg("--verbose")
.arg(file1)
.fails()
.stderr_contains(&"failed to change");
.stderr_contains("failed to change");
}
/// Test for setting the group to a group ID for a group that does not exist.
@ -547,7 +547,7 @@ fn test_chown_owner_group_id() {
// stderr: "chown: invalid user: '1001:116'
return;
}
result.stderr_contains(&"retained as");
result.stderr_contains("retained as");
let result = scene
.ucmd()
@ -560,7 +560,7 @@ fn test_chown_owner_group_id() {
// stderr: "chown: invalid user: '1001.116'
return;
}
result.stderr_contains(&"retained as");
result.stderr_contains("retained as");
scene
.ucmd()
@ -568,7 +568,7 @@ fn test_chown_owner_group_id() {
.arg("--verbose")
.arg(file1)
.fails()
.stderr_contains(&"failed to change");
.stderr_contains("failed to change");
}
#[test]
@ -603,7 +603,7 @@ fn test_chown_owner_group_mix() {
.arg("--verbose")
.arg(file1)
.run();
result.stderr_contains(&"retained as");
result.stderr_contains("retained as");
// TODO: on macos group name is not recognized correctly: "chown: invalid group: '0:root'
#[cfg(any(windows, all(unix, not(target_os = "macos"))))]
@ -613,7 +613,7 @@ fn test_chown_owner_group_mix() {
.arg("--verbose")
.arg(file1)
.fails()
.stderr_contains(&"failed to change");
.stderr_contains("failed to change");
}
#[test]
@ -643,8 +643,8 @@ fn test_chown_recursive() {
.arg("a")
.arg("z")
.run();
result.stderr_contains(&"ownership of 'a/a' retained as");
result.stderr_contains(&"ownership of 'z/y' retained as");
result.stderr_contains("ownership of 'a/a' retained as");
result.stderr_contains("ownership of 'z/y' retained as");
}
#[test]
@ -665,7 +665,7 @@ fn test_root_preserve() {
.arg(user_name)
.arg("/")
.fails();
result.stderr_contains(&"chown: it is dangerous to operate recursively");
result.stderr_contains("chown: it is dangerous to operate recursively");
}
#[cfg(any(target_os = "linux", target_os = "android"))]

View file

@ -352,7 +352,7 @@ fn test_install_target_new_file_failing_nonexistent_parent() {
ucmd.arg(file1)
.arg(format!("{}/{}", dir, file2))
.fails()
.stderr_contains(&"No such file or directory");
.stderr_contains("No such file or directory");
}
#[test]

View file

@ -561,8 +561,8 @@ fn test_ls_a() {
.arg("-a")
.arg("-1")
.succeeds()
.stdout_contains(&".test-1")
.stdout_contains(&"..")
.stdout_contains(".test-1")
.stdout_contains("..")
.stdout_matches(&re_pwd);
scene
@ -590,8 +590,8 @@ fn test_ls_a() {
.arg("-1")
.arg("some-dir")
.succeeds()
.stdout_contains(&".test-2")
.stdout_contains(&"..")
.stdout_contains(".test-2")
.stdout_contains("..")
.no_stderr()
.stdout_matches(&re_pwd);
@ -1821,7 +1821,7 @@ fn test_ls_files_dirs() {
.ucmd()
.arg("doesntexist")
.fails()
.stderr_contains(&"'doesntexist': No such file or directory");
.stderr_contains("'doesntexist': No such file or directory");
// One exists, the other doesn't
scene
@ -1829,8 +1829,8 @@ fn test_ls_files_dirs() {
.arg("a")
.arg("doesntexist")
.fails()
.stderr_contains(&"'doesntexist': No such file or directory")
.stdout_contains(&"a:");
.stderr_contains("'doesntexist': No such file or directory")
.stdout_contains("a:");
}
#[test]
@ -1851,7 +1851,7 @@ fn test_ls_recursive() {
.arg("z")
.arg("-R")
.succeeds()
.stdout_contains(&"z:");
.stdout_contains("z:");
let result = scene
.ucmd()
.arg("--color=never")
@ -1861,7 +1861,7 @@ fn test_ls_recursive() {
.succeeds();
#[cfg(not(windows))]
result.stdout_contains(&"a/b:\nb");
result.stdout_contains("a/b:\nb");
#[cfg(windows)]
result.stdout_contains(&"a\\b:\nb");
}
@ -2014,7 +2014,7 @@ fn test_ls_indicator_style() {
"-p",
] {
// Verify that classify and file-type both contain indicators for symlinks.
scene.ucmd().arg(opt).succeeds().stdout_contains(&"/");
scene.ucmd().arg(opt).succeeds().stdout_contains("/");
}
// Classify, Indicator options should not contain any indicators when value is none.
@ -2030,9 +2030,9 @@ fn test_ls_indicator_style() {
.ucmd()
.arg(opt)
.succeeds()
.stdout_does_not_contain(&"/")
.stdout_does_not_contain(&"@")
.stdout_does_not_contain(&"|");
.stdout_does_not_contain("/")
.stdout_does_not_contain("@")
.stdout_does_not_contain("|");
}
// Classify and File-Type all contain indicators for pipes and links.
@ -2043,8 +2043,8 @@ fn test_ls_indicator_style() {
.ucmd()
.arg(format!("--indicator-style={}", opt))
.succeeds()
.stdout_contains(&"@")
.stdout_contains(&"|");
.stdout_contains("@")
.stdout_contains("|");
}
// Test sockets. Because the canonical way of making sockets to test is with
@ -2631,7 +2631,7 @@ fn test_ls_ignore_hide() {
.arg("--ignore=READ[ME")
.arg("-1")
.succeeds()
.stderr_contains(&"Invalid pattern")
.stderr_contains("Invalid pattern")
.stdout_is("CONTRIBUTING.md\nREADME.md\nREADMECAREFULLY.md\nsome_other_file\n");
scene
@ -2639,7 +2639,7 @@ fn test_ls_ignore_hide() {
.arg("--hide=READ[ME")
.arg("-1")
.succeeds()
.stderr_contains(&"Invalid pattern")
.stderr_contains("Invalid pattern")
.stdout_is("CONTRIBUTING.md\nREADME.md\nREADMECAREFULLY.md\nsome_other_file\n");
}

View file

@ -67,7 +67,7 @@ fn test_mknod_fifo_invalid_extra_operand() {
.arg("1")
.arg("2")
.fails()
.stderr_contains(&"Fifos do not have major and minor device numbers");
.stderr_contains("Fifos do not have major and minor device numbers");
}
#[test]
@ -78,28 +78,28 @@ fn test_mknod_character_device_requires_major_and_minor() {
.arg("c")
.fails()
.status_code(1)
.stderr_contains(&"Special files require major and minor device numbers.");
.stderr_contains("Special files require major and minor device numbers.");
new_ucmd!()
.arg("test_file")
.arg("c")
.arg("1")
.fails()
.status_code(1)
.stderr_contains(&"Special files require major and minor device numbers.");
.stderr_contains("Special files require major and minor device numbers.");
new_ucmd!()
.arg("test_file")
.arg("c")
.arg("1")
.arg("c")
.fails()
.stderr_contains(&"Invalid value \"c\" for '<MINOR>'");
.stderr_contains("Invalid value \"c\" for '<MINOR>'");
new_ucmd!()
.arg("test_file")
.arg("c")
.arg("c")
.arg("1")
.fails()
.stderr_contains(&"Invalid value \"c\" for '<MAJOR>'");
.stderr_contains("Invalid value \"c\" for '<MAJOR>'");
}
#[test]
@ -109,7 +109,7 @@ fn test_mknod_invalid_arg() {
.arg("--foo")
.fails()
.no_stdout()
.stderr_contains(&"Found argument '--foo' which wasn't expected");
.stderr_contains("Found argument '--foo' which wasn't expected");
}
#[test]
@ -123,5 +123,5 @@ fn test_mknod_invalid_mode() {
.fails()
.no_stdout()
.status_code(1)
.stderr_contains(&"invalid mode");
.stderr_contains("invalid mode");
}

View file

@ -81,7 +81,7 @@ fn test_2files() {
// spell-checker:disable-next-line
for (path, data) in [(&file1, "abcdefghijklmnop"), (&file2, "qrstuvwxyz\n")] {
let mut f = File::create(&path).unwrap();
let mut f = File::create(path).unwrap();
assert!(
f.write_all(data.as_bytes()).is_ok(),
"Test setup failed - could not write file"
@ -133,7 +133,7 @@ fn test_from_mixed() {
// spell-checker:disable-next-line
let (data1, data2, data3) = ("abcdefg", "hijklmnop", "qrstuvwxyz\n");
for (path, data) in [(&file1, data1), (&file3, data3)] {
let mut f = File::create(&path).unwrap();
let mut f = File::create(path).unwrap();
assert!(
f.write_all(data.as_bytes()).is_ok(),
"Test setup failed - could not write file"

View file

@ -282,7 +282,7 @@ fn test_filter_with_env_var_set() {
RandomFile::new(&at, name).add_lines(n_lines);
let env_var_value = "some-value";
env::set_var("FILE", &env_var_value);
env::set_var("FILE", env_var_value);
ucmd.args(&[format!("--filter={}", "cat > $FILE").as_str(), name])
.succeeds();

View file

@ -78,7 +78,7 @@ fn test_tee_no_more_writeable_1() {
.pipe_in(&content[..])
.fails()
.stdout_contains(&content)
.stderr_contains(&"No space left on device");
.stderr_contains("No space left on device");
assert_eq!(at.read(file_out), content);
}

View file

@ -31,7 +31,7 @@ fn test_count_bytes_large_stdin() {
.args(&["-c"])
.pipe_in(data)
.succeeds()
.stdout_is_bytes(&expected.as_bytes());
.stdout_is_bytes(expected.as_bytes());
}
}

View file

@ -183,25 +183,25 @@ mod tests {
#[test]
fn test_random_string_generate() {
let random_string = RandomString::generate(&AlphanumericNewline, 0);
let random_string = RandomString::generate(AlphanumericNewline, 0);
assert_eq!(0, random_string.len());
let random_string = RandomString::generate(&AlphanumericNewline, 1);
let random_string = RandomString::generate(AlphanumericNewline, 1);
assert_eq!(1, random_string.len());
let random_string = RandomString::generate(&AlphanumericNewline, 100);
let random_string = RandomString::generate(AlphanumericNewline, 100);
assert_eq!(100, random_string.len());
}
#[test]
fn test_random_string_generate_with_delimiter_when_length_is_zero() {
let random_string = RandomString::generate_with_delimiter(&Alphanumeric, 0, 0, false, 0);
let random_string = RandomString::generate_with_delimiter(Alphanumeric, 0, 0, false, 0);
assert_eq!(0, random_string.len());
}
#[test]
fn test_random_string_generate_with_delimiter_when_num_delimiter_is_greater_than_length() {
let random_string = RandomString::generate_with_delimiter(&Alphanumeric, 0, 2, false, 1);
let random_string = RandomString::generate_with_delimiter(Alphanumeric, 0, 2, false, 1);
assert_eq!(1, random_string.len());
assert!(random_string.as_bytes().contains(&0));
assert!(random_string.as_bytes().ends_with(&[0]));
@ -209,7 +209,7 @@ mod tests {
#[test]
fn test_random_string_generate_with_delimiter_should_end_with_delimiter() {
let random_string = RandomString::generate_with_delimiter(&Alphanumeric, 0, 1, true, 1);
let random_string = RandomString::generate_with_delimiter(Alphanumeric, 0, 1, true, 1);
assert_eq!(1, random_string.len());
assert_eq!(
1,
@ -217,7 +217,7 @@ mod tests {
);
assert!(random_string.as_bytes().ends_with(&[0]));
let random_string = RandomString::generate_with_delimiter(&Alphanumeric, 0, 1, false, 1);
let random_string = RandomString::generate_with_delimiter(Alphanumeric, 0, 1, false, 1);
assert_eq!(1, random_string.len());
assert_eq!(
1,
@ -225,7 +225,7 @@ mod tests {
);
assert!(random_string.as_bytes().ends_with(&[0]));
let random_string = RandomString::generate_with_delimiter(&Alphanumeric, 0, 1, true, 2);
let random_string = RandomString::generate_with_delimiter(Alphanumeric, 0, 1, true, 2);
assert_eq!(2, random_string.len());
assert_eq!(
1,
@ -233,7 +233,7 @@ mod tests {
);
assert!(random_string.as_bytes().ends_with(&[0]));
let random_string = RandomString::generate_with_delimiter(&Alphanumeric, 0, 2, true, 2);
let random_string = RandomString::generate_with_delimiter(Alphanumeric, 0, 2, true, 2);
assert_eq!(2, random_string.len());
assert_eq!(
2,
@ -241,7 +241,7 @@ mod tests {
);
assert!(random_string.as_bytes().ends_with(&[0]));
let random_string = RandomString::generate_with_delimiter(&Alphanumeric, 0, 1, true, 3);
let random_string = RandomString::generate_with_delimiter(Alphanumeric, 0, 1, true, 3);
assert_eq!(3, random_string.len());
assert_eq!(
1,
@ -252,21 +252,21 @@ mod tests {
#[test]
fn test_random_string_generate_with_delimiter_should_not_end_with_delimiter() {
let random_string = RandomString::generate_with_delimiter(&Alphanumeric, 0, 0, false, 1);
let random_string = RandomString::generate_with_delimiter(Alphanumeric, 0, 0, false, 1);
assert_eq!(1, random_string.len());
assert_eq!(
0,
random_string.as_bytes().iter().filter(|p| **p == 0).count()
);
let random_string = RandomString::generate_with_delimiter(&Alphanumeric, 0, 0, true, 1);
let random_string = RandomString::generate_with_delimiter(Alphanumeric, 0, 0, true, 1);
assert_eq!(1, random_string.len());
assert_eq!(
0,
random_string.as_bytes().iter().filter(|p| **p == 0).count()
);
let random_string = RandomString::generate_with_delimiter(&Alphanumeric, 0, 1, false, 2);
let random_string = RandomString::generate_with_delimiter(Alphanumeric, 0, 1, false, 2);
assert_eq!(2, random_string.len());
assert_eq!(
1,
@ -274,7 +274,7 @@ mod tests {
);
assert!(!random_string.as_bytes().ends_with(&[0]));
let random_string = RandomString::generate_with_delimiter(&Alphanumeric, 0, 1, false, 3);
let random_string = RandomString::generate_with_delimiter(Alphanumeric, 0, 1, false, 3);
assert_eq!(3, random_string.len());
assert_eq!(
1,
@ -282,7 +282,7 @@ mod tests {
);
assert!(!random_string.as_bytes().ends_with(&[0]));
let random_string = RandomString::generate_with_delimiter(&Alphanumeric, 0, 2, false, 3);
let random_string = RandomString::generate_with_delimiter(Alphanumeric, 0, 2, false, 3);
assert_eq!(3, random_string.len());
assert_eq!(
2,
@ -294,7 +294,7 @@ mod tests {
#[test]
fn test_generate_with_delimiter_with_greater_length() {
let random_string =
RandomString::generate_with_delimiter(&Alphanumeric, 0, 100, false, 1000);
RandomString::generate_with_delimiter(Alphanumeric, 0, 100, false, 1000);
assert_eq!(1000, random_string.len());
assert_eq!(
100,
@ -302,8 +302,7 @@ mod tests {
);
assert!(!random_string.as_bytes().ends_with(&[0]));
let random_string =
RandomString::generate_with_delimiter(&Alphanumeric, 0, 100, true, 1000);
let random_string = RandomString::generate_with_delimiter(Alphanumeric, 0, 100, true, 1000);
assert_eq!(1000, random_string.len());
assert_eq!(
100,
@ -325,7 +324,7 @@ mod tests {
let length = 8192 * 3 + 1;
let random_string =
RandomString::generate_with_delimiter(&Alphanumeric, b'\n', 100, true, length);
RandomString::generate_with_delimiter(Alphanumeric, b'\n', 100, true, length);
assert_eq!(length, random_string.len());
assert_eq!(
100,

View file

@ -710,7 +710,7 @@ impl AtPath {
"symlink",
&format!("{},{}", &original, &self.plus_as_string(link)),
);
symlink_file(&original, &self.plus(link)).unwrap();
symlink_file(original, &self.plus(link)).unwrap();
}
pub fn symlink_dir(&self, original: &str, link: &str) {
@ -732,7 +732,7 @@ impl AtPath {
"symlink",
&format!("{},{}", &original, &self.plus_as_string(link)),
);
symlink_dir(&original, &self.plus(link)).unwrap();
symlink_dir(original, &self.plus(link)).unwrap();
}
pub fn is_symlink(&self, path: &str) -> bool {
@ -1445,7 +1445,7 @@ pub fn run_ucmd_as_root(
log_info("run", "sudo -E --non-interactive whoami");
match Command::new("sudo")
.env("LC_ALL", "C")
.args(&["-E", "--non-interactive", "whoami"])
.args(["-E", "--non-interactive", "whoami"])
.output()
{
Ok(output) if String::from_utf8_lossy(&output.stdout).eq("root\n") => {
@ -1833,7 +1833,7 @@ mod tests {
// Skip test if we can't guarantee non-interactive `sudo`, or if we're not "root"
if let Ok(output) = Command::new("sudo")
.env("LC_ALL", "C")
.args(&["-E", "--non-interactive", "whoami"])
.args(["-E", "--non-interactive", "whoami"])
.output()
{
if output.status.success() && String::from_utf8_lossy(&output.stdout).eq("root\n") {