Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
- Guard root `package.json` against accidental regression of the docs-split: assert no `dependencies`/`devDependencies`/`peerDependencies`/`scripts` blocks ever return to the published manifest
- `release.sh` now treats `docs/package.json` as a first-class `RELEASE_FILES` entry, so the release flow backs it up, restores it on rollback, and stages it without inline duplication. Backup/restore preserves nested directory paths
- Extract `bashunit::runner::source_login_shell_profiles` and `bashunit::runner::print_verbose_test_summary` from the 320-line `run_test` body so the hot path reads top-down without inline `~/.profile` sourcing or printf scaffolding
- Further trim `bashunit::runner::run_test`: extract `export_test_identity` (test ID + coverage env exports) and `apply_interpolated_title` (data-provider title interpolation) so the function opens with five named one-liners instead of an inline export/branch block
- Centralize all ANSI escape emission through the existing `_BASHUNIT_COLOR_*` constants. `src/coverage.sh` and the `--watch` screen-clear in `src/main.sh` no longer hardcode escape sequences (#247)
- Speed up coverage report generation by collapsing the per-line non-executable pattern checks in `bashunit::coverage::is_executable_line` into a single combined `grep` invocation (#636)
- Speed up coverage report generation further by combining executable + hit counting into a single source-file pass (`bashunit::coverage::compute_file_coverage`) shared across text/lcov/html reporters, removing per-line `get_line_hits` scans of the coverage data file (#636)
Expand Down
42 changes: 26 additions & 16 deletions src/runner.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,29 @@ function bashunit::runner::source_login_shell_profiles() {
[ -f ~/.profile ] && source ~/.profile 2>/dev/null || true
}

function bashunit::runner::export_test_identity() {
local test_file=$1
local fn_name=$2
export BASHUNIT_CURRENT_TEST_ID="$(bashunit::helper::generate_id "$fn_name")"
if bashunit::env::is_coverage_enabled; then
export _BASHUNIT_COVERAGE_CURRENT_TEST_FILE="$test_file"
export _BASHUNIT_COVERAGE_CURRENT_TEST_FN="$fn_name"
fi
}

function bashunit::runner::apply_interpolated_title() {
local fn_name=$1
shift
local interpolated
interpolated="$(bashunit::helper::interpolate_function_name "$fn_name" "$@")"
if [ "$interpolated" != "$fn_name" ]; then
bashunit::state::set_current_test_interpolated_function_name "$interpolated"
else
bashunit::state::reset_current_test_interpolated_function_name
fi
printf '%s' "$interpolated"
}

function bashunit::runner::print_verbose_test_summary() {
local test_file=$1
local fn_name=$2
Expand Down Expand Up @@ -620,24 +643,11 @@ function bashunit::runner::run_test() {
shift

bashunit::internal_log "Running test" "$fn_name" "$*"
# Export a unique test identifier so that test doubles can
# create temporary files scoped per test run. This prevents
# race conditions when running tests in parallel.
export BASHUNIT_CURRENT_TEST_ID="$(bashunit::helper::generate_id "$fn_name")"
# Export current test file and function for coverage tracking (only when coverage enabled)
if bashunit::env::is_coverage_enabled; then
export _BASHUNIT_COVERAGE_CURRENT_TEST_FILE="$test_file"
export _BASHUNIT_COVERAGE_CURRENT_TEST_FN="$fn_name"
fi
bashunit::runner::export_test_identity "$test_file" "$fn_name"

bashunit::state::reset_test_title

local interpolated_fn_name="$(bashunit::helper::interpolate_function_name "$fn_name" "$@")"
if [ "$interpolated_fn_name" != "$fn_name" ]; then
bashunit::state::set_current_test_interpolated_function_name "$interpolated_fn_name"
else
bashunit::state::reset_current_test_interpolated_function_name
fi
local interpolated_fn_name
interpolated_fn_name=$(bashunit::runner::apply_interpolated_title "$fn_name" "$@")
local current_assertions_failed="$_BASHUNIT_ASSERTIONS_FAILED"
local current_assertions_snapshot="$_BASHUNIT_ASSERTIONS_SNAPSHOT"
local current_assertions_incomplete="$_BASHUNIT_ASSERTIONS_INCOMPLETE"
Expand Down
Loading