Skip to content

Instantly share code, notes, and snippets.

@xiaods
Created July 18, 2017 16:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save xiaods/003e51d8558ef197c96029f5b546b9f0 to your computer and use it in GitHub Desktop.
Save xiaods/003e51d8558ef197c96029f5b546b9f0 to your computer and use it in GitHub Desktop.
go lang continuous test shell function

Go lang continuous test shell function

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.

Shell function

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
}

Usage

$ 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment