Skip to content

Commit 66d4fae

Browse files
authored
numfmt: fix GNU compat issue #11653 & correct test cases (#11695)
1 parent dba5491 commit 66d4fae

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

src/uu/numfmt/src/numfmt.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -413,7 +413,6 @@ pub fn uu_app() -> Command {
413413
.about(translate!("numfmt-about"))
414414
.after_help(translate!("numfmt-after-help"))
415415
.override_usage(format_usage(&translate!("numfmt-usage")))
416-
.allow_negative_numbers(true)
417416
.infer_long_args(true)
418417
.arg(
419418
Arg::new(DEBUG)

tests/by-util/test_numfmt.rs

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,12 @@ fn test_invalid_arg() {
1111
new_ucmd!().arg("--definitely-invalid").fails_with_code(1);
1212
}
1313

14+
// This test failed when fixing #11653.
15+
// Add a `--` separator to ensure floats are not rounded(it match the gnu pattern).
1416
#[test]
1517
fn test_should_not_round_floats() {
1618
new_ucmd!()
17-
.args(&["0.99", "1.01", "1.1", "1.22", ".1", "-0.1"])
19+
.args(&["--", "0.99", "1.01", "1.1", "1.22", ".1", "-0.1"])
1820
.succeeds()
1921
.stdout_is("0.99\n1.01\n1.1\n1.22\n0.1\n-0.1\n");
2022
}
@@ -1370,12 +1372,22 @@ fn test_null_byte_input_multiline() {
13701372
// GNU rejects `-9923868` as an invalid short option (leading `-9`) and
13711373
// requires `--` separator; uutils accepts it as a negative positional number.
13721374
#[test]
1373-
#[ignore = "GNU compat: see uutils/coreutils#11653"]
13741375
fn test_negative_number_without_double_dash_gnu_compat_issue_11653() {
13751376
new_ucmd!()
13761377
.args(&["--to=iec", "-9923868"])
13771378
.fails_with_code(1)
1378-
.stderr_contains("invalid option");
1379+
.stderr_contains("unexpected argument");
1380+
}
1381+
1382+
// https://github.com/uutils/coreutils/issues/11653
1383+
// GNU rejects `-9923868` as an invalid short option (leading `-9`) and
1384+
// requires `--` separator; uutils accepts it as a negative positional number.
1385+
#[test]
1386+
fn test_negative_number_with_double_dash_gnu_compat_issue_11653() {
1387+
new_ucmd!()
1388+
.args(&["--to=iec", "--", "-9923868"])
1389+
.succeeds()
1390+
.stdout_is("-9.5M\n");
13791391
}
13801392

13811393
// https://github.com/uutils/coreutils/issues/11654

0 commit comments

Comments
 (0)