github.com/ryanbennettvoid/go-swagger@v0.18.1-0.20190104015444-3854bbbe2392/hack/test.sh (about)

     1  #!/bin/bash
     2  
     3  # Bails on any command failure
     4  set -e -o pipefail
     5  
     6  cd $(git rev-parse --show-toplevel)
     7  echo "Running tests in $(pwd)..."
     8  
     9  # List of packages to test
    10  # Currently no packaged tests are available in fixtures or examples
    11  packages=$(go list ./... | grep -v -E 'vendor|fixtures|examples')
    12  repo_pref="github.com/${CIRCLE_PROJECT_USERNAME-"$(basename `pwd`)"}/${CIRCLE_PROJECT_REPONAME-"$(basename `pwd`)"}/"
    13  
    14  if [[ ${1} == "--nocover" ]] ; then
    15      # Run simple tests without coverage computations, but with race detector turned on
    16      echo "Running unit tests with race detector"
    17      go test -race -vet off -v ${packages}
    18  else
    19      # Run test coverage on each subdirectories and merge the coverage profile.
    20      echo "Running CI unit tests with coverage calculation"
    21      echo "mode: ${GOCOVMODE-atomic}" > coverage.txt
    22      # Standard go tooling behavior is to ignore dirs with leading underscores
    23      for dir in ${packages} ; do
    24          pth="${GOPATH}/src/${dir}"
    25          # -tags netgo: test as statically linked
    26          # -installsuffix netgo: produce suffixed object for this statically linked build
    27          go test -vet off -tags netgo -installsuffix netgo -covermode=${GOCOVMODE-atomic} -coverprofile=${pth}/profile.tmp $dir
    28          if [[ -f $pth/profile.tmp ]] ; then
    29              cat $pth/profile.tmp | tail -n +2 >> coverage.txt
    30              rm -f $pth/profile.tmp
    31          fi
    32      done
    33      go tool cover -func coverage.txt
    34      # print out coverage report
    35      gocov convert coverage.txt | gocov report
    36      outputdir="/usr/share/coverage"
    37      if [[ ! -d ${outputdir} ]] ; then
    38          mkdir -p ${outputdir}
    39      fi
    40      gocov convert coverage.txt | gocov-html > ${outputdir}/coverage-${CIRCLE_BUILD_NUM-"0"}.html
    41  fi