Skip to content

Commit bd46555

Browse files
committed
chore: improve find_total_tests performance
1 parent 4c23069 commit bd46555

2 files changed

Lines changed: 13 additions & 13 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
- Allow `assert_have_been_called_with` to check arguments of specific calls
99
- Enable parallel tests on Windows
1010
- Add `assert_not_called`
11+
- Improve `find_total_tests` performance
1112

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

src/helpers.sh

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -190,19 +190,18 @@ function helpers::get_latest_tag() {
190190
function helpers::find_total_tests() {
191191
local filter=${1:-}
192192
local files=("${@:2}")
193-
local total_count=0
194-
195-
for file in "${files[@]}"; do
196-
local count
197-
if [[ -n "$filter" ]]; then
198-
count=$(grep -r -E "^\s*function\s+test.*$filter" "$file" --include=\*.sh 2>/dev/null | wc -l)
199-
else
200-
count=$(grep -r -E '^\s*function\s+test' "$file" --include=\*.sh 2>/dev/null | wc -l)
201-
fi
202-
total_count=$((total_count + count))
203-
done
204-
205-
echo "$total_count"
193+
194+
if [[ ${#files[@]} -eq 0 ]]; then
195+
echo 0
196+
return
197+
fi
198+
199+
local pattern='^\s*function\s+test'
200+
if [[ -n "$filter" ]]; then
201+
pattern+=".*$filter"
202+
fi
203+
204+
grep -r -E "$pattern" --include="*.sh" "${files[@]}" 2>/dev/null | wc -l | xargs
206205
}
207206

208207
function helper::load_test_files() {

0 commit comments

Comments
 (0)