File tree Expand file tree Collapse file tree 3 files changed +48
-1
lines changed
Expand file tree Collapse file tree 3 files changed +48
-1
lines changed Original file line number Diff line number Diff line change 2020 - Can also be set via ` BASHUNIT_NO_PROGRESS=true ` environment variable
2121
2222### Fixed
23+ - Data providers now work without the ` function ` keyword on test functions (Issue #586 )
24+ - Previously, data provider detection required at least the first test using a provider to have the ` function ` keyword
25+ - Now all test functions work consistently regardless of whether they use the ` function ` keyword
26+ - Fixes regex in ` bashunit::helper::get_provider_data() ` to make the ` function ` keyword optional
2327- Self-test ` tests/acceptance/install_test.sh ` now passes when no network tools are available (Issue #582 )
2428 - Tests skip gracefully with ` BASHUNIT_NO_NETWORK=true ` or in sandboxed environments
2529
Original file line number Diff line number Diff line change @@ -262,7 +262,7 @@ function bashunit::helper::get_provider_data() {
262262 local data_provider_function
263263 data_provider_function=$(
264264 # shellcheck disable=SC1087
265- grep -B 2 -E " function[[:space:]]+$function_name [[:space:]]*\(\)" " $script " 2> /dev/null | \
265+ grep -B 2 -E " ( function[[:space:]]+)? $function_name [[:space:]]*\(\)" " $script " 2> /dev/null | \
266266 sed -nE ' s/^[[:space:]]*# *@?data_provider[[:space:]]+//p'
267267 )
268268
Original file line number Diff line number Diff line change 1+ #! /usr/bin/env bash
2+ set -euo pipefail
3+
4+ # Test case for issue #586: data providers should work without the function keyword
5+ # All test functions and providers defined WITHOUT the function keyword
6+
7+ # @data_provider provide_test_data_1
8+ test_should_work_without_function_keyword_1 () {
9+ local input=" $1 "
10+ local expected=" $2 "
11+
12+ assert_equals " $expected " " $input "
13+ }
14+
15+ provide_test_data_1 () {
16+ echo " value1" " value1"
17+ echo " value2" " value2"
18+ }
19+
20+ # @data_provider provide_test_data_2
21+ test_should_work_without_function_keyword_2 () {
22+ local input=" $1 "
23+
24+ assert_not_equals " invalid" " $input "
25+ }
26+
27+ provide_test_data_2 () {
28+ echo " first"
29+ echo " second"
30+ }
31+
32+ # @data_provider provide_test_data_3
33+ test_should_work_without_function_keyword_3 () {
34+ local value=" $1 "
35+
36+ assert_matches " ^test" " $value "
37+ }
38+
39+ provide_test_data_3 () {
40+ bashunit::data_set " test1"
41+ bashunit::data_set " test2"
42+ bashunit::data_set " test3"
43+ }
You can’t perform that action at this time.
0 commit comments