Thursday, February 23, 2017

Run tests in background with golang

With the new "gogland" IDE there is no support(yet) for running tests on each save.

However, if you run ubuntu, you could use the following script to continously run the tests in the background and get notified when you a) break the tests b) fix the tests.

#!/bin/bash
failing=0
while :
do
go test > /dev/null
if [ "$?" = "1" ]; then
if [ "$failing" = "1" ]; then
echo "Continuing failure!"
else
failing=1
echo "tests failed"
notify-send "go tests failed" -t 1500
fi
go test
else
if [ "$failing" = "1" ]; then
notify-send "go tests fixed" -t 1500
echo "Tests fixed."
fi
failing=0
fi
sleep 1
done
download the script:
wget https://gist.githubusercontent.com/nilsmagnus/8d5a431f19760ddcaa5d8c12d22b13f9/raw/c16fba1f9be83c395a3e4e493c72df8c715fe896/continous_gotest_notify.sh 
execute the script:
sh continous_gotest_notify.sh