From dc5342d115dd3e70bd4d195f19c2be8b23a60787 Mon Sep 17 00:00:00 2001 From: Sylvestre Ledru Date: Sat, 20 Apr 2024 15:14:11 +0200 Subject: [PATCH] hashsum: allow multiple usage of -l and take the last one tested by gnu/tests/cksum/b2sum.sh --- src/uu/hashsum/src/hashsum.rs | 3 ++- tests/by-util/test_hashsum.rs | 16 ++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/src/uu/hashsum/src/hashsum.rs b/src/uu/hashsum/src/hashsum.rs index 708596096..39b5a0a07 100644 --- a/src/uu/hashsum/src/hashsum.rs +++ b/src/uu/hashsum/src/hashsum.rs @@ -481,7 +481,8 @@ fn uu_app_opt_length(command: Command) -> Command { .long("length") .help("digest length in bits; must not exceed the max for the blake2 algorithm (512) and must be a multiple of 8") .value_name("BITS") - .value_parser(parse_bit_num), + .value_parser(parse_bit_num) + .overrides_with("length"), ) } diff --git a/tests/by-util/test_hashsum.rs b/tests/by-util/test_hashsum.rs index a3a5849ff..eed265ac5 100644 --- a/tests/by-util/test_hashsum.rs +++ b/tests/by-util/test_hashsum.rs @@ -180,6 +180,22 @@ fn test_check_b2sum_length_option_0() { .stdout_only("testf: OK\n"); } +#[test] +fn test_check_b2sum_length_duplicate() { + let scene = TestScenario::new(util_name!()); + let at = &scene.fixtures; + + at.write("testf", "foobar\n"); + + scene + .ccmd("b2sum") + .arg("--length=123") + .arg("--length=128") + .arg("testf") + .succeeds() + .stdout_contains("d6d45901dec53e65d2b55fb6e2ab67b0"); +} + #[test] fn test_check_b2sum_length_option_8() { let scene = TestScenario::new(util_name!());