github.com/xraypb/xray-core@v1.6.6/testing/coverage/coverall (about) 1 #!/bin/bash 2 3 FAIL=0 4 5 XRAY_OUT=${PWD}/out/xray 6 export XRAY_COV=${XRAY_OUT}/cov 7 COVERAGE_FILE=${XRAY_COV}/coverage.txt 8 9 function test_package { 10 DIR=".$1" 11 DEP=$(go list -f '{{ join .Deps "\n" }}' $DIR | grep xray | tr '\n' ',') 12 DEP=${DEP}$DIR 13 RND_NAME=$(openssl rand -hex 16) 14 COV_PROFILE=${XRAY_COV}/${RND_NAME}.out 15 go test -tags "json coverage" -coverprofile=${COV_PROFILE} -coverpkg=$DEP $DIR || FAIL=1 16 } 17 18 rm -rf ${XRAY_OUT} 19 mkdir -p ${XRAY_COV} 20 touch ${COVERAGE_FILE} 21 22 TEST_FILES=(./*_test.go) 23 if [ -f ${TEST_FILES[0]} ]; then 24 test_package "" 25 fi 26 27 for DIR in $(find * -type d ! -path "*.git*" ! -path "*vendor*" ! -path "*external*"); do 28 TEST_FILES=($DIR/*_test.go) 29 if [ -f ${TEST_FILES[0]} ]; then 30 test_package "/$DIR" 31 fi 32 done 33 34 for OUT_FILE in $(find ${XRAY_COV} -name "*.out"); do 35 echo "Merging file ${OUT_FILE}" 36 cat ${OUT_FILE} | grep -v "mode: set" >> ${COVERAGE_FILE} 37 done 38 39 COV_SORTED=${XRAY_COV}/coverallsorted.out 40 cat ${COVERAGE_FILE} | sort -t: -k1 | grep -vw "testing" | grep -v ".pb.go" | grep -vw "vendor" | grep -vw "external" > ${COV_SORTED} 41 echo "mode: set" | cat - ${COV_SORTED} > ${COVERAGE_FILE} 42 43 if [ "$FAIL" -eq 0 ]; then 44 echo "Uploading coverage datea to codecov." 45 #bash <(curl -s https://codecov.io/bash) -f ${COVERAGE_FILE} -v || echo "Codecov did not collect coverage reports." 46 fi 47 48 exit $FAIL