Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions fuzz/fuzz_targets/fuzz_cksum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,10 +130,10 @@ fuzz_target!(|_data: &[u8]| {
if let Ok(checksum_file_path) =
generate_checksum_file(algo, &file_path, &selected_digest_opts)
{
print_test_begin(format!("cksum {:?}", args));
print_test_begin(format!("cksum {args:?}"));

if let Ok(content) = fs::read_to_string(&checksum_file_path) {
println!("File content ({})", checksum_file_path);
println!("File content ({checksum_file_path})");
print_or_empty(&content);
} else {
eprintln!("Error reading the checksum file.");
Expand Down
17 changes: 7 additions & 10 deletions fuzz/fuzz_targets/fuzz_common/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ pub fn is_gnu_cmd(cmd_path: &str) -> Result<(), std::io::Error> {
CHECK_GNU.call_once(|| {
let version_output = Command::new(cmd_path).arg("--version").output().unwrap();

println!("version_output {:#?}", version_output);
println!("version_output {version_output:#?}");

let version_str = String::from_utf8_lossy(&version_output.stdout).to_string();
if version_str.contains("GNU coreutils") {
Expand Down Expand Up @@ -112,7 +112,7 @@ where
let original_stdin_fd = if let Some(input_str) = pipe_input {
// we have pipe input
let mut input_file = tempfile::tempfile().unwrap();
write!(input_file, "{}", input_str).unwrap();
write!(input_file, "{input_str}").unwrap();
input_file.seek(SeekFrom::Start(0)).unwrap();

// Redirect stdin to read from the in-memory file
Expand Down Expand Up @@ -320,10 +320,10 @@ pub fn compare_result(
gnu_result: &CommandResult,
fail_on_stderr_diff: bool,
) {
print_section(format!("Compare result for: {} {}", test_type, input));
print_section(format!("Compare result for: {test_type} {input}"));

if let Some(pipe) = pipe_input {
println!("Pipe: {}", pipe);
println!("Pipe: {pipe}");
}

let mut discrepancies = Vec::new();
Expand Down Expand Up @@ -369,16 +369,13 @@ pub fn compare_result(
);
if should_panic {
print_end_with_status(
format!("Test failed and will panic for: {} {}", test_type, input),
format!("Test failed and will panic for: {test_type} {input}"),
false,
);
panic!("Test failed for: {} {}", test_type, input);
panic!("Test failed for: {test_type} {input}");
} else {
print_end_with_status(
format!(
"Test completed with discrepancies for: {} {}",
test_type, input
),
format!("Test completed with discrepancies for: {test_type} {input}"),
false,
);
}
Expand Down
7 changes: 3 additions & 4 deletions fuzz/fuzz_targets/fuzz_common/pretty_print.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ use console::{style, Style};
use similar::TextDiff;

pub fn print_section<S: fmt::Display>(s: S) {
println!("{}", style(format!("=== {}", s)).bold());
println!("{}", style(format!("=== {s}")).bold());
}

pub fn print_subsection<S: fmt::Display>(s: S) {
println!("{}", style(format!("--- {}", s)).bright());
println!("{}", style(format!("--- {s}")).bright());
}

pub fn print_test_begin<S: fmt::Display>(msg: S) {
Expand All @@ -33,9 +33,8 @@ pub fn print_end_with_status<S: fmt::Display>(msg: S, ok: bool) {
};

println!(
"{} {} {}",
"{} {ok} {}",
style("===").bold(), // Kind of gray
ok,
style(msg).bold()
);
}
Expand Down
2 changes: 1 addition & 1 deletion fuzz/fuzz_targets/fuzz_expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ fn generate_expr(max_depth: u32) -> String {
// 90% chance to add an operator followed by a number
if rng.random_bool(0.9) {
let op = *ops.choose(&mut rng).unwrap();
expr.push_str(&format!(" {} ", op));
expr.push_str(&format!(" {op} "));
last_was_operator = true;
}
// 10% chance to add a random string (potentially invalid syntax)
Expand Down
16 changes: 8 additions & 8 deletions fuzz/fuzz_targets/fuzz_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,28 +138,28 @@ fn generate_test_arg() -> String {
if test_arg.arg_type == ArgType::INTEGER {
arg.push_str(&format!(
"{} {} {}",
&rng.random_range(-100..=100).to_string(),
rng.random_range(-100..=100).to_string(),
test_arg.arg,
&rng.random_range(-100..=100).to_string()
rng.random_range(-100..=100).to_string()
));
} else if test_arg.arg_type == ArgType::STRINGSTRING {
let random_str = generate_random_string(rng.random_range(1..=10));
let random_str2 = generate_random_string(rng.random_range(1..=10));

arg.push_str(&format!(
"{} {} {}",
&random_str, test_arg.arg, &random_str2
"{random_str} {} {random_str2}",
test_arg.arg,
));
} else if test_arg.arg_type == ArgType::STRING {
let random_str = generate_random_string(rng.random_range(1..=10));
arg.push_str(&format!("{} {}", test_arg.arg, &random_str));
arg.push_str(&format!("{} {random_str}", test_arg.arg));
} else if test_arg.arg_type == ArgType::FILEFILE {
let path = generate_random_path(&mut rng);
let path2 = generate_random_path(&mut rng);
arg.push_str(&format!("{} {} {}", path, test_arg.arg, path2));
arg.push_str(&format!("{path} {} {path2}", test_arg.arg));
} else if test_arg.arg_type == ArgType::FILE {
let path = generate_random_path(&mut rng);
arg.push_str(&format!("{} {}", test_arg.arg, path));
arg.push_str(&format!("{} {path}", test_arg.arg));
}
}
4 => {
Expand All @@ -176,7 +176,7 @@ fn generate_test_arg() -> String {
.collect();

if let Some(test_arg) = file_test_args.choose(&mut rng) {
arg.push_str(&format!("{}{}", test_arg.arg, path));
arg.push_str(&format!("{}{path}", test_arg.arg));
}
}
}
Expand Down
11 changes: 4 additions & 7 deletions tests/benches/factor/benches/table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ fn table(c: &mut Criterion) {
let mut group = c.benchmark_group("table");
group.throughput(Throughput::Elements(INPUT_SIZE as _));
for a in inputs.take(10) {
let a_str = format!("{:?}", a);
let a_str = format!("{a:?}");
group.bench_with_input(BenchmarkId::new("factor", &a_str), &a, |b, &a| {
b.iter(|| {
for n in a {
Expand All @@ -46,18 +46,15 @@ fn check_personality() {
const PERSONALITY_PATH: &str = "/proc/self/personality";

let p_string = fs::read_to_string(PERSONALITY_PATH)
.unwrap_or_else(|_| panic!("Couldn't read '{}'", PERSONALITY_PATH))
.unwrap_or_else(|_| panic!("Couldn't read '{PERSONALITY_PATH}'"))
.strip_suffix('\n')
.unwrap()
.to_owned();

let personality = u64::from_str_radix(&p_string, 16)
.unwrap_or_else(|_| panic!("Expected a hex value for personality, got '{:?}'", p_string));
.unwrap_or_else(|_| panic!("Expected a hex value for personality, got '{p_string:?}'"));
if personality & ADDR_NO_RANDOMIZE == 0 {
eprintln!(
"WARNING: Benchmarking with ASLR enabled (personality is {:x}), results might not be reproducible.",
personality
);
eprintln!("WARNING: Benchmarking with ASLR enabled (personality is {personality:x}), results might not be reproducible.");
}
}

Expand Down
10 changes: 4 additions & 6 deletions tests/by-util/test_chcon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -596,7 +596,7 @@ fn get_file_context(path: impl AsRef<Path>) -> Result<Option<String>, selinux::e
let path = path.as_ref();
match selinux::SecurityContext::of_path(path, false, false) {
Err(r) => {
println!("get_file_context failed: '{}': {}.", path.display(), &r);
println!("get_file_context failed: '{}': {r}.", path.display());
Err(r)
}

Expand All @@ -615,7 +615,7 @@ fn get_file_context(path: impl AsRef<Path>) -> Result<Option<String>, selinux::e
.next()
.unwrap_or_default();
let context = String::from_utf8(bytes.into()).unwrap_or_default();
println!("get_file_context: '{}' => '{}'.", context, path.display());
println!("get_file_context: '{context}' => '{}'.", path.display());
Ok(Some(context))
}
}
Expand All @@ -632,13 +632,11 @@ fn set_file_context(path: impl AsRef<Path>, context: &str) -> Result<(), selinux
selinux::SecurityContext::from_c_str(&c_context, false).set_for_path(path, false, false);
if let Err(r) = &r {
println!(
"set_file_context failed: '{}' => '{}': {}.",
context,
"set_file_context failed: '{context}' => '{}': {r}.",
path.display(),
r
);
} else {
println!("set_file_context: '{}' => '{}'.", context, path.display());
println!("set_file_context: '{context}' => '{}'.", path.display());
}
r
}
3 changes: 1 addition & 2 deletions tests/by-util/test_chgrp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,7 @@ fn test_preserve_root() {
"./../../../../../../../../../../../../../../",
] {
let expected_error = format!(
"chgrp: it is dangerous to operate recursively on '{}' (same as '/')\nchgrp: use --no-preserve-root to override this failsafe\n",
d,
"chgrp: it is dangerous to operate recursively on '{d}' (same as '/')\nchgrp: use --no-preserve-root to override this failsafe\n",
);
new_ucmd!()
.arg("--preserve-root")
Expand Down
18 changes: 6 additions & 12 deletions tests/by-util/test_chmod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,9 @@ fn run_single_test(test: &TestCase, at: &AtPath, mut ucmd: UCommand) {

assert!(
perms == test.before,
"{}: expected: {:o} got: {:o}",
"{}: expected: {:o} got: {perms:o}",
"setting permissions on test files before actual test run failed",
test.after,
perms
);

for arg in &test.args {
Expand All @@ -61,10 +60,8 @@ fn run_single_test(test: &TestCase, at: &AtPath, mut ucmd: UCommand) {
let perms = at.metadata(TEST_FILE).permissions().mode();
assert!(
perms == test.after,
"{}: expected: {:o} got: {:o}",
ucmd,
"{ucmd}: expected: {:o} got: {perms:o}",
test.after,
perms
);
}

Expand Down Expand Up @@ -243,8 +240,7 @@ fn test_chmod_umask_expected() {
let current_umask = uucore::mode::get_umask();
assert_eq!(
current_umask, 0o022,
"Unexpected umask value: expected 022 (octal), but got {:03o}. Please adjust the test environment.",
current_umask
"Unexpected umask value: expected 022 (octal), but got {current_umask:03o}. Please adjust the test environment.",
);
}

Expand Down Expand Up @@ -847,7 +843,7 @@ fn test_chmod_symlink_to_dangling_target_dereference() {
.arg("u+x")
.arg(symlink)
.fails()
.stderr_contains(format!("cannot operate on dangling symlink '{}'", symlink));
.stderr_contains(format!("cannot operate on dangling symlink '{symlink}'"));
}

#[test]
Expand Down Expand Up @@ -1019,8 +1015,7 @@ fn test_chmod_traverse_symlink_combo() {
let actual_target = at.metadata(target).permissions().mode();
assert_eq!(
actual_target, expected_target_perms,
"For flags {:?}, expected target perms = {:o}, got = {:o}",
flags, expected_target_perms, actual_target
"For flags {flags:?}, expected target perms = {expected_target_perms:o}, got = {actual_target:o}",
);

let actual_symlink = at
Expand All @@ -1029,8 +1024,7 @@ fn test_chmod_traverse_symlink_combo() {
.mode();
assert_eq!(
actual_symlink, expected_symlink_perms,
"For flags {:?}, expected symlink perms = {:o}, got = {:o}",
flags, expected_symlink_perms, actual_symlink
"For flags {flags:?}, expected symlink perms = {expected_symlink_perms:o}, got = {actual_symlink:o}",
);
}
}
2 changes: 1 addition & 1 deletion tests/by-util/test_cksum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1722,7 +1722,7 @@ mod gnu_cksum_base64 {
if ["sysv", "bsd", "crc", "crc32b"].contains(&algo) {
digest.to_string()
} else {
format!("{} (f) = {}", algo.to_uppercase(), digest).replace("BLAKE2B", "BLAKE2b")
format!("{} (f) = {digest}", algo.to_uppercase()).replace("BLAKE2B", "BLAKE2b")
}
}

Expand Down
26 changes: 12 additions & 14 deletions tests/by-util/test_cp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2040,31 +2040,31 @@ fn test_cp_deref_folder_to_folder() {
// No action as this test is disabled but kept in case we want to
// try to make it work in the future.
let a = Command::new("cmd").args(&["/C", "dir"]).output();
println!("output {:#?}", a);
println!("output {a:#?}");

let a = Command::new("cmd")
.args(&["/C", "dir", &at.as_string()])
.output();
println!("output {:#?}", a);
println!("output {a:#?}");

let a = Command::new("cmd")
.args(&["/C", "dir", path_to_new_symlink.to_str().unwrap()])
.output();
println!("output {:#?}", a);
println!("output {a:#?}");

let path_to_new_symlink = at.subdir.join(TEST_COPY_FROM_FOLDER);

let a = Command::new("cmd")
.args(&["/C", "dir", path_to_new_symlink.to_str().unwrap()])
.output();
println!("output {:#?}", a);
println!("output {a:#?}");

let path_to_new_symlink = at.subdir.join(TEST_COPY_TO_FOLDER_NEW);

let a = Command::new("cmd")
.args(&["/C", "dir", path_to_new_symlink.to_str().unwrap()])
.output();
println!("output {:#?}", a);
println!("output {a:#?}");
}

let path_to_new_symlink = at
Expand Down Expand Up @@ -2138,31 +2138,31 @@ fn test_cp_no_deref_folder_to_folder() {
// No action as this test is disabled but kept in case we want to
// try to make it work in the future.
let a = Command::new("cmd").args(&["/C", "dir"]).output();
println!("output {:#?}", a);
println!("output {a:#?}");

let a = Command::new("cmd")
.args(&["/C", "dir", &at.as_string()])
.output();
println!("output {:#?}", a);
println!("output {a:#?}");

let a = Command::new("cmd")
.args(&["/C", "dir", path_to_new_symlink.to_str().unwrap()])
.output();
println!("output {:#?}", a);
println!("output {a:#?}");

let path_to_new_symlink = at.subdir.join(TEST_COPY_FROM_FOLDER);

let a = Command::new("cmd")
.args(&["/C", "dir", path_to_new_symlink.to_str().unwrap()])
.output();
println!("output {:#?}", a);
println!("output {a:#?}");

let path_to_new_symlink = at.subdir.join(TEST_COPY_TO_FOLDER_NEW);

let a = Command::new("cmd")
.args(&["/C", "dir", path_to_new_symlink.to_str().unwrap()])
.output();
println!("output {:#?}", a);
println!("output {a:#?}");
}

let path_to_new_symlink = at
Expand Down Expand Up @@ -2552,7 +2552,7 @@ fn test_closes_file_descriptors() {
// For debugging purposes:
for f in me.fd().unwrap() {
let fd = f.unwrap();
println!("{:?} {:?}", fd, fd.mode());
println!("{fd:?} {:?}", fd.mode());
}

new_ucmd!()
Expand Down Expand Up @@ -6093,9 +6093,7 @@ fn test_cp_preserve_xattr_readonly_source() {
let stdout = String::from_utf8_lossy(&getfattr_output.stdout);
assert!(
stdout.contains(xattr_key),
"Expected '{}' not found in getfattr output:\n{}",
xattr_key,
stdout
"Expected '{xattr_key}' not found in getfattr output:\n{stdout}"
);

at.set_readonly(source_file);
Expand Down
2 changes: 1 addition & 1 deletion tests/by-util/test_csplit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1457,7 +1457,7 @@ fn create_named_pipe_with_writer(path: &str, data: &str) -> std::process::Child
nix::unistd::mkfifo(path, nix::sys::stat::Mode::S_IRWXU).unwrap();
std::process::Command::new("sh")
.arg("-c")
.arg(format!("printf '{}' > {path}", data))
.arg(format!("printf '{data}' > {path}"))
.spawn()
.unwrap()
}
Expand Down
Loading
Loading