File tree Expand file tree Collapse file tree 3 files changed +14
-14
lines changed Expand file tree Collapse file tree 3 files changed +14
-14
lines changed Original file line number Diff line number Diff line change @@ -8,21 +8,20 @@ declare -r BASHUNIT_GIT_REPO="https://github.com/TypedDevs/bashunit"
8
8
# @return string Eg: "Some logic camelCase"
9
9
#
10
10
function helper::normalize_test_function_name() {
11
- local original_function_name=" ${1-} "
11
+ local original_fn_name=" ${1-} "
12
+ local interpolated_fn_name=" ${2-} "
12
13
13
- if [[ -n " ${BASHUNIT_CURRENT_FUNCTION_NAME-} " &&
14
- " $original_function_name " == " $BASHUNIT_CURRENT_FUNCTION_NAME " &&
15
- -n " ${BASHUNIT_INTERPOLATED_FUNCTION_NAME-} " ]]; then
16
- original_function_name=" $BASHUNIT_INTERPOLATED_FUNCTION_NAME "
14
+ if [[ -n " ${interpolated_fn_name-} " ]]; then
15
+ original_fn_name=" $interpolated_fn_name "
17
16
fi
18
17
19
18
local result
20
19
21
20
# Remove the first "test_" prefix, if present
22
- result=" ${original_function_name # test_} "
21
+ result=" ${original_fn_name # test_} "
23
22
# If no "test_" was removed (e.g., "testFoo"), remove the "test" prefix
24
- if [[ " $result " == " $original_function_name " ]]; then
25
- result=" ${original_function_name # test} "
23
+ if [[ " $result " == " $original_fn_name " ]]; then
24
+ result=" ${original_fn_name # test} "
26
25
fi
27
26
# Replace underscores with spaces
28
27
result=" ${result// _/ } "
Original file line number Diff line number Diff line change @@ -136,7 +136,7 @@ function runner::run_test() {
136
136
local function_name=" $1 "
137
137
shift
138
138
export BASHUNIT_CURRENT_FUNCTION_NAME=" $function_name "
139
- export BASHUNIT_INTERPOLATED_FUNCTION_NAME =" $( helper::interpolate_function_name " $function_name " " $@ " ) "
139
+ local interpolated_function_name =" $( helper::interpolate_function_name " $function_name " " $@ " ) "
140
140
local current_assertions_failed=" $( state::get_assertions_failed) "
141
141
local current_assertions_snapshot=" $( state::get_assertions_snapshot) "
142
142
local current_assertions_incomplete=" $( state::get_assertions_incomplete) "
@@ -265,7 +265,7 @@ function runner::run_test() {
265
265
return
266
266
fi
267
267
268
- local label=" $( helper::normalize_test_function_name " $function_name " ) "
268
+ local label=" $( helper::normalize_test_function_name " $function_name " " $interpolated_function_name " ) "
269
269
270
270
console_results::print_successful_test " ${label} " " $duration " " $@ "
271
271
state::add_tests_passed
Original file line number Diff line number Diff line change @@ -228,13 +228,14 @@ function test_to_run_with_filter_matching_string_in_function_name() {
228
228
function test_interpolate_function_name() {
229
229
local result
230
230
result=" $( helper::interpolate_function_name " test_name_::1::_foo" " bar" ) "
231
+
231
232
assert_same " test_name_'bar'_foo" " $result "
232
233
}
233
234
234
235
function test_normalize_test_function_name_with_interpolation() {
235
- local fn=" test_returns_value_::1::_given"
236
- export BASHUNIT_CURRENT_FUNCTION_NAME=" $fn "
236
+ local fn=" test_returns_value_::1::_and_::2::_given"
237
237
# shellcheck disable=SC2155
238
- export BASHUNIT_INTERPOLATED_FUNCTION_NAME=" $( helper::interpolate_function_name " $fn " " 3" ) "
239
- assert_same " Returns value '3' given" " $( helper::normalize_test_function_name " $fn " ) "
238
+ local interpolated_fn=" $( helper::interpolate_function_name " $fn " " 3" " 4" ) "
239
+
240
+ assert_same " Returns value '3' and '4' given" " $( helper::normalize_test_function_name " $fn " " $interpolated_fn " ) "
240
241
}
You can’t perform that action at this time.
0 commit comments