1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-07-27 19:17:43 +00:00
Commit graph

72 commits

Author SHA1 Message Date
Dorian Peron
6e23d4e979 tests: patch tests to simplify imports 2025-07-01 03:36:46 +02:00
Luv-Ray
fb2399f56b
fix clippy (#8275)
* fix clippy

* update

* update
2025-06-27 09:15:24 +02:00
Nicolas Boichat
560d1eb1b7 seq: Add a print_seq fast path function for integer and positive increments
A lot of custom logic, we basically do arithmetic on character
arrays, but this comes at with huge performance gains.

Unlike coreutils `seq`, we do this for all positive increments
(because why not), and we do not fall back to slow path if
the last parameter is in scientific notation.

Also, add some tests for empty separator, as that may catch
some corner cases.
2025-04-21 11:25:54 +02:00
Nicolas Boichat
e0a6482759 seq: Trim whitespaces, then try to remove +
Otherwise, `seq` crashes with ` 0xee.` as input.

Also update one of the tests to catch that.
2025-04-04 17:09:33 +02:00
Nicolas Boichat
ae3756b434 seq: Do not allow -w and -f to be specified at the same time
Fixes #7466.
2025-04-04 10:17:17 +02:00
Nicolas Boichat
84e5ee4b86 seq: Accept underflow in parameters
Also, add a test to check that a very, very, small number is
treated as 0. That's probably undefined behaviour, but it does
make some sense.
2025-04-03 17:26:38 +02:00
Nicolas Boichat
d58f1cc0f1 test_seq: Modify undefined behaviour tests
GNU `seq` doesn't support such large positive exponents anyway,
and we are limited by i64 range, so increase the exponent value
to make sure we fully overflow that range.

Also, add a test to check that a very, very, small number is
treated as 0 (that's also undefined behaviour, but it does
make sense in a way).
2025-04-03 17:26:38 +02:00
Sylvestre Ledru
a0179ea239 uutests: adjust the tests to use them 2025-03-28 21:40:31 +01:00
Nicolas Boichat
596ea0a694 test_seq: Add a few more tests for corner cases
Some of these tests are not completely defined behavior, but
in many cases they make sense (or at least one can find some
consistent logic to it).

However, there are 2 edge cases that are more dubious IMHO.
One of them has been reported on list a while back, and I
just reported another.
2025-03-22 22:02:11 +01:00
Nicolas Boichat
59cd6e5e41 tests: Move seq/yes run function to Ucommand::run_stdout_starts_with
Tests for both `seq` and `yes` run a command that never terminates,
and check the beggining of their output in stdout, move the copied
parts of the wrapper function to common/util.

We still need to use slightly different logic to parse exit value
as `seq` returns success if stdout gets closed, while `yes` fails.
2025-03-22 22:02:11 +01:00
Nicolas Boichat
c0a1179e7c seq: Enable test_auto_precision and test_undefined
Those tests appear to have been fixed, enable them.
2025-03-14 12:05:16 +01:00
Nicolas Boichat
1782de8999 seq: Add tests for default float formats
Add tests for some of the default float formats (%f, %g, %E), mostly
to check that the default precision is correctly set to 6 digits.
2025-03-14 12:05:16 +01:00
Daniel Hofstetter
df4dfea852 tests: replace run() with succeeds() or fails() 2025-03-09 16:53:56 +01:00
Sylvestre Ledru
18cb7dcf9e Use the new function fails_with_code
Done with
```
$ perl -0777 -i -pe 's/([ \t]+)\.fails\(\)[ \t]*\n[ \t]+\.no_stdout\(\)[ \t]*\n[ \t]+\.code_is\(([0-9]+)\);/\1.fails_with_code(\2)\n\1.no_stdout();/gs' *rs
$ sed -i -e "s|.fails()(.*).code_is(|.fails_with_code(|g" *rs
$ perl -0777 -i -pe 's/([ \t]+)\.fails\(\)[ \t]*\n[ \t]+\.code_is\(([0-9]+)\);/\1.fails_with_code(\2);/gs' *rs
$ perl -0777 -i -pe 's/([ \t]+)\.fails\(\)(.*?)[ \t]+\.code_is\(([0-9]+)\);/\1.fails_with_code(\3)\2;/gs' *rs
...
```
2025-03-01 17:26:20 +01:00
Alexander Shirokov
b3c0633b95
seq:add bounds for exponents
Add bounds for exponents to avoid overflow issues for inputs like 'seq
1e-9223372036854775808'
2025-01-15 22:35:24 +01:00
Alexander
05ada0d204
seq:add floating point support (#6959)
* seq:enable parsing of hexadecimal floats

Turn on the float parser. Now it's possible to use hexadecimal floats as
parameters. For example,

    cargo run -- 0x1p-1 3
    0.5
    1.5
    2.5

Issue #6935

---------

Co-authored-by: Daniel Hofstetter <daniel.hofstetter@42dh.com>
Co-authored-by: Sylvestre Ledru <sylvestre@debian.org>
2025-01-15 11:53:18 +01:00
Jeffrey Finkelstein
cccab35337 seq: improve error handling for invalid -f values
Improve the error message produced by `seq` when given invalid format
specifiers for the `-f` option. Before this commit:

    $ seq -f "%" 1
    seq: %: invalid conversion specification
    $ seq -f "%g%" 1
    seq: %: invalid conversion specification

After this commit:

    $ seq -f "%" 1
    seq: format '%' ends in %
    $ seq -f "%g%" 1
    seq: format '%g%' has too many % directives

This matches the behavior of GNU `seq`.
2024-12-30 12:30:26 -05:00
Daniel Hofstetter
ee0426e3f3 seq: use allow_hyphen_values instead of
allow_negative_numbers because clap removed support for "exotic" negative
numbers like -.1
2024-12-15 16:14:01 +01:00
Daniel Hofstetter
1f6f7fbe8c tests/seq: fix ticket references of ignored tests 2024-12-07 17:04:05 +01:00
Daniel Hofstetter
e654645974 tests/seq: use stdout_only() to remove no_stderr() 2024-12-07 16:59:13 +01:00
aimerlief
367cc19d45
fix(seq): handle 0e... scientific notation without padding (#6934)
* fix(seq): handle 0e... scientific notation without padding

- Updated the parse_exponent_no_decimal function to treat 0e... as zero.
- Added test cases to verify correct behavior for 0e15 and -w 0e15.

Fix: #6926

* fix(seq): improved parse for accurate BigDecimal handling

* apply missing cargo fmt formatting adjustments
2024-12-07 16:42:34 +01:00
Arthur Pin
88e10478bc tests/seq: test scientific notation with uppercase 'E' 2024-12-06 18:00:39 -03:00
steinwand6
c986fb7d2e
seq: add overflow checks when parsing exponents (#6858)
* seq: remove ignore flag from test_invalid_float_point_fail_properly(#6235)

* seq: prevent overflow in parse_exponent_no_decimal

* seq: add tests for invalid floating point arguments

* seq: add overflow checks when parsing decimal with exponent

* seq: add overflow checks
2024-11-20 16:11:04 +01:00
Sylvestre Ledru
d63bc4a4e1
seq: add the unit test even if they are failing for now (#6236)
* seq: add the unit test even if they are failing for now

* improve test

Co-authored-by: Daniel Hofstetter <daniel.hofstetter@42dh.com>

---------

Co-authored-by: Daniel Hofstetter <daniel.hofstetter@42dh.com>
2024-04-21 14:48:03 +02:00
Sylvestre Ledru
b309d64e78
Merge branch 'main' into issue-5766 2024-01-06 22:55:54 +01:00
Sylvestre Ledru
247f2e55bd
seq: adjust some error messages. GNU's are better (#5798)
* seq: adjust some error messages. GNU's are better
tested by tests/seq/seq.pl

* uucore: remove todo

---------

Co-authored-by: Daniel Hofstetter <daniel.hofstetter@42dh.com>
2024-01-06 16:54:29 +01:00
Samuel Tardieu
32f0256d7d uucore/num_format: properly display 10ᵖ where p is the precision
`seq --format %.2g 10 10` would display `1` because the precision would
not allow room for the decimal point, and the `0` in `10` would be
trimmed as an insignificant trailing `0`.

This has been fixed by only trimming trailing `0` in the presence of a
decimal point.
2024-01-05 15:40:20 +01:00
Daniel Hofstetter
bc7877b58c
Merge pull request #5124 from shinhs0506/seq-parse
seq: parse "infinity" and "-infinity"
2023-09-30 06:59:32 +02:00
Sylvestre Ledru
bfca6bf70f Add license headers on all files 2023-08-21 10:49:27 +02:00
John Shin
2bb56d44a4 seq: add tests for infinity and -infinity args 2023-08-05 19:40:45 -07:00
Daniel Hofstetter
f8a955266e
Merge pull request #4750 from NikolaiSch/seq-panic-fix
fix: seq panic on no arguments #4749
2023-07-09 14:19:07 +02:00
Daniel Hofstetter
98264e9cdf seq: add test for call without args 2023-07-05 15:51:23 +02:00
Daniel Hofstetter
c05dbfa3b4 seq: rename "--widths" to "--equal-width"
for compatibility with GNU seq
2023-06-26 16:21:59 +02:00
Daniel Hofstetter
6988eb7ec6 tests: expand wildcard imports 2023-03-20 15:32:35 +01:00
Daniel Hofstetter
3eeb5dda30 tests: adapt to clap's modified error messages 2023-03-09 10:06:20 +01:00
Roy Ivy III
d78e1e7399 tests: revise/standardize usage error testing (for dd, install, mktemp, rm, seq, and touch) 2023-01-13 22:14:48 -06:00
Joining7943
982fb682e9 tests: Use UChild in tests. Rename run_no_wait_child to run_no_wait and return UChild
tests/tail:
* test_stdin_redirect_file:. Test fails now when assert_alive()!
The follow test `tail -f < file` where file's content is `foo` fails with:
    Assertion failed. Expected 'tail' to be running but exited with status=exit status: 0

I also tried on the command line and can confirm that tail isn't runnning when following by
descriptor. The test is deactivated until the implementation is fixed.

* test_follow_stdin_descriptor
* test_follow_stdin_explicit_indefinitely.
* test_follow_single
* test_follow_non_utf8_bytes
* test_follow_multiple
* test_follow_name_multiple
* test_follow_invalid_pid
* test_single_big_args
* test_retry3
* test_retry4
* test_retry5
* test_retry7
* test_retry8
* test_retry9
* test_follow_descriptor_vs_rename1
* test_follow_descriptor_vs_rename2
* test_follow_name_retry_headers
* test_follow_name_remove
* test_follow_name_truncate1
* test_follow_name_truncate2
* test_follow_name_truncate3
* test_follow_name_truncate4
* test_follow_truncate_fast
* test_follow_name_move_create1
* test_follow_name_move_create2
* test_follow_name_move1
* test_follow_name_move2
* test_follow_name_move_retry1
* test_follow_name_move_retry2
* test_follow_inotify_only_regular
* test_fifo
* test_illegal_seek

tests/cat:
* test_dev_full
* test_dev_full_show_all
* test_dev_random
* test_fifo_symlink

tests/dd:
* test_random_73k_test_lazy_fullblock
* test_sync_delayed_reader

tests/factor:
* test_parallel

tests/rm:
* test_rm_force_prompts_order
* test_rm_descend_directory
* test_rm_prompts

tests/seq:
* the helper run method

tests/sort:
* test_sigpipe_panic

tests/tee:
* the helper run_tee method

tests/tty:
* test_tty module

tests/yes:
* the helper run method
2022-12-02 08:06:45 +01:00
Terts Diepraam
4cfc90c077 seq: update to clap 4 2022-10-13 17:50:40 +02:00
Terts Diepraam
9177cb7b24 all: add tests for usage error exit code 2022-09-10 20:59:42 +02:00
Andreas Molzer
a2e9329918 seq: Allow option to receive immediate arguments
WIP: this needs to be adjusted
2022-02-06 09:45:38 -06:00
Andreas Molzer
66733ca994 seq: Add difficult cases to test suite 2022-02-06 09:45:37 -06:00
Jeffrey Finkelstein
9dda23d8c6 seq: correct error message for zero increment
Change a word in the error message displayed when an increment value
of 0 is provided to `seq`. This commit changes the message from "Zero
increment argument" to "Zero increment value" to match the GNU `seq`
error message.
2022-01-27 21:17:27 -05:00
Jeffrey Finkelstein
4fbe2b2b5e seq: implement -f FORMAT option
Add support for the `-f FORMAT` option to `seq`. This option instructs
the program to render each value in the generated sequence using a
given `printf`-style floating point format. For example,

    $ seq -f %.2f 0.0 0.1 0.5
    0.00
    0.10
    0.20
    0.30
    0.40
    0.50

Fixes issue #2616.
2022-01-25 20:48:26 -05:00
jfinkels
8a55205521
seq: return UResult from uumain() function (#2784) 2021-12-29 15:20:17 +01:00
Jeffrey Finkelstein
294bde8e08 seq: correct width for certain negative decimals
Fix a bug in which a negative decimal input would not be displayed with
the correct width in the output. Before this commit, the output was
incorrectly

    $ seq -w -.1 .1 .11
    -0.1
    0.0
    0.1

After this commit, the output is correctly

    $ seq -w -.1 .1 .11
    -0.1
    00.0
    00.1

The code was failing to take into account that the input decimal "-.1"
needs to be displayed with a leading zero, like "-0.1".
2021-12-23 20:37:29 -05:00
Sylvestre Ledru
177374aa5a
Merge pull request #2740 from jfinkels/seq-inf-width-spaces
seq: correct fixed-width spacing for inf sequences
2021-11-12 21:16:40 +01:00
Thomas Queiroz
c9624725ab
tests: use CmdResult::usage_error 2021-11-09 17:37:05 -03:00
Jeffrey Finkelstein
0b86afa858 seq: correct fixed-width spacing for inf sequences
Pad infinity and negative infinity values with spaces when using the
`-w` option to `seq`. This corrects the behavior of `seq` to match that
of the GNU version:

    $ seq -w 1.000 inf inf | head -n 4
    1.000
      inf
      inf
      inf

Previously, it incorrectly padded with 0s instead of spaces.
2021-11-08 20:12:54 -05:00
jfinkels
2e12316ae1
seq: use BigDecimal to represent floats (#2698)
* seq: use BigDecimal to represent floats

Use `BigDecimal` to represent arbitrary precision floats in order to
prevent numerical precision issues when iterating over a sequence of
numbers. This commit makes several changes at once to accomplish this
goal.

First, it creates a new struct, `PreciseNumber`, that is responsible for
storing not only the number itself but also the number of digits (both
integer and decimal) needed to display it. This information is collected
at the time of parsing the number, which lives in the new
`numberparse.rs` module.

Second, it uses the `BigDecimal` struct to store arbitrary precision
floating point numbers instead of the previous `f64` primitive
type. This protects against issues of numerical precision when
repeatedly accumulating a very small increment.

Third, since neither the `BigDecimal` nor `BigInt` types have a
representation of infinity, minus infinity, minus zero, or NaN, we add
the `ExtendedBigDecimal` and `ExtendedBigInt` enumerations which extend
the basic types with these concepts.

* fixup! seq: use BigDecimal to represent floats

* fixup! seq: use BigDecimal to represent floats

* fixup! seq: use BigDecimal to represent floats

* fixup! seq: use BigDecimal to represent floats

* fixup! seq: use BigDecimal to represent floats
2021-11-06 15:44:42 +01:00
vulppine
cddd40b4e1 seq: Updates hex parse readability, adds hex test 2021-10-05 18:41:28 -07:00