feat(assert): a one-call assertion helper and self-labelled failures - #919
Merged
Merged
Conversation
…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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
🤔 Background
Related #915
Writing a custom assertion is a three-part contract, and both ways of getting it wrong are silent: a missing
returnafter a failure bumps the passed and failed counters for one assertion, while a missingbashunit::assertion_passedleaves the test with zero assertions, reported as risky.💡 Changes
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. Noeval.bashunit::assertion_failednow takes an optional 4th argument labelling the failure block, letting a custom assertion name itself instead of showing the test name.--boot/BASHUNIT_BOOTSTRAPway to load a shared assertions file once per run, and a correction to thebashunit::assertion_failedsignature in globals.md (the 3rd argument is the failure condition message, never a label).