Skip to content

Commit 623499d

Browse files
authored
Merge pull request #407 from TypedDevs/chore/use-at-data_provider
Deprecate data_provider in favor of @data_provider
2 parents 4f11e82 + f743bf5 commit 623499d

9 files changed

Lines changed: 59 additions & 18 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
- Fix asserts on test doubles in subshell
66
- Allow interpolating arguments in data providers output
7+
- Deprecate `# data_provider` in favor of `# @data_provider`
78

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

adrs/adr-004-metadata-prefix.md

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# Title: Prefix metadata comments with @
2+
3+
* Status: accepted
4+
* Authors: @Chemaclass
5+
* Date: 2025-05-29
6+
7+
8+
## Context and Problem Statement
9+
10+
Data providers are defined via a special comment `# data_provider`. We want to
11+
clearly differentiate these meta comments from ordinary comments.
12+
13+
## Considered Options
14+
15+
* Keep using `# data_provider` as is.
16+
* Introduce an `@` prefix for special comments while supporting the old syntax.
17+
18+
## Decision Outcome
19+
20+
We decided to prefix the metadata provider directives with `@`,
21+
eg: using `# @data_provider provider_name`.
22+
23+
> The previous form without the prefix is still supported for backward compatibility but is now deprecated.
24+
25+
### Positive Consequences
26+
27+
* Highlights special bashunit directives clearly.
28+
* Allows future directives to consistently use the `@` prefix.
29+
30+
### Negative Consequences
31+
32+
* Projects must eventually update old comments to the new syntax.
33+
34+
## Technical Details
35+
36+
`helper::get_provider_data` now matches both `# @data_provider` and the old
37+
`# data_provider` when locating provider functions.

docs/blog/2024-09-01-release-0-15.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ BASHUNIT_REPORT_HTML=
5151

5252
::: code-group
5353
```bash [example_test.sh]
54-
# data_provider provider_directories
54+
# @data_provider provider_directories
5555
function test_directory_exists() {
5656
local outro=$1
5757
local directory=$2

docs/data-providers.md

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,12 @@ Each run is treated as a separate test, so it can pass or fail independently. Pl
1313

1414
A data provider function is specified as follows:
1515

16+
> **Note**: The previous `# data_provider` syntax is still supported but
17+
> deprecated. Prefer using the `@` prefix going forward.
18+
1619
::: code-group
1720
```bash [Example]
18-
# data_provider provider_function_name
21+
# @data_provider provider_function_name
1922
function test_my_test_case() {
2023
...
2124
}
@@ -32,7 +35,7 @@ argument position.
3235

3336
::: code-group
3437
```bash [example_test.sh]
35-
# data_provider fizz_numbers
38+
# @data_provider fizz_numbers
3639
function test_returns_fizz_when_multiple_of_::1::_like_::2::_given() {
3740
# ...
3841
}
@@ -53,7 +56,7 @@ Running example_test.sh
5356

5457
::: code-group
5558
```bash [example_test.sh]
56-
# data_provider provider_directories
59+
# @data_provider provider_directories
5760
function test_directories_exists() {
5861
local dir1=$1
5962
local dir2=$2
@@ -78,7 +81,7 @@ Running example_test.sh
7881

7982
::: code-group
8083
```bash [example_test.sh]
81-
# data_provider provider_directories
84+
# @data_provider provider_directories
8285
function test_directory_exists() {
8386
local directory=$1
8487

@@ -103,7 +106,7 @@ Running example_test.sh
103106

104107
::: code-group
105108
```bash [example_test.sh]
106-
# data_provider provider_directories
109+
# @data_provider provider_directories
107110
function test_directory_exists() {
108111
local outro=$1
109112
local directory=$2

src/helpers.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -158,9 +158,9 @@ function helper::get_provider_data() {
158158
fi
159159

160160
data_provider_function=$(\
161-
grep -B 1 "function $function_name()" "$script" |\
162-
grep "# data_provider " |\
163-
sed -E -e 's/\ *# data_provider (.*)$/\1/g'\
161+
grep -B 2 "function $function_name()" "$script" |\
162+
grep -E "# *@?data_provider " |\
163+
sed -E -e 's/\ *# *@?data_provider (.*)$/\1/g'\
164164
|| true
165165
)
166166

tests/functional/provider_test.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ function set_up() {
55
_GLOBAL="aa-bb"
66
}
77

8-
# data_provider provide_multiples_values
8+
# @data_provider provide_multiples_values
99
function test_multiple_values_from_data_provider() {
1010
local first=$1
1111
local second=$2
@@ -17,7 +17,7 @@ function provide_multiples_values() {
1717
echo "aa" "bb"
1818
}
1919

20-
# data_provider provide_single_values
20+
# @data_provider provide_single_values
2121
function test_single_values_from_data_provider() {
2222
local data="$1"
2323

@@ -30,7 +30,7 @@ function provide_single_values() {
3030
echo "three"
3131
}
3232

33-
# data_provider provide_single_value
33+
# @data_provider provide_single_value
3434
function test_single_value_from_data_provider() {
3535
local current_data="$1"
3636

tests/unit/assert_test.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ function test_unsuccessful_fail() {
1111
"$(fail "Failure message")"
1212
}
1313

14-
# data_provider provider_successful_assert_true
14+
# @data_provider provider_successful_assert_true
1515
function test_successful_assert_true() {
1616
# shellcheck disable=SC2086
1717
assert_empty "$(assert_true $1)"
@@ -45,7 +45,7 @@ function test_unsuccessful_assert_true_on_function() {
4545
"$(assert_true "eval return 2")"
4646
}
4747

48-
# data_provider provider_successful_assert_false
48+
# @data_provider provider_successful_assert_false
4949
function test_successful_assert_false() {
5050
# shellcheck disable=SC2086
5151
assert_empty "$(assert_false $1)"

tests/unit/check_os_test.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ function test_detect_osx_os() {
4040
assert_equals "OSX" "$_OS"
4141
}
4242

43-
# data_provider window_linux_variations
43+
# @data_provider window_linux_variations
4444
function test_detect_windows_os() {
4545
local windows_linux="$1"
4646
mock uname echo "$windows_linux"

tests/unit/helpers_test.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ function fake_provider_data_string() {
123123

124124
function test_get_provider_data() {
125125
# shellcheck disable=SC2317
126-
# data_provider fake_provider_data_string
126+
# @data_provider fake_provider_data_string
127127
function fake_function_get_provider_data() {
128128
return 0
129129
}
@@ -137,8 +137,8 @@ function fake_provider_data_array() {
137137
}
138138

139139
function test_get_provider_data_array() {
140+
# @data_provider fake_provider_data_array
140141
# shellcheck disable=SC2317
141-
# data_provider fake_provider_data_array
142142
function fake_function_get_provider_data_array() {
143143
return 0
144144
}
@@ -150,7 +150,7 @@ function test_get_provider_data_array() {
150150

151151
function test_get_provider_data_should_returns_empty_when_not_exists_provider_function() {
152152
# shellcheck disable=SC2317
153-
# data_provider not_existing_provider
153+
# @data_provider not_existing_provider
154154
function fake_function_get_not_existing_provider_data() {
155155
return 0
156156
}

0 commit comments

Comments
 (0)