File tree Expand file tree Collapse file tree 5 files changed +40
-0
lines changed Expand file tree Collapse file tree 5 files changed +40
-0
lines changed Original file line number Diff line number Diff line change 1616- Fix preservation of trailing whitespace in final argument to ` data_set `
1717- Fix unbound variable error in ` parse_data_provider_args ` with ` set -u `
1818- Fix wrong assertion_failed name of test on failure
19+ - Fix test name interpolation on failure
1920
2021## [ 0.24.0] ( https://github.com/TypedDevs/bashunit/compare/0.23.0...0.24.0 ) - 2025-09-14
2122
Original file line number Diff line number Diff line change @@ -18,6 +18,15 @@ function helper::normalize_test_function_name() {
1818 return
1919 fi
2020
21+ if [[ -z " ${interpolated_fn_name-} " && " ${original_fn_name} " == * " ::" * ]]; then
22+ local state_interpolated_fn_name
23+ state_interpolated_fn_name=" $( state::get_current_test_interpolated_function_name) "
24+
25+ if [[ -n " $state_interpolated_fn_name " ]]; then
26+ interpolated_fn_name=" $state_interpolated_fn_name "
27+ fi
28+ fi
29+
2130 if [[ -n " ${interpolated_fn_name-} " ]]; then
2231 original_fn_name=" $interpolated_fn_name "
2332 fi
Original file line number Diff line number Diff line change @@ -305,6 +305,11 @@ function runner::run_test() {
305305 state::reset_test_title
306306
307307 local interpolated_fn_name=" $( helper::interpolate_function_name " $fn_name " " $@ " ) "
308+ if [[ " $interpolated_fn_name " != " $fn_name " ]]; then
309+ state::set_current_test_interpolated_function_name " $interpolated_fn_name "
310+ else
311+ state::reset_current_test_interpolated_function_name
312+ fi
308313 local current_assertions_failed=" $( state::get_assertions_failed) "
309314 local current_assertions_snapshot=" $( state::get_assertions_snapshot) "
310315 local current_assertions_incomplete=" $( state::get_assertions_incomplete) "
@@ -416,6 +421,7 @@ function runner::run_test() {
416421 local label
417422 label=" $( helper::normalize_test_function_name " $fn_name " " $interpolated_fn_name " ) "
418423 state::reset_test_title
424+ state::reset_current_test_interpolated_function_name
419425
420426 local failure_label=" $label "
421427 local failure_function=" $fn_name "
Original file line number Diff line number Diff line change @@ -18,6 +18,7 @@ _TEST_TITLE=""
1818_TEST_EXIT_CODE=0
1919_TEST_HOOK_FAILURE=" "
2020_TEST_HOOK_MESSAGE=" "
21+ _CURRENT_TEST_INTERPOLATED_NAME=" "
2122
2223function state::get_tests_passed() {
2324 echo " $_TESTS_PASSED "
@@ -147,6 +148,18 @@ function state::reset_test_title() {
147148 _TEST_TITLE=" "
148149}
149150
151+ function state::get_current_test_interpolated_function_name() {
152+ echo " $_CURRENT_TEST_INTERPOLATED_NAME "
153+ }
154+
155+ function state::set_current_test_interpolated_function_name() {
156+ _CURRENT_TEST_INTERPOLATED_NAME=" $1 "
157+ }
158+
159+ function state::reset_current_test_interpolated_function_name() {
160+ _CURRENT_TEST_INTERPOLATED_NAME=" "
161+ }
162+
150163function state::get_test_hook_failure() {
151164 echo " $_TEST_HOOK_FAILURE "
152165}
Original file line number Diff line number Diff line change @@ -39,6 +39,17 @@ function test_normalize_test_function_name_custom_title() {
3939 assert_same " 🔥 handles invalid input with 💣" " $( helper::normalize_test_function_name " test_handles_invalid_input" ) "
4040}
4141
42+ function test_normalize_test_function_name_uses_current_interpolated_name_from_state() {
43+ local fn_name=" test_::1::_interpolated_output"
44+ local interpolated_fn=" test_'value'_interpolated_output"
45+
46+ state::set_current_test_interpolated_function_name " $interpolated_fn "
47+
48+ assert_same " 'value' interpolated output" " $( helper::normalize_test_function_name " $fn_name " ) "
49+
50+ state::reset_current_test_interpolated_function_name
51+ }
52+
4253function test_get_functions_to_run_no_filter_should_return_all_functions() {
4354 local functions=(" prefix_function1" " prefix_function2" " other_function" " prefix_function3" )
4455
You can’t perform that action at this time.
0 commit comments