Skip to content

Commit

Permalink
Merge pull request #388 from TypedDevs/fix/387-test-tests-display-name
Browse files Browse the repository at this point in the history
Fix display name when test_test_*
  • Loading branch information
Chemaclass authored Dec 5, 2024
2 parents dd06592 + 922a4d4 commit 3efc0a7
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
## Unreleased

- Improved output: adding a space between each test file
- Remove `BASHUNIT_DEV_MODE` in favor of `BASHUNIT_DEV_LOG`
- Removed `BASHUNIT_DEV_MODE` in favor of `BASHUNIT_DEV_LOG`
- Fixed name rendered when having `test_test_*`

## [0.18.0](https://github.com/TypedDevs/bashunit/compare/0.17.0...0.18.0) - 2024-10-16

Expand Down
8 changes: 5 additions & 3 deletions src/helpers.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,14 @@ function helper::normalize_test_function_name() {
local original_function_name="${1-}"
local result

# Remove "test_" prefix
# Remove the first "test_" prefix, if present
result="${original_function_name#test_}"
# If no "test_" was removed (e.g., "testFoo"), remove the "test" prefix
if [[ "$result" == "$original_function_name" ]]; then
result="${original_function_name#test}"
fi
# Replace underscores with spaces
result="${result//_/ }"
# Remove "test" prefix
result="${result#test}"
# Capitalize the first letter
result="$(tr '[:lower:]' '[:upper:]' <<< "${result:0:1}")${result:1}"

Expand Down
4 changes: 4 additions & 0 deletions tests/unit/helpers_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ function test_normalize_test_function_name_snake_case() {
assert_same "Some logic" "$(helper::normalize_test_function_name "test_some_logic")"
}

function test_normalize_double_test_function_name_snake_case() {
assert_same "Test some logic" "$(helper::normalize_test_function_name "test_test_some_logic")"
}

function test_normalize_test_function_name_camel_case() {
assert_same "SomeLogic" "$(helper::normalize_test_function_name "testSomeLogic")"
}
Expand Down

0 comments on commit 3efc0a7

Please sign in to comment.