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

cksum: handle an error like GNU

This commit is contained in:
Sylvestre Ledru 2024-04-20 21:21:03 +02:00 committed by Ben Wiederhake
parent 10d8fd6f98
commit 234f2f9508
2 changed files with 22 additions and 0 deletions

View file

@ -327,6 +327,8 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
};
let input_length = matches.get_one::<usize>(options::LENGTH);
let check = matches.get_flag(options::CHECK);
let length = if let Some(length) = input_length {
match length.to_owned() {
0 => None,
@ -367,6 +369,14 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
None
};
if algo_name == "bsd" && check {
return Err(io::Error::new(
io::ErrorKind::InvalidInput,
"--check is not supported with --algorithm={bsd,sysv,crc}",
)
.into());
}
let (name, algo, bits) = detect_algo(algo_name, length);
let output_format = if matches.get_flag(options::RAW) {

View file

@ -277,6 +277,18 @@ fn test_untagged_algorithm_stdin() {
}
}
#[test]
fn test_check_algo() {
new_ucmd!()
.arg("-a=bsd")
.arg("--check")
.arg("lorem_ipsum.txt")
.fails()
.no_stdout()
.stderr_contains("cksum: --check is not supported with --algorithm={bsd,sysv,crc}")
.code_is(1);
}
#[test]
fn test_length_with_wrong_algorithm() {
new_ucmd!()