Repository: uutils/coreutils (Rust)

Issue:
Test `test_hashsum::b3sum::test_nonames` for real
Improved in https://github.com/uutils/coreutils/pull/3816 but not enough as it isn't testing it. This patch runs it:

```
diff --git a/tests/by-util/test_hashsum.rs b/tests/by-util/test_hashsum.rs
index 06d039d59..7a87125c8 100644
--- a/tests/by-util/test_hashsum.rs
+++ b/tests/by-util/test_hashsum.rs
@@ -34,7 +34,7 @@ macro_rules! test_digest {
         fn test_nonames() {
             let ts = TestScenario::new("hashsum");
             // EXPECTED_FILE has no newline character at the end
-            if DIGEST_ARG == "b3sum" {
+            if DIGEST_ARG == "--b3sum" {
                 // Option only available on b3sum
                 assert_eq!(format!("{0}\n{0}\n", ts.fixtures.read(EXPECTED_FILE)),
                        ts.ucmd().arg(DIGEST_ARG).arg(BITS_ARG).arg("--no-names").arg("input.txt").arg("-").pipe_in_fixture("input.txt")

```

But fails with:
```

---- test_hashsum::b3sum::test_nonames stdout ----
current_directory_resolved: 
open: /tmp/.tmpc8CYCJ/b3sum.expected
open: /tmp/.tmpc8CYCJ/input.txt
run: /home/sylvestre/dev/debian/coreutils/target/debug/coreutils hashsum --b3sum --bits=256 --no-names input.txt -
thread 'test_hashsum::b3sum::test_nonames' panicked at 'assertion failed: `(left == right)`
  left: `"a1a55887535397bf461902491c8779188a5dd1f8c3951b3d9cf6ecba194e87b0\na1a55887535397bf461902491c8779188a5dd1f8c3951b3d9cf6ecba194e87b0\n"`,
 right: `"a1a55887535397bf461902491c8779188a5dd1f8c3951b3d9cf6ecba194e87b0  input.txt\na1a55887535397bf461902491c8779188a5dd1f8c3951b3d9cf6ecba194e87b0  -\n"`', /home/sylvestre/dev/debian/coreutils/tests/by-util/test_hashsum.rs:83:1
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
```

To run it:
```
cargo test test_hashsum::b3sum::test_nonames      
```


Discussion:
Hi. I want to try this issue but need some help. Is "noname" option only valid for binary_name "b3sum" or binary_name hashmap with "--b3sum" argument? 

Can I change like this?
```rust
let nonames = if binary_name == "b3sum" || matches.try_contains_id("b3sum").is_ok() {
    matches.contains_id("no-names")
} else {
    false
};
```
I think `--no-names` should be accepted in both cases, so your solution seems on the right track.
Thanks a lot! Then I'll submit PR soon. 



Patch:
diff --git a/src/uu/hashsum/src/hashsum.rs b/src/uu/hashsum/src/hashsum.rs
index e2e90434339..255ba2d49e4 100644
--- a/src/uu/hashsum/src/hashsum.rs
+++ b/src/uu/hashsum/src/hashsum.rs
@@ -276,11 +276,10 @@ pub fn uumain(mut args: impl uucore::Args) -> UResult<()> {
     };
     let check = matches.get_flag("check");
     let tag = matches.get_flag("tag");
-    let nonames = if binary_name == "b3sum" {
-        matches.get_flag("no-names")
-    } else {
-        false
-    };
+    let nonames = *matches
+        .try_get_one("no-names")
+        .unwrap_or(Some(&false))
+        .unwrap();
     let status = matches.get_flag("status");
     let quiet = matches.get_flag("quiet") || status;
     let strict = matches.get_flag("strict");


Test patch:
diff --git a/tests/by-util/test_hashsum.rs b/tests/by-util/test_hashsum.rs
index 5fdc6e648fa..d62b662347c 100644
--- a/tests/by-util/test_hashsum.rs
+++ b/tests/by-util/test_hashsum.rs
@@ -34,7 +34,7 @@ macro_rules! test_digest {
         fn test_nonames() {
             let ts = TestScenario::new("hashsum");
             // EXPECTED_FILE has no newline character at the end
-            if DIGEST_ARG == "b3sum" {
+            if DIGEST_ARG == "--b3sum" {
                 // Option only available on b3sum
                 assert_eq!(format!("{0}\n{0}\n", ts.fixtures.read(EXPECTED_FILE)),
                        ts.ucmd().arg(DIGEST_ARG).arg(BITS_ARG).arg("--no-names").arg("input.txt").arg("-").pipe_in_fixture("input.txt")