diff --git a/tests/by-util/test_cksum.rs b/tests/by-util/test_cksum.rs index 5a46da22b..4f2b0e467 100644 --- a/tests/by-util/test_cksum.rs +++ b/tests/by-util/test_cksum.rs @@ -80,6 +80,34 @@ fn test_nonexisting_file() { .stderr_contains(format!("cksum: {file_name}: No such file or directory")); } +#[test] +fn test_one_nonexisting_file() { + let (at, mut ucmd) = at_and_ucmd!(); + + at.touch("abc.txt"); + at.touch("xyz.txt"); + + ucmd.arg("abc.txt") + .arg("asdf.txt") + .arg("xyz.txt") + .fails() + .stdout_contains_line("4294967295 0 xyz.txt") + .stderr_contains("asdf.txt: No such file or directory") + .stdout_contains_line("4294967295 0 abc.txt"); +} + +#[test] +fn test_folder() { + let (at, mut ucmd) = at_and_ucmd!(); + + let folder_name = "a_folder"; + at.mkdir(folder_name); + + ucmd.arg(folder_name) + .succeeds() + .stdout_only(format!("4294967295 0 {folder_name}\n")); +} + // Make sure crc is correct for files larger than 32 bytes // but <128 bytes (1 fold pclmul) // spell-checker:disable-line #[test] @@ -276,93 +304,15 @@ fn test_length_is_zero() { } #[test] -fn test_raw_single_file() { - for algo in ALGOS { - new_ucmd!() - .arg("--raw") - .arg("lorem_ipsum.txt") - .arg(format!("--algorithm={algo}")) - .succeeds() - .no_stderr() - .stdout_is_fixture_bytes(format!("raw/{algo}_single_file.expected")); - } -} -#[test] -fn test_raw_multiple_files() { - new_ucmd!() - .arg("--raw") - .arg("lorem_ipsum.txt") - .arg("alice_in_wonderland.txt") - .fails() - .no_stdout() - .stderr_contains("cksum: the --raw option is not supported with multiple files") - .code_is(1); -} - -#[test] -fn test_fail_on_folder() { +fn test_blake2b_fail_on_directory() { let (at, mut ucmd) = at_and_ucmd!(); let folder_name = "a_folder"; at.mkdir(folder_name); - ucmd.arg(folder_name) + ucmd.arg("--algorithm=blake2b") + .arg(folder_name) .fails() .no_stdout() .stderr_contains(format!("cksum: {folder_name}: Is a directory")); } - -#[test] -fn test_all_algorithms_fail_on_folder() { - let scene = TestScenario::new(util_name!()); - - let at = &scene.fixtures; - - let folder_name = "a_folder"; - at.mkdir(folder_name); - - for algo in ALGOS { - scene - .ucmd() - .arg(format!("--algorithm={algo}")) - .arg(folder_name) - .fails() - .no_stdout() - .stderr_contains(format!("cksum: {folder_name}: Is a directory")); - } -} - -#[test] -fn test_folder_and_file() { - let scene = TestScenario::new(util_name!()); - - let at = &scene.fixtures; - - let folder_name = "a_folder"; - at.mkdir(folder_name); - - scene - .ucmd() - .arg(folder_name) - .arg("lorem_ipsum.txt") - .fails() - .stderr_contains(format!("cksum: {folder_name}: Is a directory")) - .stdout_is_fixture("crc_single_file.expected"); -} - -#[test] -fn test_one_nonexisting_file(){ - let (at, mut ucmd) = at_and_ucmd!(); - - at.touch("abc.txt"); - at.touch("xyz.txt"); - - ucmd - .arg("abc.txt") - .arg("asdf.txt") - .arg("xyz.txt") - .fails() - .stdout_contains_line("4294967295 0 xyz.txt") - .stderr_contains("asdf.txt: No such file or directory") - .stdout_contains_line("4294967295 0 abc.txt"); -} \ No newline at end of file