mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-27 19:17:43 +00:00
Merge pull request #7690 from nyurik/manual-inline
chore: manual inline formatting - tests
This commit is contained in:
commit
a77e218a79
26 changed files with 128 additions and 176 deletions
|
@ -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.");
|
||||
|
|
|
@ -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") {
|
||||
|
@ -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
|
||||
|
@ -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();
|
||||
|
@ -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,
|
||||
);
|
||||
}
|
||||
|
|
|
@ -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) {
|
||||
|
@ -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()
|
||||
);
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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 => {
|
||||
|
@ -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));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue