Skip to content

Commit bcf5952

Browse files
committed
perf(runner): replace grep/sed with parameter expansion in parse_result_sync
Drop six echo|sed subprocesses and one grep per sync test result parse at src/runner.sh:971. Use bash parameter expansion (##*, %%##*) in a single case branch, matching the pattern already used by the async path at lines 714-727. Bash 3.0+ compatible.
1 parent 36e162c commit bcf5952

File tree

1 file changed

+26
-10
lines changed

1 file changed

+26
-10
lines changed

src/runner.sh

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -966,16 +966,32 @@ function bashunit::runner::parse_result_sync() {
966966
local assertions_snapshot=0
967967
local test_exit_code=0
968968

969-
# Extract values using sed instead of BASH_REMATCH for Bash 3.0+ compatibility
970-
# shellcheck disable=SC2001
971-
if [ "$(echo "$result_line" | "$GREP" -cE 'ASSERTIONS_FAILED=[0-9]*##ASSERTIONS_PASSED=[0-9]*' || true)" -gt 0 ]; then
972-
assertions_failed=$(echo "$result_line" | sed 's/.*ASSERTIONS_FAILED=\([0-9]*\)##.*/\1/')
973-
assertions_passed=$(echo "$result_line" | sed 's/.*ASSERTIONS_PASSED=\([0-9]*\)##.*/\1/')
974-
assertions_skipped=$(echo "$result_line" | sed 's/.*ASSERTIONS_SKIPPED=\([0-9]*\)##.*/\1/')
975-
assertions_incomplete=$(echo "$result_line" | sed 's/.*ASSERTIONS_INCOMPLETE=\([0-9]*\)##.*/\1/')
976-
assertions_snapshot=$(echo "$result_line" | sed 's/.*ASSERTIONS_SNAPSHOT=\([0-9]*\)##.*/\1/')
977-
test_exit_code=$(echo "$result_line" | sed 's/.*TEST_EXIT_CODE=\([0-9]*\).*/\1/')
978-
fi
969+
# Extract values using parameter expansion instead of spawning grep/sed subprocesses
970+
case "$result_line" in
971+
*"ASSERTIONS_FAILED="*"##ASSERTIONS_PASSED="*)
972+
local _tail
973+
_tail="${result_line##*ASSERTIONS_FAILED=}"
974+
assertions_failed="${_tail%%##*}"
975+
_tail="${result_line##*ASSERTIONS_PASSED=}"
976+
assertions_passed="${_tail%%##*}"
977+
_tail="${result_line##*ASSERTIONS_SKIPPED=}"
978+
assertions_skipped="${_tail%%##*}"
979+
_tail="${result_line##*ASSERTIONS_INCOMPLETE=}"
980+
assertions_incomplete="${_tail%%##*}"
981+
_tail="${result_line##*ASSERTIONS_SNAPSHOT=}"
982+
assertions_snapshot="${_tail%%##*}"
983+
_tail="${result_line##*TEST_EXIT_CODE=}"
984+
test_exit_code="${_tail%%##*}"
985+
# Strip any trailing non-digit suffix (end of line) from the final field
986+
test_exit_code="${test_exit_code%%[!0-9]*}"
987+
: "${assertions_failed:=0}"
988+
: "${assertions_passed:=0}"
989+
: "${assertions_skipped:=0}"
990+
: "${assertions_incomplete:=0}"
991+
: "${assertions_snapshot:=0}"
992+
: "${test_exit_code:=0}"
993+
;;
994+
esac
979995

980996
bashunit::internal_log "[SYNC]" "fn_name:$fn_name" "execution_result:$execution_result"
981997

0 commit comments

Comments
 (0)