Skip to content

feat(assert): assert_between / assert_not_between for numeric ranges #1026

Description

@Chemaclass

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]

Acceptance criteria

Repo checklist (agent)

  • TDD: RED → GREEN → REFACTOR. Use /add-assertion if helpful.
  • Bash 3.0+ only: no printf -v, no +=, no declare -A, no [[ ]], no ${var,,}, no &>>.
  • Assertions are bare-named (assert_x), helpers are bashunit::-namespaced. Start every assertion with bashunit::assert::should_skip && return 0 and report through bashunit::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 no assert_fails; test failure output by comparing against print_failed_test, as the existing tests do.
  • Docs: add the entry to docs/assertions.md, then regenerate the bashunit doc acceptance snapshot (editing that file breaks it).
  • Update the assertion count in README.md ("It ships 73 assertions…" — currently already stale at 74) and add a CHANGELOG.md line under ## Unreleased.
  • Gates: make sa, make lint, ./bashunit tests/, ./bashunit --parallel tests/. Never run shfmt -w.
  • One issue = one PR.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    Status
    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions