github.com/verrazzano/verrazzano@v1.7.0/build/coverage.sh (about) 1 #!/bin/bash 2 # 3 # Copyright (c) 2020, 2022, Oracle and/or its affiliates. 4 # Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl. 5 # 6 # Code coverage generation 7 TEST_PATHS=${TEST_PATHS:-./...} 8 # Coverage exclusions regex 9 COVERAGE_EXCLUSIONS=${COVERAGE_EXCLUSIONS:-/tests/e2e} 10 11 go test -coverprofile ./coverage.raw.cov $(go list ${TEST_PATHS} | grep -Ev "(${COVERAGE_EXCLUSIONS})") 12 TEST_STATUS=$? 13 14 # Remove specific files from coverage report 15 cat ./coverage.raw.cov |\ 16 grep -v "zz_generated.deepcopy" |\ 17 grep -v "mocks" |\ 18 grep -v "e2e" |\ 19 grep -v "generated_assets" > coverage.cov 20 21 # Display the global code coverage. This generates the total number the badge uses 22 go tool cover -func=coverage.cov 23 24 # If needed, generate HTML report 25 if [ "$1" == "html" ]; then 26 go tool cover -html=coverage.cov -o coverage.html 27 GOCOV=$(command -v gocov) 28 if [ $? -eq 0 ] ; then 29 GOCOV_XML=$(command -v gocov-xml) 30 if [ $? -eq 0 ] ; then 31 $GOCOV convert coverage.cov | $GOCOV_XML > coverage.xml 32 fi 33 fi 34 fi 35 36 exit $TEST_STATUS