Skip to content

Instantly share code, notes, and snippets.

@grodowski
Created January 31, 2017 14:11
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 grodowski/d9d2d3cd2f45356d3405d05444b03f7a to your computer and use it in GitHub Desktop.
Save grodowski/d9d2d3cd2f45356d3405d05444b03f7a to your computer and use it in GitHub Desktop.
Golang - recursive tests + coverage
#!/bin/bash
shopt -s globstar
rootdir=`pwd`
for dir in **/ ; do
cd $dir
exec 5>&1
out=$(go test -v -coverprofile=cov_part.out | tee >(cat - >&5))
if [ $? -eq 1 ] ; then
if [ $(cat $out | grep -o 'no buildable Go source files') == "" ] ; then
echo "Tests failed! Exiting..." ; exit 1
fi
fi
cd $rootdir
done
if [ -z "$CI_NAME" ]; then
echo "CI_NAME is unset. Skipping coverage report!"
exit 0
fi
find . -name cov_part.out | xargs cat > cov.out
# make sure we do not run the ruby gem which is first in $PATH :(
node /usr/local/lib/node_modules/codeclimate-test-reporter/bin/codeclimate.js < cov.out
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment