Skip to content

Commit 4164409

Browse files
authored
refactor(runner): extract encoded field decoder (#657)
1 parent 11a406b commit 4164409

2 files changed

Lines changed: 20 additions & 18 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
- Extract `bashunit::runner::detect_runtime_error` so the 23-pattern runtime-error scan in `run_test` becomes a single named call
1717
- 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)
1818
- Extract `bashunit::runner::compute_total_assertions` so the five `_te_*` parameter-expansion lines collapse into a single named call
19+
- Extract `bashunit::runner::extract_encoded_field` so the three `TEST_TITLE`/`TEST_HOOK_FAILURE`/`TEST_HOOK_MESSAGE` decode blocks share a single key-aware helper instead of three near-duplicates
1920
- 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)
2021
- 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)
2122
- 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 & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,19 @@ function bashunit::runner::apply_interpolated_title() {
4646
printf '%s' "$interpolated"
4747
}
4848

49+
function bashunit::runner::extract_encoded_field() {
50+
local test_execution_result=$1
51+
local key=$2
52+
local marker="##${key}="
53+
case "$test_execution_result" in
54+
*"$marker"*)
55+
local rest="${test_execution_result#*"$marker"}"
56+
printf '%s' "${rest%%##*}"
57+
;;
58+
*) printf '' ;;
59+
esac
60+
}
61+
4962
function bashunit::runner::compute_total_assertions() {
5063
local test_execution_result=$1
5164
local failed passed skipped incomplete snapshot
@@ -790,27 +803,15 @@ function bashunit::runner::run_test() {
790803
local total_assertions
791804
total_assertions=$(bashunit::runner::compute_total_assertions "$test_execution_result")
792805

793-
local encoded_test_title
794-
encoded_test_title="${test_execution_result##*##TEST_TITLE=}"
795-
encoded_test_title="${encoded_test_title%%##*}"
806+
local encoded_test_title hook_failure encoded_hook_message
807+
encoded_test_title=$(bashunit::runner::extract_encoded_field "$test_execution_result" "TEST_TITLE")
808+
hook_failure=$(bashunit::runner::extract_encoded_field "$test_execution_result" "TEST_HOOK_FAILURE")
809+
encoded_hook_message=$(bashunit::runner::extract_encoded_field "$test_execution_result" "TEST_HOOK_MESSAGE")
810+
796811
local test_title=""
797812
[ -n "$encoded_test_title" ] && test_title="$(bashunit::helper::decode_base64 "$encoded_test_title")"
798-
799-
local encoded_hook_failure
800-
encoded_hook_failure="${test_execution_result##*##TEST_HOOK_FAILURE=}"
801-
encoded_hook_failure="${encoded_hook_failure%%##*}"
802-
local hook_failure=""
803-
if [ "$encoded_hook_failure" != "$test_execution_result" ]; then
804-
hook_failure="$encoded_hook_failure"
805-
fi
806-
807-
local encoded_hook_message
808-
encoded_hook_message="${test_execution_result##*##TEST_HOOK_MESSAGE=}"
809-
encoded_hook_message="${encoded_hook_message%%##*}"
810813
local hook_message=""
811-
if [ -n "$encoded_hook_message" ]; then
812-
hook_message="$(bashunit::helper::decode_base64 "$encoded_hook_message")"
813-
fi
814+
[ -n "$encoded_hook_message" ] && hook_message="$(bashunit::helper::decode_base64 "$encoded_hook_message")"
814815

815816
bashunit::set_test_title "$test_title"
816817
local label

0 commit comments

Comments
 (0)