This is surely a missing piece of my current Go IDE (LIteIDE), but I found and adapted this little shell function to test an entire Go tree whenever I make a change:
function goct() {
local project_hash=-1
local sleeptime=10
while true; do
local new_project_hash="$(find . -type f -print0 | sort -z | xargs -0 shasum | shasum)"
if [ "${new_project_hash}" != "${project_hash}" ]; then
project_hash="${new_project_hash}"
echo "Change detected - executing tests..."
go test ./...
if [ $? -ne 0 ]; then
echo "FAILED"
# May take some fime to fix, so back off.
sleeptime=120
osascript -e 'display notification "Go Test Failed" with title "Go Failure" sound name "Submarine"'
else
sleeptime=10
fi
echo
fi
sleep $sleeptime
done
}
Note: The notification thingy is OS X – so for Linux change or remove that.