Skip to content

Commit df84a6b

Browse files
committed
Make test-php-watch cross-platform compatible via fswatch
1 parent 85001b9 commit df84a6b

File tree

1 file changed

+21
-5
lines changed

1 file changed

+21
-5
lines changed

bin/test-php-watch.sh

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,29 @@
11
#!/bin/bash
2-
if ! which inotifywait >/dev/null 2>&1; then
3-
echo "Error: the inotifywait command is not available. Make sure you have inotify-tools installed."
4-
exit 1
2+
3+
# Check for the fswatch command
4+
if ! which fswatch >/dev/null 2>&1; then
5+
echo "Error: The fswatch command is not available."
6+
echo "On macOS, you can install it with Homebrew: brew install fswatch"
7+
exit 1
58
fi
69

10+
cd "$(git rev-parse --show-toplevel)"
11+
712
while true; do
813
echo "Waiting for a change in the plugins directory..."
9-
output=$(inotifywait -e modify,create,delete -r ./plugins --include '.*(\.php$|/tests/.*)' 2> /dev/null)
10-
plugin_slug=$(echo "$output" | awk -F/ '{print $3}')
14+
15+
file=$(fswatch -1 -r \
16+
--event Created \
17+
--event Updated \
18+
--event Removed \
19+
--include '\.php$' \
20+
--include '/tests/' \
21+
./plugins 2>/dev/null | head -n 1)
22+
23+
# Make the file path relative.
24+
file="${file#"$PWD/"}"
25+
26+
plugin_slug=$(echo "$file" | awk -F/ '{print $2}')
1127
sleep 1 # Give the user a chance to copy text from terminal before IDE auto-saves.
1228
clear
1329
echo "Running phpunit tests for $(tput bold)$plugin_slug$(tput sgr0):"

0 commit comments

Comments
 (0)