github.com/vnpaycloud-console/gophercloud/v2@v2.0.5/script/coverage (about)

     1  #!/bin/bash
     2  #
     3  # Run unit tests with coverage enabled.
     4  
     5  set -euxo pipefail
     6  
     7  n=1
     8  for testpkg in $(go list ./testing ./.../testing); do
     9    covpkg="${testpkg/"/testing"/}"
    10    go test -covermode count -coverprofile "testing_"$n.coverprofile -coverpkg "$covpkg" "$testpkg" 2>/dev/null
    11    n=$((n+1))
    12  done
    13  
    14  base_pkg=$(go list)
    15  # Look for additional test files
    16  for path in $(find . -path '*/testing' -prune -o -path '*/internal' -prune -o -name '*_test.go' -exec dirname {} \; | uniq); do
    17    pkg="${base_pkg}${path:1}"
    18    go test -covermode count -coverprofile "testing_"$n.coverprofile -coverpkg "$pkg" "$pkg" 2>/dev/null
    19    n=$((n+1))
    20  done
    21  
    22  # shellcheck disable=SC2046
    23  gocovmerge $(ls -- *.coverprofile) > cover.out
    24  rm ./*.coverprofile