1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-07-28 11:37:44 +00:00

Made cksum return an error if used on a directory. (#5822)

* Made cksum to return an error if it is used on a directory regardless of the algorithm

* Added one more test for cksum on folders and deleted an old one that expected it to succeed instead of fail

* Made cksum work on more than one item if it fails and added a test for this case
This commit is contained in:
Atomei Alexandru 2024-01-13 15:43:36 +02:00 committed by GitHub
parent 7e3f4d8358
commit 563df4b79d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 49 additions and 25 deletions

View file

@ -80,18 +80,6 @@ fn test_nonexisting_file() {
.stderr_contains(format!("cksum: {file_name}: No such file or directory"));
}
#[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]
@ -312,15 +300,52 @@ fn test_raw_multiple_files() {
}
#[test]
fn test_blake2b_fail_on_directory() {
fn test_fail_on_folder() {
let (at, mut ucmd) = at_and_ucmd!();
let folder_name = "a_folder";
at.mkdir(folder_name);
ucmd.arg("--algorithm=blake2b")
.arg(folder_name)
ucmd.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");
}