Skip to content

Instantly share code, notes, and snippets.

@tmichel
Last active February 6, 2018 13:00
Show Gist options
  • Select an option

  • Save tmichel/6ebfbc86046438dd052044f89b599424 to your computer and use it in GitHub Desktop.

Select an option

Save tmichel/6ebfbc86046438dd052044f89b599424 to your computer and use it in GitHub Desktop.
Watch file changes and run go test (OSX)
#!/bin/bash
echo "Watching for changes..."
red() {
str="$1"
sed "/[[:<:]]$str/s//$(printf "\033[31m$str\033[0m")/"
}
green() {
str="$1"
sed "/[[:<:]]$str/s//$(printf "\033[32m$str\033[0m")/"
}
fswatch -e '\.git' . | while read file
do
if ! echo $file | grep -q '\.go$'; then
continue
fi
package="$(dirname "${file##$GOPATH/src/}")"
cmd="go test -short $@ $package"
echo -n "..."
date
echo "...Changed: ${file##$PWD/}"
echo "...Running: $cmd"
output=$($cmd 2>&1)
if [[ $? == 0 ]]; then
message="PASS"
else
message="FAIL"
fi
echo "$output" | green "ok" | red "FAIL" | red "FATAL"
terminal-notifier -message "$message $package" -title "Test results"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment