From 8f269b4e10152b8fb0916720005660eceb220f4d Mon Sep 17 00:00:00 2001 From: tommi Date: Sat, 4 Jan 2025 18:58:02 +0100 Subject: [PATCH 1/2] cksum: test length and blake2b algorithm before testing supported algorithms --- src/uu/cksum/src/cksum.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/uu/cksum/src/cksum.rs b/src/uu/cksum/src/cksum.rs index e96d2de6fcd..64bbf65a497 100644 --- a/src/uu/cksum/src/cksum.rs +++ b/src/uu/cksum/src/cksum.rs @@ -276,10 +276,6 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> { } }; - if ["bsd", "crc", "sysv"].contains(&algo_name) && check { - return Err(ChecksumError::AlgorithmNotSupportedWithCheck.into()); - } - let input_length = matches.get_one::(options::LENGTH); let length = match input_length { @@ -293,6 +289,10 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> { None => None, }; + if ["bsd", "crc", "sysv"].contains(&algo_name) && check { + return Err(ChecksumError::AlgorithmNotSupportedWithCheck.into()); + } + if check { let text_flag = matches.get_flag(options::TEXT); let binary_flag = matches.get_flag(options::BINARY); From 7f9e1697218157180f21f4f63b51bfc24715749c Mon Sep 17 00:00:00 2001 From: tommi Date: Sat, 4 Jan 2025 19:35:25 +0100 Subject: [PATCH 2/2] tests/cksum: test added for checking the length and the blake2b arguments before the check of the supported algorithms --- tests/by-util/test_cksum.rs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/tests/by-util/test_cksum.rs b/tests/by-util/test_cksum.rs index 2efc78b96f3..c213c4a82d5 100644 --- a/tests/by-util/test_cksum.rs +++ b/tests/by-util/test_cksum.rs @@ -352,6 +352,18 @@ fn test_length_not_supported() { .no_stdout() .stderr_contains("--length is only supported with --algorithm=blake2b") .code_is(1); + + new_ucmd!() + .arg("-l") + .arg("158") + .arg("-c") + .arg("-a") + .arg("crc") + .arg("/tmp/xxx") + .fails() + .no_stdout() + .stderr_contains("--length is only supported with --algorithm=blake2b") + .code_is(1); } #[test]