Skip to content

Commit fafbe6b

Browse files
authored
refactor(runner): extract subshell output type and formatter (#656)
1 parent 4a31f9f commit fafbe6b

2 files changed

Lines changed: 20 additions & 13 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
- 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
1515
- 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
1616
- Extract `bashunit::runner::detect_runtime_error` so the 23-pattern runtime-error scan in `run_test` becomes a single named call
17+
- Extract `bashunit::runner::extract_subshell_type` and `bashunit::runner::format_subshell_output` so the encoded-output decode block in `run_test` is two pure transforms (the `print_line` side effect stays at the call site)
1718
- 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)
1819
- 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)
1920
- 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: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,21 @@ function bashunit::runner::apply_interpolated_title() {
4646
printf '%s' "$interpolated"
4747
}
4848

49+
function bashunit::runner::extract_subshell_type() {
50+
local subshell_output=$1
51+
local type="${subshell_output%%]*}"
52+
printf '%s' "${type#[}"
53+
}
54+
55+
function bashunit::runner::format_subshell_output() {
56+
local subshell_output=$1
57+
local line="${subshell_output#*]}"
58+
line=${line//\[failed\]/$'\n'}
59+
line=${line//\[skipped\]/$'\n'}
60+
line=${line//\[incomplete\]/$'\n'}
61+
printf '%s' "$line"
62+
}
63+
4964
function bashunit::runner::detect_runtime_error() {
5065
local runtime_output=$1
5166
local error
@@ -739,21 +754,12 @@ function bashunit::runner::run_test() {
739754
local subshell_output=$(bashunit::runner::decode_subshell_output "$test_execution_result")
740755

741756
if [ -n "$subshell_output" ]; then
742-
# Formatted as "[type]line" @see `bashunit::state::print_line()`
743-
local type="${subshell_output%%]*}" # Remove everything after "]"
744-
type="${type#[}" # Remove the leading "["
745-
local line="${subshell_output#*]}" # Remove everything before and including "]"
746-
747-
# Replace [type] with a newline to split the messages
748-
line=${line//\[failed\]/$'\n'} # Replace [failed] with newline
749-
line=${line//\[skipped\]/$'\n'} # Replace [skipped] with newline
750-
line=${line//\[incomplete\]/$'\n'} # Replace [incomplete] with newline
751-
757+
local type
758+
type=$(bashunit::runner::extract_subshell_type "$subshell_output")
759+
subshell_output=$(bashunit::runner::format_subshell_output "$subshell_output")
752760
if ! bashunit::env::is_failures_only_enabled; then
753-
bashunit::state::print_line "$type" "$line"
761+
bashunit::state::print_line "$type" "$subshell_output"
754762
fi
755-
756-
subshell_output=$line
757763
fi
758764

759765
local runtime_output="${test_execution_result%%##ASSERTIONS_*}"

0 commit comments

Comments
 (0)