This commit is contained in:
RPRX 2020-11-25 19:01:53 +08:00
parent 47d23e9972
commit c7f7c08ead
711 changed files with 82154 additions and 2 deletions

48
testing/coverage/coverall Normal file
View file

@ -0,0 +1,48 @@
#!/bin/bash
FAIL=0
XRAY_OUT=${PWD}/out/xray
export XRAY_COV=${XRAY_OUT}/cov
COVERAGE_FILE=${XRAY_COV}/coverage.txt
function test_package {
DIR=".$1"
DEP=$(go list -f '{{ join .Deps "\n" }}' $DIR | grep xray | tr '\n' ',')
DEP=${DEP}$DIR
RND_NAME=$(openssl rand -hex 16)
COV_PROFILE=${XRAY_COV}/${RND_NAME}.out
go test -tags "json coverage" -coverprofile=${COV_PROFILE} -coverpkg=$DEP $DIR || FAIL=1
}
rm -rf ${XRAY_OUT}
mkdir -p ${XRAY_COV}
touch ${COVERAGE_FILE}
TEST_FILES=(./*_test.go)
if [ -f ${TEST_FILES[0]} ]; then
test_package ""
fi
for DIR in $(find * -type d ! -path "*.git*" ! -path "*vendor*" ! -path "*external*"); do
TEST_FILES=($DIR/*_test.go)
if [ -f ${TEST_FILES[0]} ]; then
test_package "/$DIR"
fi
done
for OUT_FILE in $(find ${XRAY_COV} -name "*.out"); do
echo "Merging file ${OUT_FILE}"
cat ${OUT_FILE} | grep -v "mode: set" >> ${COVERAGE_FILE}
done
COV_SORTED=${XRAY_COV}/coverallsorted.out
cat ${COVERAGE_FILE} | sort -t: -k1 | grep -vw "testing" | grep -v ".pb.go" | grep -vw "vendor" | grep -vw "external" > ${COV_SORTED}
echo "mode: set" | cat - ${COV_SORTED} > ${COVERAGE_FILE}
if [ "$FAIL" -eq 0 ]; then
echo "Uploading coverage datea to codecov."
#bash <(curl -s https://codecov.io/bash) -f ${COVERAGE_FILE} -v || echo "Codecov did not collect coverage reports."
fi
exit $FAIL

View file

@ -0,0 +1,40 @@
#!/bin/bash
COVERAGE_FILE=${PWD}/coverage.txt
COV_SORTED=${PWD}/coverallsorted.out
touch "$COVERAGE_FILE"
function test_package {
DIR=".$1"
DEP=$(go list -f '{{ join .Deps "\n" }}' "$DIR" | grep xray | tr '\n' ',')
DEP=${DEP}$DIR
RND_NAME=$(openssl rand -hex 16)
COV_PROFILE=${RND_NAME}.out
go test -coverprofile="$COV_PROFILE" -coverpkg="$DEP" "$DIR" || return
}
TEST_FILES=(./*_test.go)
if [ -f "${TEST_FILES[0]}" ]; then
test_package ""
fi
# shellcheck disable=SC2044
for DIR in $(find ./* -type d ! -path "*.git*" ! -path "*vendor*" ! -path "*external*"); do
TEST_FILES=("$DIR"/*_test.go)
if [ -f "${TEST_FILES[0]}" ]; then
test_package "/$DIR"
fi
done
# merge out
while IFS= read -r -d '' OUT_FILE
do
echo "Merging file ${OUT_FILE}"
< "${OUT_FILE}" grep -v "mode: set" >> "$COVERAGE_FILE"
done < <(find ./* -name "*.out" -print0)
< "$COVERAGE_FILE" sort -t: -k1 | grep -vw "testing" | grep -v ".pb.go" | grep -vw "vendor" | grep -vw "external" > "$COV_SORTED"
echo "mode: set" | cat - "${COV_SORTED}" > "${COVERAGE_FILE}"
bash <(curl -s https://codecov.io/bash) || echo 'Codecov failed to upload'