github.com/gonum/matrix@v0.0.0-20181209220409-c518dec07be9/.travis/test-coverage.sh (about) 1 #!/bin/bash 2 3 PROFILE_OUT=$PWD/profile.out 4 ACC_OUT=$PWD/acc.out 5 6 testCover() { 7 # set the return value to 0 (succesful) 8 retval=0 9 # get the directory to check from the parameter. Default to '.' 10 d=${1:-.} 11 # skip if there are no Go files here 12 ls $d/*.go &> /dev/null || return $retval 13 # switch to the directory to check 14 pushd $d > /dev/null 15 # create the coverage profile 16 coverageresult=`go test -v -coverprofile=$PROFILE_OUT` 17 # output the result so we can check the shell output 18 echo ${coverageresult} 19 # append the results to acc.out if coverage didn't fail, else set the retval to 1 (failed) 20 ( [[ ${coverageresult} == *FAIL* ]] && retval=1 ) || ( [ -f $PROFILE_OUT ] && grep -v "mode: set" $PROFILE_OUT >> $ACC_OUT ) 21 # return to our working dir 22 popd > /dev/null 23 # return our return value 24 return $retval 25 } 26 27 # Init acc.out 28 echo "mode: set" > $ACC_OUT 29 30 # Run test coverage on all directories containing go files 31 find . -maxdepth 10 -type d | while read d; do testCover $d || exit; done 32 33 # Upload the coverage profile to coveralls.io 34 [ -n "$COVERALLS_TOKEN" ] && goveralls -coverprofile=$ACC_OUT -service=travis-ci -repotoken $COVERALLS_TOKEN 35