diff --git a/src/uu/cksum/src/cksum.rs b/src/uu/cksum/src/cksum.rs index 1493ce452..b384cd275 100644 --- a/src/uu/cksum/src/cksum.rs +++ b/src/uu/cksum/src/cksum.rs @@ -327,6 +327,8 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> { }; let input_length = matches.get_one::(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) { diff --git a/tests/by-util/test_cksum.rs b/tests/by-util/test_cksum.rs index 112274baf..f25467451 100644 --- a/tests/by-util/test_cksum.rs +++ b/tests/by-util/test_cksum.rs @@ -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!()