Last active
February 6, 2018 13:00
-
-
Save tmichel/6ebfbc86046438dd052044f89b599424 to your computer and use it in GitHub Desktop.
Watch file changes and run go test (OSX)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/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