Repository navigation
Conversation
|
What is purpose of this refactoring; is it intended to support further changes? |
|
No. This PR just drops tests we don't need to verify. |
|
In that case would you drop the refactoring and just remove the test. |
|
No. If |
In that case, I don't think this change is justified. The refactoring makes the code more difficult to understand without providing any meaningful benefit. |
Co-authored-by: Daniel Hofstetter <daniel.hofstetter@42dh.com>
|
An alternative idea is to modify the proposed helper function a bit to also create the error, something like: fn create_err(e: &std::num::ParseIntError, arg: &str) -> Box<dyn UError> {
let msg = if *e.kind() == IntErrorKind::PosOverflow {
translate!("stty-error-invalid-integer-argument-value-too-large", "value" => format!("'{arg}'"))
} else {
translate!("stty-error-invalid-integer-argument", "value" => format!("'{arg}'"))
};
USimpleError::new(1, msg)
}And then use it like: let n = line.parse::<u8>().map_err(|e| create_err(&e, line))?; |
|
Including |
6565ce3 to
cc471b2
Compare
|
I don't think this refactoring solely to remove a test is worthwhile. Could we keep the parsing logic returning a fn try_parse_u8(arg: &str) -> Result<u8, T> |
|
We don't have similar fn for u32, usize, etc... yet. But I don't like to have a fn specialized for parsing u8.
|
|
I think the reduction of tests is "only" a side effect of the refactoring. For me it is about readability. The first thought when I see a call of |
|
An another thought about this: we accepts different stderr with GNU. Then someone can try to patch GnuTests to accept raw |
Right, the existing function is badly named, it could be something like: |
| #[test] | ||
| fn test_parse_u8_or_err_overflow() { | ||
| // Test that overflow values return an error | ||
| fn test_create_parse_err_overflow() { |
There was a problem hiding this comment.
tests/by-util/test_stty.rs already checks both messages for line/min/time, do we still need these unit tests?
There was a problem hiding this comment.
I'm fine to drop. But some tests are platform specific at there.
fn parse_u8_or_erris mixing logic for parsingu8and processing the error message.We don't need to test logic of
.parse::<u8>if they are separated.