-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
hashsum: test b3sum::test_nonames for real #4027
Conversation
src/uu/hashsum/src/hashsum.rs
Outdated
@@ -297,7 +297,7 @@ pub fn uumain(mut args: impl uucore::Args) -> UResult<()> { | |||
}; | |||
let check = matches.contains_id("check"); | |||
let tag = matches.contains_id("tag"); | |||
let nonames = if binary_name == "b3sum" { | |||
let nonames = if binary_name == "b3sum" || matches.try_contains_id("b3sum").is_ok() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think checking whether it is Ok
is not enough. try_contains_id
returns Ok
when the id
is valid (i.e. there is an Arg
in Command
with that id
). We also need it to be present, so Ok(true)
, otherwise nonames
can be true when an algorithm other than b3sum
is used (I put a dbg!(nonames)
on line 305):
❯ cargo run -- hashsum --b2sum --no-names
[src/uu/hashsum/src/hashsum.rs:305] nonames = true
Note that we can assume that b3sum
is a valid id, so matches.contains_id("b3sum)
should be good enough.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, thanks! I didn't tested that part.
I used try_contains_id
because it panics in test_hashsum::test_check_sha1 due to
thread 'test_hashsum::test_check_sha1' panicked at 'Command was expected to succeed.
stdout =
stderr = thread 'main' panicked at 'Mismatch between definition and access of `b3sum`. Unknown argument or group id. Make sure you are using the argument id and not the short or long flags
I thought about using try_contains_id("b3sum").unwrap_or(false)
, but when I run cargo run -- hashsum --b2sum --no-names
nonames
is false and it's unexpected.
If nonames
should be set for all other algorithms according to the no-names
argument, how about this?
let nonames = matches.try_contains_id("no-names").
Or could you suggest any other options that I can take?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh I see! No names should be false for all other algorithms, so try_contains_id
is correct then but we need matches.try_contains_id("b3sum") == Some(true)
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay! Thanks! I'll work on it 😃👍🏻
src/uu/hashsum/src/hashsum.rs
Outdated
@@ -297,7 +297,7 @@ pub fn uumain(mut args: impl uucore::Args) -> UResult<()> { | |||
}; | |||
let check = matches.contains_id("check"); | |||
let tag = matches.contains_id("tag"); | |||
let nonames = if binary_name == "b3sum" || matches.try_contains_id("b3sum").is_ok() { | |||
let nonames = if binary_name == "b3sum" || matches.try_contains_id("b3sum").unwrap_or(false) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I used unwrap_or(false)
as the return type of try_contains_id
is Result<bool, MatchesError>
3dd4d4e
to
18478aa
Compare
Okay, so a funny thing happened because we merged clap 4. Now, ❯ cargo run -- hashsum --b2sum --no-names
[src/uu/hashsum/src/hashsum.rs:305] nonames = true But, that might not be a problem, because we don't actually need let nonames = *matches.get_one("no-names").unwrap_or(&false); Sorry for introducing the weird behaviour with clap and changing my mind about this :) |
Oh.. that's weird. No problem, I will change as you suggested! |
Signed-off-by: Huijeong Kim <[email protected]>
18478aa
to
60e23fc
Compare
src/uu/hashsum/src/hashsum.rs
Outdated
} else { | ||
false | ||
}; | ||
let nonames = *matches.try_get_one("no-names").unwrap_or(Some(&false)).unwrap(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While I change my code, I found another weird behavior of clap.
get_one("no-names")
panics inside the function call if the flag not exist (in test_check_sha1 test), so that it can't handle unwrap_or()
.
So I used try_get_one()
and it returns Result<Option<T>, MatchesError>
. That's why I have two unwraps here..
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh yeah it should have been try_get_one
! I made a mistake indeed :)
@tertsdiepraam are we good here? thanks |
Yeah, looks good! Thanks @huijeong-kim! |
Thank you for your kind review @tertsdiepraam 😄👍 |
Terts is the best! ;) |
That's very kind 😄 Some GNU tests seem to be failing when after merged this: https://github.com/uutils/coreutils/actions/runs/3302752256. I can't reproduce the failure locally though. I'll check whether the issue persists in other runs. |
Oh it fails 🥲 I'll try to find out something from logs.. How can I run the test locally? |
This reverts commit 02f6fa7.
Resolves #3818
Signed-off-by: Huijeong Kim [email protected]