feat(assert): add numeric range assertions - #1037
Conversation
assert_between and assert_not_between accept a leading + on any operand, but operands wider than the fork-free fixed-point path fall through to bc, which cannot parse one: it answers with a parse error on stderr and an empty result, read here as "greater than". assert_within_delta already stripped the sign for the same reason; is_le now does it for every caller. Also pins the _is_numeric hardening this branch introduced: 1.2.3 and 5-3 now report as non-numeric instead of leaking a bc parse error or being evaluated as an expression.
Chemaclass
left a comment
There was a problem hiding this comment.
Approved.
Solid feature. Inclusive bounds, an exact negation, usage errors for reversed and non-numeric input, and a failure message that names which bound broke. Docs, both completion files, the doc snapshot, the arity provider and the CHANGELOG are all updated.
Verified locally: full suite, --parallel, make sa, make lint, and no new shfmt drift against main.
I pushed one fix on top (fb697ec).
assert_between "+1" "+9999999999999999999999" "+5" leaked a raw bc parse error and then reported a bogus expects min <= max usage error. Operands wider than the fork-free fixed-point path fall through to bc, and bc cannot parse a leading +: it returns an empty result, which is_le reads as "greater than". assert_within_delta already strips the sign for exactly this reason, so bashunit::math::is_le now does it for every caller. Regression tests in math_test.sh and numeric_test.sh.
I also pinned the _is_numeric hardening this branch introduces. That is a user-visible fix on its own and it was not recorded: on main, assert_within_delta "1.2.3" "1" "0.5" leaks Parse error: bad expression into the report, and 5-3 is silently evaluated as 2. Two regression tests plus a Fixed entry in the CHANGELOG.
# Conflicts: # CHANGELOG.md
Background
Related #1026
Numeric assertions covered open-ended comparisons but not a single inclusive range check. I added bounded assertions so one logical range check reports one result and one failure message.
Changes
assert_between <min> <max> <actual>with inclusive bounds andassert_not_betweenas its exact negation.bc/awkfallback for unsupported precision.Verification
make test— 1,789 passed; 32 skipped; 4 incomplete; 2 snapshots; no failures./bashunit --parallel tests/— 1,751 passed; 35 skipped; 4 incomplete; 2 snapshots; no failuresmake samake lintgit diff --checkChecklist
CHANGELOG.mdto reflect the new feature or fixFixes #1026