Repository navigation
Closed
Labels
enhancementNew feature or requestNew feature or requestgood first issueGood for newcomersGood for newcomers
Description
Problem
Numeric comparison covers the open-ended cases — assert_greater_than, assert_greater_or_equal_than, assert_less_than, assert_less_or_equal_than, assert_within_delta — but not the bounded one. Asserting "the duration was between 100 and 500 ms" or "the exit code is in the 4xx range" takes two assertions, which reports two results and two failure messages for one logical check.
Dates already have the bounded form: assert_date_within_range (src/assert/dates.sh). Numbers do not.
Proposal
assert_between <min> <max> <actual> [label]
assert_not_between <min> <max> <actual> [label]- Inclusive bounds, matching
assert_date_within_range— check that assertion first and mirror its semantics and argument order rather than choosing independently. - Supports integers and decimals, reusing the fixed-point path added for
assert_within_deltain perf(assert): compare assert_within_delta in fixed point, not via bc #979 (with thebc/awkfallback) instead of forkingbcper call. - Reports once, not twice — use
bashunit::assert_once(src/assert/once.sh) if implemented in terms of other assertions, so the count matches one assertion (Custom asserts: a composed assertion should count and report once #917).
Acceptance criteria
-
assert_between 1 10 5passes;assert_between 1 10 11fails - Bounds are inclusive:
assert_between 1 10 1andassert_between 1 10 10both pass - Decimals work:
assert_between 0.1 0.3 0.2 - Negative numbers work
-
min > maxis a usage error, not a silently always-failing assertion - Non-numeric input is a usage error (feat(assert): a missing argument reports a failed assertion, not a usage error #983 / docs(doubles): the spy assertion family disagrees with itself on argument order #984 precedent), not a comparison against empty
- The failure message shows all three values and which bound was violated
- Counts as exactly one assertion (Custom asserts: a composed assertion should count and report once #917)
-
assert_not_betweenis the exact negation and is tested independently - No
bcfork on the common integer path (perf(assert): compare assert_within_delta in fixed point, not via bc #979 precedent) — the fork-budget acceptance tests must still pass
Repo checklist (agent)
- TDD: RED → GREEN → REFACTOR. Use
/add-assertionif helpful. - Bash 3.0+ only: no
printf -v, no+=, nodeclare -A, no[[ ]], no${var,,}, no&>>. - Assertions are bare-named (
assert_x), helpers arebashunit::-namespaced. Start every assertion withbashunit::assert::should_skip && return 0and report throughbashunit::assertion_failed/bashunit::assertion_passed, matching its neighbours in the same file. - A missing required argument must go through
bashunit::assert::usage_error, not compare against an empty string (feat(assert): a missing argument reports a failed assertion, not a usage error #983). - Tests: mirror the src layout —
tests/unit/assert/<file>_test.sh. There is noassert_fails; test failure output by comparing againstprint_failed_test, as the existing tests do. - Docs: add the entry to
docs/assertions.md, then regenerate thebashunit docacceptance snapshot (editing that file breaks it). - Update the assertion count in
README.md("It ships 73 assertions…" — currently already stale at 74) and add aCHANGELOG.mdline under## Unreleased. - Gates:
make sa,make lint,./bashunit tests/,./bashunit --parallel tests/. Never runshfmt -w. - One issue = one PR.
Metadata
Metadata
Assignees
Labels
enhancementNew feature or requestNew feature or requestgood first issueGood for newcomersGood for newcomers
Type
Projects
- StatusShow more project fieldsDone
Activity