mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-28 03:27:44 +00:00
* Changed dd parsing error message to be in line with GNU dd * Correct logic to make dd incorrect number error message fully compatible with GNU. Add test --------- Co-authored-by: just-an-engineer <Julian.Beltz@zetier.com>
This commit is contained in:
parent
e4749381f9
commit
b89a6255a9
2 changed files with 20 additions and 6 deletions
|
@ -430,7 +430,7 @@ impl std::fmt::Display for ParseError {
|
||||||
write!(f, "Unrecognized conv=CONV -> {arg}")
|
write!(f, "Unrecognized conv=CONV -> {arg}")
|
||||||
}
|
}
|
||||||
Self::MultiplierStringParseFailure(arg) => {
|
Self::MultiplierStringParseFailure(arg) => {
|
||||||
write!(f, "Unrecognized byte multiplier -> {arg}")
|
write!(f, "invalid number: ‘{arg}’")
|
||||||
}
|
}
|
||||||
Self::MultiplierStringOverflow(arg) => {
|
Self::MultiplierStringOverflow(arg) => {
|
||||||
write!(
|
write!(
|
||||||
|
@ -474,8 +474,9 @@ fn show_zero_multiplier_warning() {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Parse bytes using str::parse, then map error if needed.
|
/// Parse bytes using str::parse, then map error if needed.
|
||||||
fn parse_bytes_only(s: &str) -> Result<u64, ParseError> {
|
fn parse_bytes_only(s: &str, i: usize) -> Result<u64, ParseError> {
|
||||||
s.parse()
|
s[..i]
|
||||||
|
.parse()
|
||||||
.map_err(|_| ParseError::MultiplierStringParseFailure(s.to_string()))
|
.map_err(|_| ParseError::MultiplierStringParseFailure(s.to_string()))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -520,9 +521,9 @@ fn parse_bytes_no_x(full: &str, s: &str) -> Result<u64, ParseError> {
|
||||||
return Err(ParseError::InvalidNumber(full.to_string()))
|
return Err(ParseError::InvalidNumber(full.to_string()))
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
(Some(i), None, None) => (parse_bytes_only(&s[..i])?, 1),
|
(Some(i), None, None) => (parse_bytes_only(s, i)?, 1),
|
||||||
(None, Some(i), None) => (parse_bytes_only(&s[..i])?, 2),
|
(None, Some(i), None) => (parse_bytes_only(s, i)?, 2),
|
||||||
(None, None, Some(i)) => (parse_bytes_only(&s[..i])?, 512),
|
(None, None, Some(i)) => (parse_bytes_only(s, i)?, 512),
|
||||||
_ => return Err(ParseError::MultiplierStringParseFailure(full.to_string())),
|
_ => return Err(ParseError::MultiplierStringParseFailure(full.to_string())),
|
||||||
};
|
};
|
||||||
num.checked_mul(multiplier)
|
num.checked_mul(multiplier)
|
||||||
|
|
|
@ -1775,3 +1775,16 @@ fn test_stdin_stdout_not_rewound_even_when_connected_to_seekable_file() {
|
||||||
println!("stdout:\n{}", out_file_content);
|
println!("stdout:\n{}", out_file_content);
|
||||||
assert_eq!(out_file_content, "bde");
|
assert_eq!(out_file_content, "bde");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_wrong_number_err_msg() {
|
||||||
|
new_ucmd!()
|
||||||
|
.args(&["count=kBb"])
|
||||||
|
.fails()
|
||||||
|
.stderr_contains("dd: invalid number: ‘kBb’\n");
|
||||||
|
|
||||||
|
new_ucmd!()
|
||||||
|
.args(&["count=1kBb555"])
|
||||||
|
.fails()
|
||||||
|
.stderr_contains("dd: invalid number: ‘1kBb555’\n");
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue