gonum.org/v1/gonum@v0.14.0/.github/workflows/script.d/test-coverage.sh (about)

     1  #!/bin/bash
     2  
     3  MODE=set
     4  PROFILE_OUT="${PWD}/profile.out"
     5  ACC_OUT="${PWD}/coverage.txt"
     6  
     7  testCover() {
     8      # set the return value to 0 (successful)
     9      retval=0
    10      # get the directory to check from the parameter. Default to '.'
    11      d=${1:-.}
    12      # skip if there are no Go files here
    13      ls $d/*.go &> /dev/null || return $retval
    14      # switch to the directory to check
    15      pushd $d > /dev/null
    16      # create the coverage profile
    17      coverageresult=$(go test $TAGS -coverprofile="${PROFILE_OUT}" -covermode=${MODE})
    18      # output the result so we can check the shell output
    19      echo ${coverageresult}
    20      # append the results to acc.out if coverage didn't fail, else set the retval to 1 (failed)
    21      ( [[ ${coverageresult} == *FAIL* ]] && retval=1 ) || ( [ -f "${PROFILE_OUT}" ] && grep -v "mode: ${MODE}" "${PROFILE_OUT}" >> "${ACC_OUT}" )
    22      # return to our working dir
    23      popd > /dev/null
    24      # return our return value
    25      return $retval
    26  }
    27  
    28  # Init coverage.txt
    29  echo "mode: ${MODE}" > $ACC_OUT
    30  
    31  # Run test coverage on all directories containing go files except testlapack, testblas, testgraph and testrand.
    32  find . -type d -not -path '*testlapack*' -and -not -path '*testblas*' -and -not -path '*testgraph*' -and -not -path '*testrand*' | while read d; do testCover $d || exit; done