mirror of
https://github.com/uutils/coreutils.git
synced 2026-05-06 07:26:38 -04:00
numfmt: fix --to=auto to return with exitcode=1 (#11701)
* numfmt: fix --to=auto to return with exitcode=1 * numfmt: update direct variable use in format macro * numfmt_test: remove extra test * numfmt: replacing format in translate directly
This commit is contained in:
@@ -68,7 +68,7 @@ numfmt-error-invalid-number = invalid number: { $input }
|
||||
numfmt-error-missing-i-suffix = missing 'i' suffix in input: '{ $number }{ $suffix }' (e.g Ki/Mi/Gi)
|
||||
numfmt-error-rejecting-suffix = rejecting suffix in input: '{ $number }{ $suffix }' (consider using --from)
|
||||
numfmt-error-suffix-unsupported-for-unit = This suffix is unsupported for specified unit
|
||||
numfmt-error-unit-auto-not-supported-with-to = Unit 'auto' isn't supported with --to options
|
||||
numfmt-error-invalid-unit-argument = invalid argument '{$arg}' for '{$opt}'
|
||||
numfmt-error-number-too-big = Number is too big and unsupported
|
||||
numfmt-error-format-no-percent = format '{ $format }' has no % directive
|
||||
numfmt-error-format-ends-in-percent = format '{ $format }' ends in %
|
||||
|
||||
@@ -475,7 +475,11 @@ fn consider_suffix(
|
||||
let (bases, with_i) = match u {
|
||||
Unit::Si => (si_bases_f64(), false),
|
||||
Unit::Iec(with_i) => (iec_bases_f64(), with_i),
|
||||
Unit::Auto => return Err(translate!("numfmt-error-unit-auto-not-supported-with-to")),
|
||||
Unit::Auto => {
|
||||
return Err(
|
||||
translate!("numfmt-error-invalid-unit-argument", "arg" => "auto", "opt" => "--to"),
|
||||
);
|
||||
}
|
||||
Unit::None => return Ok((n, None)),
|
||||
};
|
||||
|
||||
|
||||
@@ -165,14 +165,16 @@ fn handle_buffer<R: BufRead>(mut input: R, options: &NumfmtOptions) -> UResult<b
|
||||
Ok(saw_invalid)
|
||||
}
|
||||
|
||||
fn parse_unit(s: &str) -> Result<Unit> {
|
||||
fn parse_unit(s: &str, opt: &str) -> Result<Unit> {
|
||||
match s {
|
||||
"auto" => Ok(Unit::Auto),
|
||||
"auto" if opt != TO => Ok(Unit::Auto),
|
||||
"si" => Ok(Unit::Si),
|
||||
"iec" => Ok(Unit::Iec(false)),
|
||||
"iec-i" => Ok(Unit::Iec(true)),
|
||||
"none" => Ok(Unit::None),
|
||||
_ => Err(translate!("numfmt-error-unsupported-unit")),
|
||||
value => Err(
|
||||
translate!("numfmt-error-invalid-unit-argument", "arg" => value, "opt" => format!("--{opt}")),
|
||||
),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -237,8 +239,8 @@ fn parse_delimiter(arg: &OsString) -> Result<Vec<u8>> {
|
||||
}
|
||||
|
||||
fn parse_options(args: &ArgMatches) -> Result<NumfmtOptions> {
|
||||
let from = parse_unit(args.get_one::<String>(FROM).unwrap())?;
|
||||
let to = parse_unit(args.get_one::<String>(TO).unwrap())?;
|
||||
let from = parse_unit(args.get_one::<String>(FROM).unwrap(), FROM)?;
|
||||
let to = parse_unit(args.get_one::<String>(TO).unwrap(), TO)?;
|
||||
let from_unit = parse_unit_size(args.get_one::<String>(FROM_UNIT).unwrap())?;
|
||||
let to_unit = parse_unit_size(args.get_one::<String>(TO_UNIT).unwrap())?;
|
||||
|
||||
|
||||
@@ -1411,12 +1411,8 @@ fn test_scientific_notation_rejected_by_gnu_issue_11655() {
|
||||
.stderr_contains("invalid suffix in input");
|
||||
}
|
||||
|
||||
// https://github.com/uutils/coreutils/issues/11662
|
||||
// `--to=auto` is accepted at parse time by uutils then rejected at runtime
|
||||
// with exit code 2; GNU rejects it in option parsing with exit code 1.
|
||||
#[test]
|
||||
#[ignore = "GNU compat: see uutils/coreutils#11662"]
|
||||
fn test_to_auto_rejected_at_parse_time_issue_11662() {
|
||||
fn test_to_auto_rejected_at_parse_time() {
|
||||
new_ucmd!()
|
||||
.args(&["--to=auto", "100"])
|
||||
.fails_with_code(1)
|
||||
|
||||
Reference in New Issue
Block a user