Skip to content

Commit fc7cd14

Browse files
authored
Merge pull request #413 from TypedDevs/chore/optimize-runner
Optimize runner
2 parents a7961ca + 76759a0 commit fc7cd14

2 files changed

Lines changed: 32 additions & 38 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
- Add `assert_not_called`
1111
- Improve `find_total_tests` performance
1212
- Added `assert_match_snapshot_ignore_colors`
13+
- Optimize `runner::parse_result_sync`
1314

1415
## [0.19.1](https://github.com/TypedDevs/bashunit/compare/0.19.0...0.19.1) - 2025-05-23
1516

src/runner.sh

Lines changed: 31 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,11 @@ function runner::functions_for_script() {
5454

5555
# Filter the names down to the ones defined in the script, sort them by line number
5656
shopt -s extdebug
57-
for f in $all_fn_names; do
58-
declare -F "$f" | grep "$script"
59-
done | sort -k2 -n | awk '{print $1}'
57+
# shellcheck disable=SC2086
58+
declare -F $all_fn_names |
59+
awk -v s="$script" '$3 == s {print $1" " $2}' |
60+
sort -k2 -n |
61+
awk '{print $1}'
6062
shopt -u extdebug
6163
}
6264

@@ -349,41 +351,32 @@ function runner::parse_result_sync() {
349351
local fn_name=$1
350352
local execution_result=$2
351353

352-
local assertions_failed=$(\
353-
echo "$execution_result" |\
354-
tail -n 1 |\
355-
sed -E -e 's/.*##ASSERTIONS_FAILED=([0-9]*)##.*/\1/g'\
356-
)
357-
358-
local assertions_passed=$(\
359-
echo "$execution_result" |\
360-
tail -n 1 |\
361-
sed -E -e 's/.*##ASSERTIONS_PASSED=([0-9]*)##.*/\1/g'\
362-
)
363-
364-
local assertions_skipped=$(\
365-
echo "$execution_result" |\
366-
tail -n 1 |\
367-
sed -E -e 's/.*##ASSERTIONS_SKIPPED=([0-9]*)##.*/\1/g'\
368-
)
369-
370-
local assertions_incomplete=$(\
371-
echo "$execution_result" |\
372-
tail -n 1 |\
373-
sed -E -e 's/.*##ASSERTIONS_INCOMPLETE=([0-9]*)##.*/\1/g'\
374-
)
375-
376-
local assertions_snapshot=$(\
377-
echo "$execution_result" |\
378-
tail -n 1 |\
379-
sed -E -e 's/.*##ASSERTIONS_SNAPSHOT=([0-9]*)##.*/\1/g'\
380-
)
381-
382-
local test_exit_code=$(\
383-
echo "$execution_result" |\
384-
tail -n 1 |\
385-
sed -E -e 's/.*##TEST_EXIT_CODE=([0-9]*)##.*/\1/g'\
386-
)
354+
local result_line
355+
result_line=$(echo "$execution_result" | tail -n 1)
356+
357+
local assertions_failed=0
358+
local assertions_passed=0
359+
local assertions_skipped=0
360+
local assertions_incomplete=0
361+
local assertions_snapshot=0
362+
local test_exit_code=0
363+
364+
local regex
365+
regex='ASSERTIONS_FAILED=([0-9]*)##'
366+
regex+='ASSERTIONS_PASSED=([0-9]*)##'
367+
regex+='ASSERTIONS_SKIPPED=([0-9]*)##'
368+
regex+='ASSERTIONS_INCOMPLETE=([0-9]*)##'
369+
regex+='ASSERTIONS_SNAPSHOT=([0-9]*)##'
370+
regex+='TEST_EXIT_CODE=([0-9]*)'
371+
372+
if [[ $result_line =~ $regex ]]; then
373+
assertions_failed="${BASH_REMATCH[1]}"
374+
assertions_passed="${BASH_REMATCH[2]}"
375+
assertions_skipped="${BASH_REMATCH[3]}"
376+
assertions_incomplete="${BASH_REMATCH[4]}"
377+
assertions_snapshot="${BASH_REMATCH[5]}"
378+
test_exit_code="${BASH_REMATCH[6]}"
379+
fi
387380

388381
log "debug" "[SYNC]" "fn_name:$fn_name" "execution_result:$execution_result"
389382

0 commit comments

Comments
 (0)