Skip to content

timeout: Use common parser to parse time duration #7648

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Apr 4, 2025

Conversation

drinkcat
Copy link
Contributor

@drinkcat drinkcat commented Apr 4, 2025

test_timeout: Add tests for very short timeouts

Note that unlike GNU coreutils, any value > 0 will not be treated
as 0, even if the exponent is very large.

uucore: parser: parse_time: Use ExtendedBigDecimal parser

Gives a little bit more flexibility in terms of allowed input
for durations (e.g. in timeout), e.g. hex floating point
numbers are now allowed.

Fixes another part of #7475.

uucore: parser: num_parser: Do not Underflow/Overflow when parsing 0

Values like 0e18172487393827593258 and 0e-18172487393827593258 should
just be parsed as 0, and do not need to return an error.

uucore: parser: parse_time: Handle infinity and nan

There were some missing corner cases when handling infinity and
nan:

  • inf/infinity can be capitalized
  • nan must always be rejected, even if a suffix is provided

Also, return Duration::MAX with infinite values, just for consistency
(num.fract() returns 0 for infinity so technically we were just
short of that).

Add unit tests too.

Fixes some of #7475.

@drinkcat drinkcat changed the title Parse time ebd timeout: Use common parser to parse time duration Apr 4, 2025
drinkcat added 4 commits April 4, 2025 18:12
There were some missing corner cases when handling infinity and
nan:
 - inf/infinity can be capitalized
 - nan must always be rejected, even if a suffix is provided

Also, return Duration::MAX with infinite values, just for consistency
(num.fract() returns 0 for infinity so technically we were just
short of that).

Add unit tests too.

Fixes some of uutils#7475.
Values like 0e18172487393827593258 and 0e-18172487393827593258 should
just be parsed as 0, and do not need to return an error.
Gives a little bit more flexibility in terms of allowed input
for durations (e.g. in `timeout`), e.g. hex floating point
numbers are now allowed.

Fixes another part of uutils#7475.
Note that unlike GNU coreutils, any value > 0 will not be treated
as 0, even if the exponent is very large.
@drinkcat drinkcat marked this pull request as ready for review April 4, 2025 16:30
Copy link

github-actions bot commented Apr 4, 2025

GNU testsuite comparison:

Skipping an intermittent issue tests/misc/stdbuf (passes in this run but fails in the 'main' branch)
Congrats! The gnu test tests/misc/tee is no longer failing!

@sylvestre sylvestre merged commit 88cf661 into uutils:main Apr 4, 2025
66 of 68 checks passed
@drinkcat drinkcat deleted the parse_time-ebd branch April 5, 2025 08:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants