diff --git a/src/uu/numfmt/src/format.rs b/src/uu/numfmt/src/format.rs index 0ad7224d216..6f0a6cbf389 100644 --- a/src/uu/numfmt/src/format.rs +++ b/src/uu/numfmt/src/format.rs @@ -98,7 +98,6 @@ fn parse_suffix(s: &str) -> Result<(f64, Option)> { fn remove_suffix(i: f64, s: Option, u: &Unit) -> Result { match (s, u) { - (None, _) => Ok(i), (Some((raw_suffix, false)), &Unit::Auto) | (Some((raw_suffix, false)), &Unit::Si) => { match raw_suffix { RawSuffix::K => Ok(i * 1e3), @@ -123,6 +122,15 @@ fn remove_suffix(i: f64, s: Option, u: &Unit) -> Result { RawSuffix::Z => Ok(i * IEC_BASES[7]), RawSuffix::Y => Ok(i * IEC_BASES[8]), }, + (None, &Unit::Iec(true)) => Err(format!( + "missing 'i' suffix in input: '{}' (e.g Ki/Mi/Gi)", + i + )), + (Some((raw_suffix, false)), &Unit::Iec(true)) => Err(format!( + "missing 'i' suffix in input: '{}{:?}' (e.g Ki/Mi/Gi)", + i, raw_suffix + )), + (None, _) => Ok(i), (_, _) => Err("This suffix is unsupported for specified unit".to_owned()), } } diff --git a/tests/by-util/test_numfmt.rs b/tests/by-util/test_numfmt.rs index 257f6f7ee73..dce2b094192 100644 --- a/tests/by-util/test_numfmt.rs +++ b/tests/by-util/test_numfmt.rs @@ -30,12 +30,19 @@ fn test_from_iec_i() { } #[test] -#[ignore] // FIXME: GNU from iec-i requires suffix fn test_from_iec_i_requires_suffix() { - new_ucmd!() - .args(&["--from=iec-i", "1024"]) - .fails() - .stderr_is("numfmt: missing 'i' suffix in input: '1024' (e.g Ki/Mi/Gi)"); + let numbers = vec!["1024", "10M"]; + + for number in numbers { + new_ucmd!() + .args(&["--from=iec-i", number]) + .fails() + .code_is(2) + .stderr_is(format!( + "numfmt: missing 'i' suffix in input: '{}' (e.g Ki/Mi/Gi)", + number + )); + } } #[test]