Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

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

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

Expand Down
37 changes: 37 additions & 0 deletions adrs/adr-004-metadata-prefix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# Title: Prefix metadata comments with @

* Status: accepted
* Authors: @Chemaclass
* Date: 2025-05-29


## Context and Problem Statement

Data providers are defined via a special comment `# data_provider`. We want to
clearly differentiate these meta comments from ordinary comments.

## Considered Options

* Keep using `# data_provider` as is.
* Introduce an `@` prefix for special comments while supporting the old syntax.

## Decision Outcome

We decided to prefix the metadata provider directives with `@`,
eg: using `# @data_provider provider_name`.

> The previous form without the prefix is still supported for backward compatibility but is now deprecated.

### Positive Consequences

* Highlights special bashunit directives clearly.
* Allows future directives to consistently use the `@` prefix.

### Negative Consequences

* Projects must eventually update old comments to the new syntax.

## Technical Details

`helper::get_provider_data` now matches both `# @data_provider` and the old
`# data_provider` when locating provider functions.
2 changes: 1 addition & 1 deletion docs/blog/2024-09-01-release-0-15.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ BASHUNIT_REPORT_HTML=

::: code-group
```bash [example_test.sh]
# data_provider provider_directories
# @data_provider provider_directories
function test_directory_exists() {
local outro=$1
local directory=$2
Expand Down
13 changes: 8 additions & 5 deletions docs/data-providers.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,12 @@ Each run is treated as a separate test, so it can pass or fail independently. Pl

A data provider function is specified as follows:

> **Note**: The previous `# data_provider` syntax is still supported but
> deprecated. Prefer using the `@` prefix going forward.

::: code-group
```bash [Example]
# data_provider provider_function_name
# @data_provider provider_function_name
function test_my_test_case() {
...
}
Expand All @@ -32,7 +35,7 @@ argument position.

::: code-group
```bash [example_test.sh]
# data_provider fizz_numbers
# @data_provider fizz_numbers
function test_returns_fizz_when_multiple_of_::1::_like_::2::_given() {
# ...
}
Expand All @@ -53,7 +56,7 @@ Running example_test.sh

::: code-group
```bash [example_test.sh]
# data_provider provider_directories
# @data_provider provider_directories
function test_directories_exists() {
local dir1=$1
local dir2=$2
Expand All @@ -78,7 +81,7 @@ Running example_test.sh

::: code-group
```bash [example_test.sh]
# data_provider provider_directories
# @data_provider provider_directories
function test_directory_exists() {
local directory=$1

Expand All @@ -103,7 +106,7 @@ Running example_test.sh

::: code-group
```bash [example_test.sh]
# data_provider provider_directories
# @data_provider provider_directories
function test_directory_exists() {
local outro=$1
local directory=$2
Expand Down
6 changes: 3 additions & 3 deletions src/helpers.sh
Original file line number Diff line number Diff line change
Expand Up @@ -158,9 +158,9 @@ function helper::get_provider_data() {
fi

data_provider_function=$(\
grep -B 1 "function $function_name()" "$script" |\
grep "# data_provider " |\
sed -E -e 's/\ *# data_provider (.*)$/\1/g'\
grep -B 2 "function $function_name()" "$script" |\
grep -E "# *@?data_provider " |\
sed -E -e 's/\ *# *@?data_provider (.*)$/\1/g'\
|| true
)

Expand Down
6 changes: 3 additions & 3 deletions tests/functional/provider_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ function set_up() {
_GLOBAL="aa-bb"
}

# data_provider provide_multiples_values
# @data_provider provide_multiples_values
function test_multiple_values_from_data_provider() {
local first=$1
local second=$2
Expand All @@ -17,7 +17,7 @@ function provide_multiples_values() {
echo "aa" "bb"
}

# data_provider provide_single_values
# @data_provider provide_single_values
function test_single_values_from_data_provider() {
local data="$1"

Expand All @@ -30,7 +30,7 @@ function provide_single_values() {
echo "three"
}

# data_provider provide_single_value
# @data_provider provide_single_value
function test_single_value_from_data_provider() {
local current_data="$1"

Expand Down
4 changes: 2 additions & 2 deletions tests/unit/assert_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ function test_unsuccessful_fail() {
"$(fail "Failure message")"
}

# data_provider provider_successful_assert_true
# @data_provider provider_successful_assert_true
function test_successful_assert_true() {
# shellcheck disable=SC2086
assert_empty "$(assert_true $1)"
Expand Down Expand Up @@ -45,7 +45,7 @@ function test_unsuccessful_assert_true_on_function() {
"$(assert_true "eval return 2")"
}

# data_provider provider_successful_assert_false
# @data_provider provider_successful_assert_false
function test_successful_assert_false() {
# shellcheck disable=SC2086
assert_empty "$(assert_false $1)"
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/check_os_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ function test_detect_osx_os() {
assert_equals "OSX" "$_OS"
}

# data_provider window_linux_variations
# @data_provider window_linux_variations
function test_detect_windows_os() {
local windows_linux="$1"
mock uname echo "$windows_linux"
Expand Down
6 changes: 3 additions & 3 deletions tests/unit/helpers_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ function fake_provider_data_string() {

function test_get_provider_data() {
# shellcheck disable=SC2317
# data_provider fake_provider_data_string
# @data_provider fake_provider_data_string
function fake_function_get_provider_data() {
return 0
}
Expand All @@ -137,8 +137,8 @@ function fake_provider_data_array() {
}

function test_get_provider_data_array() {
# @data_provider fake_provider_data_array
# shellcheck disable=SC2317
# data_provider fake_provider_data_array
function fake_function_get_provider_data_array() {
return 0
}
Expand All @@ -150,7 +150,7 @@ function test_get_provider_data_array() {

function test_get_provider_data_should_returns_empty_when_not_exists_provider_function() {
# shellcheck disable=SC2317
# data_provider not_existing_provider
# @data_provider not_existing_provider
function fake_function_get_not_existing_provider_data() {
return 0
}
Expand Down
Loading