test: compare integers with arbitrary precision#12882
Open
mistaste wants to merge 1 commit into
Open
Conversation
Contributor
|
|
|
GNU testsuite comparison: |
GNU `test` compares integers of any magnitude, but the integer relational
operators (`-eq`, `-ne`, `-lt`, `-le`, `-gt`, `-ge`) parsed their operands
into `i128` and reported `invalid integer` for anything larger:
$ test 1 -eq 16267277278126277227728782172782882627278282882172762677623672762783782
test: invalid integer '16267277...' # GNU: no error, exits 1
Parse the operands as `num_bigint::BigInt` instead (already used by `expr`),
so comparisons work for arbitrarily large values while keeping the existing
trimming and sign handling. Drop the now-passing `#[ignore]` on
`test_values_greater_than_i64_allowed` and add coverage for huge operands.
Fixes uutils#12874
a900637 to
ebae4d6
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #12874.
GNU
testcompares integers of any magnitude, but uutils parsed the operands ofthe integer relational operators into
i128and rejected anything larger:Change
-eq/-ne/-lt/-le/-gt/-geasnum_bigint::BigIntinstead ofi128.num-bigintis already a workspacedependency (used by
expr), and the existing trimming / sign handling ispreserved — only the artificial 128-bit range limit is removed.
#[ignore]dtest_values_greater_than_i64_allowednow passes,so the attribute is dropped.
test_arbitrary_precision_integers(CLI) andtest_integer_op_arbitrary_precision(unit) covering values beyond 128 bits,including negatives.
Checks
cargo test -p uu_test --liband thetest_testintegration tests passcargo fmtclean,cargo clippy -p uu_test --all-targetsclean