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 @@ -9,6 +9,7 @@
- Project config file `.bashunitrc` (`KEY=value` lines); precedence is CLI flag > env var / `.env` > `.bashunitrc` > default; honors `--skip-env-file` (#681)

### Fixed
- `bashunit watch` now forwards `--filter` (and other flags) to each run regardless of position, and no longer mangles forwarded arguments (#682)
- `bashunit learn` and coverage now create temp directories via `mktemp -d` (no predictable PID-based paths under `/tmp`)
- `bashunit::parallel::cleanup` refuses to `rm -rf` a `TEMP_DIR_PARALLEL_TEST_SUITE` whose path is not under `*/bashunit/parallel/*`, preventing accidental wipes from env overrides

Expand Down
42 changes: 32 additions & 10 deletions src/main.sh
Original file line number Diff line number Diff line change
Expand Up @@ -453,18 +453,40 @@ function bashunit::main::cmd_learn() {
# Subcommand: watch
#############################
function bashunit::main::cmd_watch() {
case "${1:-}" in
-h | --help)
bashunit::console_header::print_watch_help
exit 0
;;
esac
local path=""
local -a extra_args=()

while [ $# -gt 0 ]; do
case "$1" in
-h | --help)
bashunit::console_header::print_watch_help
exit 0
;;
-f | --filter)
# Forward the filter flag and its value to the underlying test run
extra_args[${#extra_args[@]}]="$1"
shift || true
if [ $# -gt 0 ]; then
extra_args[${#extra_args[@]}]="$1"
fi
;;
-*)
extra_args[${#extra_args[@]}]="$1"
;;
*)
if [ -z "$path" ]; then
path="$1"
else
extra_args[${#extra_args[@]}]="$1"
fi
;;
esac
shift || true
done

local path="${1:-.}"
shift || true
local -a extra_args=("$@")
[ -z "$path" ] && path="."

bashunit::watch::run "$path" "${extra_args[@]+\"${extra_args[@]}\"}"
bashunit::watch::run "$path" "${extra_args[@]+"${extra_args[@]}"}"
}

#############################
Expand Down
32 changes: 32 additions & 0 deletions tests/unit/watch_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -90,3 +90,35 @@ function test_wait_for_change_does_nothing_for_unknown_tool() {
assert_not_called inotifywait
assert_not_called fswatch
}

# bashunit::main::cmd_watch — filter passthrough

function test_cmd_watch_forwards_filter_after_path() {
bashunit::mock bashunit::watch::run echo

local output
output=$(bashunit::main::cmd_watch "tests/" "--filter" "my_test")

assert_contains "tests/" "$output"
assert_contains "--filter my_test" "$output"
}

function test_cmd_watch_extracts_path_when_filter_first() {
bashunit::mock bashunit::watch::run echo

local output
output=$(bashunit::main::cmd_watch "--filter" "my_test" "tests/")

assert_contains "tests/" "$output"
assert_contains "--filter my_test" "$output"
}

function test_cmd_watch_defaults_path_to_dot() {
bashunit::mock bashunit::watch::run echo

local output
output=$(bashunit::main::cmd_watch "--filter" "my_test")

assert_contains "." "$output"
assert_contains "--filter my_test" "$output"
}
Loading