Skip to content

test: compare integers with arbitrary precision#12882

Open
mistaste wants to merge 1 commit into
uutils:mainfrom
mistaste:fix-test-large-integers
Open

test: compare integers with arbitrary precision#12882
mistaste wants to merge 1 commit into
uutils:mainfrom
mistaste:fix-test-large-integers

Conversation

@mistaste

Copy link
Copy Markdown
Contributor

Summary

Fixes #12874.

GNU test compares integers of any magnitude, but uutils parsed the operands of
the integer relational operators into i128 and rejected anything larger:

$ test 1 -eq 16267277278126277227728782172782882627278282882172762677623672762783782
test: invalid integer '16267277278126277227728782172782882627278282882172762677623672762783782'
$ # GNU prints nothing and exits 1

Change

  • Parse the operands of -eq/-ne/-lt/-le/-gt/-ge as
    num_bigint::BigInt instead of i128. num-bigint is already a workspace
    dependency (used by expr), and the existing trimming / sign handling is
    preserved — only the artificial 128-bit range limit is removed.
  • The previously #[ignore]d test_values_greater_than_i64_allowed now passes,
    so the attribute is dropped.
  • Add test_arbitrary_precision_integers (CLI) and
    test_integer_op_arbitrary_precision (unit) covering values beyond 128 bits,
    including negatives.
$ test 16267277278126277227728782172782882627278282882172762677623672762783782 \
       -eq 16267277278126277227728782172782882627278282882172762677623672762783782
$ echo $?
0

Checks

  • cargo test -p uu_test --lib and the test_test integration tests pass
  • cargo fmt clean, cargo clippy -p uu_test --all-targets clean

@oech3

oech3 commented Jun 15, 2026

Copy link
Copy Markdown
Contributor

I think we should parse letters directly.

@github-actions

github-actions Bot commented Jun 15, 2026

Copy link
Copy Markdown

GNU testsuite comparison:

Skip an intermittent issue tests/date/date-locale-hour (fails in this run but passes in the 'main' branch)
Skipping an intermittent issue tests/cut/bounded-memory (passes in this run but fails in the 'main' branch)
Skipping an intermittent issue tests/rm/isatty (passes in this run but fails in the 'main' branch)
Note: The gnu test tests/tail/tail-n0f is now being skipped but was previously passing.

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
@mistaste mistaste force-pushed the fix-test-large-integers branch from a900637 to ebae4d6 Compare June 15, 2026 12:15
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.

gnucompability(test): large numbers rejected while gnu accepted

2 participants