]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
tests: numfmt: cover GNU/uutils compatibility edge cases
authorSylvestre Ledru <sylvestre@debian.org>
Sun, 5 Apr 2026 22:14:25 +0000 (00:14 +0200)
committerPádraig Brady <P@draigBrady.com>
Mon, 6 Apr 2026 14:57:51 +0000 (15:57 +0100)
* tests/numfmt/numfmt.pl: Add tests exercising corner cases around
negative-argument rejection, large integer precision, scientific
notation rejection, '--from-unit' fractional precision, zero-padded
format sign ordering, '--to-unit' prefix selection, and
'--format=%.0f' with '--to=<scale>'.
https://github.com/uutils/coreutils/pull/11668

tests/numfmt/numfmt.pl

index b899a46f540517fb56e70ad67ed0591312cba1e3..b78aef14b8adc8171881e276dab2c6569a3d7772 100755 (executable)
@@ -890,6 +890,44 @@ my @Tests =
              {OUT => "A 1000 x\nB Foo y\nC 2.8G z\n"},
              {ERR => "$prog: invalid number: 'Foo'\n"},
              {EXIT => 2}],
+
+     # A leading '-9...' must be treated as an invalid short option, not as
+     # a negative positional argument.
+     ['neg-arg-not-option', '--to=iec -9923868',
+             {ERR => "$prog: invalid option -- '9'\n" .
+                     "Try '$prog --help' for more information.\n"},
+             {EXIT => 1}],
+
+     # Large integers beyond 2^53 must be preserved exactly
+     # (no f64 round-trip).
+     ['large-int-precision', '--from=iec 9153396227555392131',
+             {OUT => "9153396227555392131"}],
+
+     # Scientific notation ('1e9') is not accepted as numeric input;
+     # it is reported as an invalid suffix.
+     ['reject-sci-notation', '1e9',
+             {ERR => "$prog: invalid suffix in input: '1e9'\n"},
+             {EXIT => 2}],
+
+     # '--from-unit' scaling must preserve fractional precision of the input
+     # rather than rounding to an integer.
+     ['from-unit-fraction', '--from=iec --from-unit=959 -- -615484.454',
+             {OUT => "-590249591.386"}],
+
+     # Zero-padded '--format' must place the sign before the padding zeros
+     # for negative numbers (matches C printf).
+     ['zero-pad-neg-sign', '--from=none --format=%018.2f -- -9869647',
+             {OUT => "-00000009869647.00"}],
+
+     # '--to-unit=N' must select the output prefix based on the scaled value
+     # (value / N), not the unscaled input.
+     ['to-unit-prefix', '--to=iec-i --to-unit=885 100000',
+             {OUT => "113"}],
+
+     # '--format=%.0f' combined with '--to=<scale>' must honor the '.0'
+     # precision specifier (no fractional digit).
+     ['fmt-zero-prec-scale', '--to=iec --format=%.0f 5183776',
+             {OUT => "5M"}],
     );
 
 # test null-terminated lines