github.com/turingchain2020/turingchain@v1.1.21/build/tools/coverage.sh (about) 1 #!/bin/bash 2 # 3 # Code coverage generation 4 set -e -o pipefail 5 6 COVERAGE_DIR="${COVERAGE_DIR:-build/coverage}" 7 PKG_LIST=$(go list ./... | grep -v "vendor" | grep -v "mock" | grep -v "mocks" \ 8 | grep -v "cmd" | grep -v "types" | grep -v "nat" | grep -v "pbft") 9 10 # Create the coverage files directory 11 mkdir -p "$COVERAGE_DIR" 12 13 # Create a coverage file for each package 14 for package in ${PKG_LIST}; do 15 go test -covermode=count -coverprofile "${COVERAGE_DIR}/${package##*/}.cov" "$package" 16 done 17 18 # Merge the coverage profile files 19 echo 'mode: count' >./coverage.cov 20 tail -q -n +2 "${COVERAGE_DIR}"/*.cov >>./coverage.cov 21 22 # Display the global code coverage 23 go tool cover -func=./coverage.cov 24 25 # If needed, generate HTML report 26 if [ "$1" == "html" ]; then 27 go tool cover -html=./coverage.cov -o coverage.html 28 fi 29 30 # Remove the coverage files directory 31 rm -rf "$COVERAGE_DIR"