From a33514b33423c94c9fd83f6df43915d6fac44b23 Mon Sep 17 00:00:00 2001 From: Chemaclass Date: Wed, 29 Jul 2026 07:26:58 +0200 Subject: [PATCH] feat(doc): list a project's own assertions in bashunit doc `bashunit doc` listed only the built-in assertions, so discoverability stopped exactly where a team's own assertions live. Add `--custom` to list them, and make plain `bashunit doc` append a "Custom assertions" section when a bootstrap defines any. `bashunit doc` now accepts `-e | --env | --boot ` and honours `BASHUNIT_BOOTSTRAP`, since a bootstrap is the only point where user assertions are guaranteed loaded. The built-in set is not hardcoded: cmd_doc snapshots `compgen -A function assert_` before sourcing the bootstrap, and whatever appears afterwards is the project's own, so the two lists can never drift apart. Each entry renders the comment block immediately above the definition, located via `declare -F` with extdebug enabled inside the capture subshell only -- toggling it in the caller's shell clobbers caller state (#808). The file is read once into an array rather than with a `sed -n Np` per line, which is the quadratic pattern removed in #807. The custom list is insertion-sorted in pure bash rather than piped through `LC_ALL=C sort`: that prefix is banned in src/ because bash 5.3.9 on macOS segfaults on it inside a command substitution (#912), and the list is tiny enough that the fork was not worth it either. The completions anti-drift contract only knew about cmd_test's flags, so a doc-only flag had nowhere correct to live. It now derives cmd_doc's flags too: the zsh expectation is the union (that script advertises everything from one _arguments block) and the bash script carries them in their own variable with its own parity test. Closes #918 --- CHANGELOG.md | 1 + completions/_bashunit | 1 + completions/bashunit.bash | 12 ++ docs/command-line.md | 16 +- docs/custom-asserts.md | 36 +++++ src/console_header.sh | 7 +- src/doc.sh | 140 ++++++++++++++++++ src/main.sh | 61 +++++++- tests/acceptance/bashunit_doc_custom_test.sh | 82 ++++++++++ .../acceptance/fixtures/custom_assert_docs.sh | 23 +++ tests/unit/completions_test.sh | 29 +++- 11 files changed, 398 insertions(+), 10 deletions(-) create mode 100644 tests/acceptance/bashunit_doc_custom_test.sh create mode 100644 tests/acceptance/fixtures/custom_assert_docs.sh diff --git a/CHANGELOG.md b/CHANGELOG.md index 438cb8cf..4d66b960 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ ## Unreleased ### Added +- `bashunit doc --custom` lists the assertions your own project defines, rendering the comment block above each one; plain `bashunit doc` appends them as a "Custom assertions" section. Needs `--boot` / `BASHUNIT_BOOTSTRAP`, which `bashunit doc` now accepts (#918) - `bashunit::assert_once