Open
Conversation
Adds `bashunit watch [path] [options]` — a new subcommand that watches .sh files for changes and automatically re-runs tests, enabling a fast TDD feedback loop without manual re-runs. Implementation: - src/watch.sh: core watch loop using inotifywait (Linux) or fswatch (macOS) - src/main.sh: cmd_watch() subcommand handler - bashunit: source watch.sh, register 'watch' in subcommand detection and router - src/console_header.sh: help text for 'watch', added to main help listing Features: - Runs tests immediately on start, then watches for changes - Supports inotifywait (Linux/inotify-tools) and fswatch (macOS) - Forwards all standard 'bashunit test' options (--filter, --simple, etc.) - Clear error message with install instructions when watcher tool is missing - Watches only .sh files to avoid spurious re-runs Usage: bashunit watch # watch current directory bashunit watch tests/ # watch specific path bashunit watch tests/ --filter user # watch + filter bashunit watch tests/ --simple # watch with simple output
Tests cover: - bashunit::watch::is_available: inotifywait, fswatch, and no-tool cases - bashunit::watch::run: error exit, error message content, install hints - bashunit::watch::wait_for_change: correct tool dispatch for linux/macos/unknown Uses mocks and spies to avoid requiring inotifywait or fswatch on CI.
…, update help snapshots
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds
bashunit watch [path] [options]— a new subcommand that watches.shfiles for changes and automatically re-runs tests on save, enabling a fast TDD feedback loop without manual re-runs.This was a frequently missing feature compared to test runners in other ecosystems (Jest
--watch, PHPUnit with file watchers, etc.).How it works
.shfile changesImplementation
src/watch.sh— core watch loop, supports bothinotifywait(Linux) andfswatch(macOS)src/main.sh—cmd_watch()subcommand handler, forwards extra args tobashunit testbashunit— sourceswatch.sh, registerswatchin subcommand detection and routersrc/console_header.sh— help text forwatch --help, listed in main--helpUsage
Requirements
inotifywaitsudo apt install inotify-toolsfswatchbrew install fswatchWhen neither tool is present, a clear error message with install instructions is shown.
Testing
All 603 existing unit tests pass with no changes (
bashunit tests/unit/ --simple).Manual testing:
bashunit watch --helpoutputbashunit --helplists the new command.shfile save (Linux withinotifywait)