File tree Expand file tree Collapse file tree 6 files changed +107
-8
lines changed
fixtures/find_total_tests Expand file tree Collapse file tree 6 files changed +107
-8
lines changed Original file line number Diff line number Diff line change 5
5
- Fix typo "to has been called"
6
6
- Add weekly downloads to the docs
7
7
- Fix parallel runner
8
+ - Count data providers when counting total tests
8
9
9
10
## [ 0.20.0] ( https://github.com/TypedDevs/bashunit/compare/0.19.1...0.20.0 ) - 2025-06-01
10
11
Original file line number Diff line number Diff line change 36
36
if [ " $total_tests " -eq 0 ]; then
37
37
printf " %s\n" " $BASHUNIT_VERSION "
38
38
else
39
- printf " %s | Tests: ~ %s\n" " $BASHUNIT_VERSION " " $total_tests "
39
+ printf " %s | Tests: %s\n" " $BASHUNIT_VERSION " " $total_tests "
40
40
fi
41
41
return
42
42
fi
43
43
44
44
if [ " $total_tests " -eq 0 ]; then
45
45
printf " ${_COLOR_BOLD}${_COLOR_PASSED} bashunit${_COLOR_DEFAULT} - %s\n" " $BASHUNIT_VERSION "
46
46
else
47
- printf " ${_COLOR_BOLD}${_COLOR_PASSED} bashunit${_COLOR_DEFAULT} - %s | Tests: ~ %s\n" \
47
+ printf " ${_COLOR_BOLD}${_COLOR_PASSED} bashunit${_COLOR_DEFAULT} - %s | Tests: %s\n" \
48
48
" $BASHUNIT_VERSION " \
49
49
" $total_tests "
50
50
fi
Original file line number Diff line number Diff line change @@ -196,12 +196,49 @@ function helpers::find_total_tests() {
196
196
return
197
197
fi
198
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=" *[tT]est.sh" " ${files[@]} " 2> /dev/null | wc -l | xargs
199
+ local total_count=0
200
+ local file
201
+
202
+ for file in " ${files[@]} " ; do
203
+ if [[ ! -f " $file " ]]; then
204
+ continue
205
+ fi
206
+
207
+ local file_count
208
+ file_count=$( (
209
+ # shellcheck source=/dev/null
210
+ source " $file "
211
+ local all_fn_names
212
+ all_fn_names=$( declare -F | awk ' {print $3}' )
213
+ local filtered_functions
214
+ filtered_functions=$( helper::get_functions_to_run " test" " $filter " " $all_fn_names " ) || true
215
+
216
+ local count=0
217
+ if [[ -n " $filtered_functions " ]]; then
218
+ # shellcheck disable=SC2206
219
+ # shellcheck disable=SC2207
220
+ local functions_to_run=($filtered_functions )
221
+ for fn_name in " ${functions_to_run[@]} " ; do
222
+ local provider_data=()
223
+ while IFS=" " read -r line; do
224
+ provider_data+=(" $line " )
225
+ done <<< " $(helper::get_provider_data " $fn_name " " $file " )"
226
+
227
+ if [[ " ${# provider_data[@]} " -eq 0 ]]; then
228
+ count=$(( count + 1 ))
229
+ else
230
+ count=$(( count + ${# provider_data[@]} ))
231
+ fi
232
+ done
233
+ fi
234
+
235
+ echo " $count "
236
+ ) )
237
+
238
+ total_count=$(( total_count + file_count))
239
+ done
240
+
241
+ echo " $total_count "
205
242
}
206
243
207
244
function helper::load_test_files() {
Original file line number Diff line number Diff line change
1
+ #! /usr/bin/env bash
2
+
3
+ # @data_provider provider_lines
4
+ function test_with_provider() {
5
+ return 0
6
+ }
7
+
8
+ function provider_lines() {
9
+ echo " alpha beta"
10
+ echo " gamma"
11
+ echo " delta epsilon zeta"
12
+ }
Original file line number Diff line number Diff line change
1
+ #! /usr/bin/env bash
2
+
3
+ function test_first() {
4
+ return 0
5
+ }
6
+
7
+ function test_second() {
8
+ return 0
9
+ }
Original file line number Diff line number Diff line change @@ -239,3 +239,43 @@ function test_normalize_test_function_name_with_interpolation() {
239
239
240
240
assert_same " Returns value '3' and '4' given" " $( helper::normalize_test_function_name " $fn " " $interpolated_fn " ) "
241
241
}
242
+
243
+ function helpers_test::find_total_in_subshell() {
244
+ bash -c ' source "$1"; shift; helpers::find_total_tests "$@"' bash " $BASHUNIT_ROOT_DIR /src/helpers.sh" " $@ "
245
+ }
246
+
247
+ function test_find_total_tests_no_files() {
248
+ assert_same " 0" " $( helpers_test::find_total_in_subshell) "
249
+ }
250
+
251
+ function test_find_total_tests_simple_file() {
252
+ local file
253
+ file=" $( current_dir) /fixtures/find_total_tests/simple_test.sh"
254
+
255
+ assert_same " 2" " $( helpers_test::find_total_in_subshell " " " $file " ) "
256
+ }
257
+
258
+ function test_find_total_tests_with_provider() {
259
+ local file
260
+ file=" $( current_dir) /fixtures/find_total_tests/provider_test.sh"
261
+
262
+ assert_same " 3" " $( helpers_test::find_total_in_subshell " " " $file " ) "
263
+ }
264
+
265
+ function test_find_total_tests_multiple_files() {
266
+ local file1
267
+ local file2
268
+ file1=" $( current_dir) /fixtures/find_total_tests/simple_test.sh"
269
+ file2=" $( current_dir) /fixtures/find_total_tests/provider_test.sh"
270
+
271
+ assert_same " 5" " $( helpers_test::find_total_in_subshell " " " $file1 " " $file2 " ) "
272
+ }
273
+
274
+ function test_find_total_tests_with_filter() {
275
+ local file1
276
+ local file2
277
+ file1=" $( current_dir) /fixtures/find_total_tests/simple_test.sh"
278
+ file2=" $( current_dir) /fixtures/find_total_tests/provider_test.sh"
279
+
280
+ assert_same " 3" " $( helpers_test::find_total_in_subshell " with_provider" " $file1 " " $file2 " ) "
281
+ }
You can’t perform that action at this time.
0 commit comments