Skip to content

feat(assert): a one-call assertion helper and self-labelled failures - #919

Merged
Chemaclass merged 1 commit into
mainfrom
feat/915-custom-asserts-one-call-helper
Jul 29, 2026
Merged

feat(assert): a one-call assertion helper and self-labelled failures#919
Chemaclass merged 1 commit into
mainfrom
feat/915-custom-asserts-one-call-helper

Conversation

@Chemaclass

Copy link
Copy Markdown
Member

🤔 Background

Related #915

Writing a custom assertion is a three-part contract, and both ways of getting it wrong are silent: a missing return after a failure bumps the passed and failed counters for one assertion, while a missing bashunit::assertion_passed leaves the test with zero assertions, reported as risky.

💡 Changes

  • Add bashunit::assert_that <expected> <actual> <cmd> [args...]: runs the command and marks the assertion passed or failed in one call, so the counters cannot drift apart. No eval.
  • bashunit::assertion_failed now takes an optional 4th argument labelling the failure block, letting a custom assertion name itself instead of showing the test name.
  • Docs: the new form, the --boot / BASHUNIT_BOOTSTRAP way to load a shared assertions file once per run, and a correction to the bashunit::assertion_failed signature in globals.md (the 3rd argument is the failure condition message, never a label).
  • Entirely additive — the existing three-part form keeps working.

…ures

Add `bashunit::assert_that <expected> <actual> <cmd> [args...]`, which runs
the command and marks the assertion passed or failed in a single call. The
three-part contract it replaces had two silent failure modes: a missing
`return` after `bashunit::assertion_failed` bumped both counters for one
assertion, and a missing `bashunit::assertion_passed` left the test with zero
assertions, reported as risky.

Also accept an optional 4th argument on `bashunit::assertion_failed` and
forward it into `bashunit::assert::fail_with`'s existing label slot, so a
custom assertion can name itself in its own failure block instead of showing
the test name.

Both changes are additive; the existing form keeps working.

Docs: document the new form, correct the `bashunit::assertion_failed`
signature in globals.md (the 3rd argument is the failure condition message,
not a label), and point at `--boot` / `BASHUNIT_BOOTSTRAP` for loading a
shared custom-assert file once per run instead of per test file.

Closes #915
@Chemaclass Chemaclass added the enhancement New feature or request label Jul 29, 2026
@Chemaclass Chemaclass self-assigned this Jul 29, 2026
@Chemaclass
Chemaclass merged commit f4997ea into main Jul 29, 2026
37 checks passed
@Chemaclass
Chemaclass deleted the feat/915-custom-asserts-one-call-helper branch July 29, 2026 04:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant