Skip to content

Commit 6cec81b

Browse files
authored
refactor(runner): extract login profile sourcing and verbose summary (#653)
1 parent 70deb64 commit 6cec81b

2 files changed

Lines changed: 35 additions & 21 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
- Split documentation into its own npm workspace under `docs/`: VitePress dependencies and `docs:*` scripts moved out of the root `package.json` so the published npm package stays slim. CI workflows, release script and contributing docs updated for the new `cd docs && npm ci` workflow; `make docs/{install,dev,build,preview}` shortcuts added
1212
- Guard root `package.json` against accidental regression of the docs-split: assert no `dependencies`/`devDependencies`/`peerDependencies`/`scripts` blocks ever return to the published manifest
1313
- `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
14+
- 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
1415
- 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)
1516
- 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)
1617
- 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)

src/runner.sh

Lines changed: 34 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,37 @@ function bashunit::runner::restore_workdir() {
1212
cd "$BASHUNIT_WORKING_DIR" 2>/dev/null || true
1313
}
1414

15+
function bashunit::runner::source_login_shell_profiles() {
16+
# shellcheck disable=SC1091
17+
[ -f /etc/profile ] && source /etc/profile 2>/dev/null || true
18+
# shellcheck disable=SC1090
19+
[ -f ~/.bash_profile ] && source ~/.bash_profile 2>/dev/null || true
20+
# shellcheck disable=SC1090
21+
[ -f ~/.bash_login ] && source ~/.bash_login 2>/dev/null || true
22+
# shellcheck disable=SC1090
23+
[ -f ~/.profile ] && source ~/.profile 2>/dev/null || true
24+
}
25+
26+
function bashunit::runner::print_verbose_test_summary() {
27+
local test_file=$1
28+
local fn_name=$2
29+
local duration=$3
30+
local test_execution_result=$4
31+
32+
if bashunit::env::is_simple_output_enabled; then
33+
echo ""
34+
fi
35+
36+
printf '%*s\n' "$TERMINAL_WIDTH" '' | tr ' ' '='
37+
printf "%s\n" "File: $test_file"
38+
printf "%s\n" "Function: $fn_name"
39+
printf "%s\n" "Duration: $duration ms"
40+
local raw_text=${test_execution_result%%##ASSERTIONS_*}
41+
[ -n "$raw_text" ] && printf "%s" "Raw text: $raw_text"
42+
printf "%s\n" "##ASSERTIONS_${test_execution_result#*##ASSERTIONS_}"
43+
printf '%*s\n' "$TERMINAL_WIDTH" '' | tr ' ' '-'
44+
}
45+
1546
function bashunit::runner::wait_for_job_slot() {
1647
local max_jobs="${BASHUNIT_PARALLEL_JOBS:-0}"
1748
if [ "$max_jobs" -le 0 ]; then
@@ -627,16 +658,8 @@ function bashunit::runner::run_test() {
627658
trap "exit_code=\$?; bashunit::runner::cleanup_on_exit \"$test_file\" \"\$exit_code\"" EXIT
628659
bashunit::state::initialize_assertions_count
629660
630-
# Source login shell profiles if enabled
631661
if bashunit::env::is_login_shell_enabled; then
632-
# shellcheck disable=SC1091
633-
[ -f /etc/profile ] && source /etc/profile 2>/dev/null || true
634-
# shellcheck disable=SC1090
635-
[ -f ~/.bash_profile ] && source ~/.bash_profile 2>/dev/null || true
636-
# shellcheck disable=SC1090
637-
[ -f ~/.bash_login ] && source ~/.bash_login 2>/dev/null || true
638-
# shellcheck disable=SC1090
639-
[ -f ~/.profile ] && source ~/.profile 2>/dev/null || true
662+
bashunit::runner::source_login_shell_profiles
640663
fi
641664
642665
# Enable coverage tracking early to include set_up/tear_down hooks
@@ -676,18 +699,8 @@ function bashunit::runner::run_test() {
676699
local duration=$((duration_ns / 1000000))
677700

678701
if bashunit::env::is_verbose_enabled; then
679-
if bashunit::env::is_simple_output_enabled; then
680-
echo ""
681-
fi
682-
683-
printf '%*s\n' "$TERMINAL_WIDTH" '' | tr ' ' '='
684-
printf "%s\n" "File: $test_file"
685-
printf "%s\n" "Function: $fn_name"
686-
printf "%s\n" "Duration: $duration ms"
687-
local raw_text=${test_execution_result%%##ASSERTIONS_*}
688-
[ -n "$raw_text" ] && printf "%s" "Raw text: ${test_execution_result%%##ASSERTIONS_*}"
689-
printf "%s\n" "##ASSERTIONS_${test_execution_result#*##ASSERTIONS_}"
690-
printf '%*s\n' "$TERMINAL_WIDTH" '' | tr ' ' '-'
702+
bashunit::runner::print_verbose_test_summary \
703+
"$test_file" "$fn_name" "$duration" "$test_execution_result"
691704
fi
692705

693706
local subshell_output=$(bashunit::runner::decode_subshell_output "$test_execution_result")

0 commit comments

Comments
 (0)