This function is assumed to be run from the root of a Go lang project. It calculates the sha1 value of the project's directory tree every 10 seconds. If the value of the command has changed then go test ./...
is executed causing all the tests in the project to be run.
function goct() {
local project_hash=-1
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 ./...
echo
fi
sleep 10
done
}
$ goct
Change detected - executing tests...
ok github.com/docker-exec/dexec 0.006s
ok github.com/docker-exec/dexec/cli 0.032s
ok github.com/docker-exec/dexec/docker 0.006s
ok github.com/docker-exec/dexec/util 0.005s