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 @@ -16,6 +16,7 @@
- Fix preservation of trailing whitespace in final argument to `data_set`
- Fix unbound variable error in `parse_data_provider_args` with `set -u`
- Fix wrong assertion_failed name of test on failure
- Fix test name interpolation on failure

## [0.24.0](https://github.com/TypedDevs/bashunit/compare/0.23.0...0.24.0) - 2025-09-14

Expand Down
9 changes: 9 additions & 0 deletions src/helpers.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,15 @@ function helper::normalize_test_function_name() {
return
fi

if [[ -z "${interpolated_fn_name-}" && "${original_fn_name}" == *"::"* ]]; then
local state_interpolated_fn_name
state_interpolated_fn_name="$(state::get_current_test_interpolated_function_name)"

if [[ -n "$state_interpolated_fn_name" ]]; then
interpolated_fn_name="$state_interpolated_fn_name"
fi
fi

if [[ -n "${interpolated_fn_name-}" ]]; then
original_fn_name="$interpolated_fn_name"
fi
Expand Down
6 changes: 6 additions & 0 deletions src/runner.sh
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,11 @@ function runner::run_test() {
state::reset_test_title

local interpolated_fn_name="$(helper::interpolate_function_name "$fn_name" "$@")"
if [[ "$interpolated_fn_name" != "$fn_name" ]]; then
state::set_current_test_interpolated_function_name "$interpolated_fn_name"
else
state::reset_current_test_interpolated_function_name
fi
local current_assertions_failed="$(state::get_assertions_failed)"
local current_assertions_snapshot="$(state::get_assertions_snapshot)"
local current_assertions_incomplete="$(state::get_assertions_incomplete)"
Expand Down Expand Up @@ -416,6 +421,7 @@ function runner::run_test() {
local label
label="$(helper::normalize_test_function_name "$fn_name" "$interpolated_fn_name")"
state::reset_test_title
state::reset_current_test_interpolated_function_name

local failure_label="$label"
local failure_function="$fn_name"
Expand Down
13 changes: 13 additions & 0 deletions src/state.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ _TEST_TITLE=""
_TEST_EXIT_CODE=0
_TEST_HOOK_FAILURE=""
_TEST_HOOK_MESSAGE=""
_CURRENT_TEST_INTERPOLATED_NAME=""

function state::get_tests_passed() {
echo "$_TESTS_PASSED"
Expand Down Expand Up @@ -147,6 +148,18 @@ function state::reset_test_title() {
_TEST_TITLE=""
}

function state::get_current_test_interpolated_function_name() {
echo "$_CURRENT_TEST_INTERPOLATED_NAME"
}

function state::set_current_test_interpolated_function_name() {
_CURRENT_TEST_INTERPOLATED_NAME="$1"
}

function state::reset_current_test_interpolated_function_name() {
_CURRENT_TEST_INTERPOLATED_NAME=""
}

function state::get_test_hook_failure() {
echo "$_TEST_HOOK_FAILURE"
}
Expand Down
11 changes: 11 additions & 0 deletions tests/unit/helpers_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,17 @@ function test_normalize_test_function_name_custom_title() {
assert_same "πŸ”₯ handles invalid input with πŸ’£" "$(helper::normalize_test_function_name "test_handles_invalid_input")"
}

function test_normalize_test_function_name_uses_current_interpolated_name_from_state() {
local fn_name="test_::1::_interpolated_output"
local interpolated_fn="test_'value'_interpolated_output"

state::set_current_test_interpolated_function_name "$interpolated_fn"

assert_same "'value' interpolated output" "$(helper::normalize_test_function_name "$fn_name")"

state::reset_current_test_interpolated_function_name
}

function test_get_functions_to_run_no_filter_should_return_all_functions() {
local functions=("prefix_function1" "prefix_function2" "other_function" "prefix_function3")

Expand Down
Loading