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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

## [Unreleased](https://github.com/TypedDevs/bashunit/compare/0.14.0...main)

- Fixed `--filter|-f` to work with `test_*` matching function name input.
- Improved `--filter|-f` to match function name with input string irrespective with location to `test` prefix.
- Add assertions to log file
- Improve UX by Removing trailing slashes `/` from the test directories naming output.

Expand Down
4 changes: 2 additions & 2 deletions src/helpers.sh
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,13 @@ function helper::check_duplicate_functions() {
#
function helper::get_functions_to_run() {
local prefix=$1
local filter=$2
local filter=${2/test_/}
local function_names=$3

local filtered_functions=""

for fn in $function_names; do
if [[ $fn == ${prefix}_${filter}* ]]; then
if [[ $fn == ${prefix}_*${filter}* ]]; then
if [[ $filtered_functions == *" $fn"* ]]; then
return 1
fi
Expand Down
3 changes: 2 additions & 1 deletion tests/functional/multi_invoker_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ function test_multi_invoker_whitespace() {

assert_equals "this arg" "$first_arg"

## Iteration (1,2,3) are from invoker_test_numbers & (4,5) are from invoker_test_whitespace
case $current_iteration in
4)
assert_equals "has spaces" "$second_arg"
Expand All @@ -64,7 +65,7 @@ function test_multi_invoker_whitespace() {
assert_equals "$(printf "has\na newline")" "$second_arg"
;;
*)
fail
fail "Unexpected results with inputs: $current_iteration"
;;
esac
}
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 @@ -227,3 +227,14 @@ EOF
assert_equals "0.10.1" "$(helpers::get_latest_tag)"
unset -f git # remove the mock
}

function test_to_run_with_filter_matching_string_in_function_name() {
local functions=("test_my_awesome_function" "test_your_awesome_function" "test_so_lala_function")

assert_equals\
"test_your_awesome_function" "$(helper::get_functions_to_run "test" "test_your_awesome_function" "${functions[*]}")"

assert_equals\
"test_my_awesome_function test_your_awesome_function"\
"$(helper::get_functions_to_run "test" "awesome" "${functions[*]}")"
}