2020-12-02 08:57:31 -05:00
|
|
|
#!/usr/bin/env bash
|
2020-06-19 15:07:58 -04:00
|
|
|
|
|
|
|
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 v2ray | 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
|
|
|
|
|
2020-12-02 08:57:31 -05:00
|
|
|
for DIR in $(find ./* -type d ! -path "*.git*"); do
|
2020-06-19 15:07:58 -04:00
|
|
|
TEST_FILES=("$DIR"/*_test.go)
|
|
|
|
if [ -f "${TEST_FILES[0]}" ]; then
|
|
|
|
test_package "/$DIR"
|
|
|
|
fi
|
2020-06-20 04:09:42 -04:00
|
|
|
done
|
2020-06-19 15:07:58 -04:00
|
|
|
|
|
|
|
# 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)
|
|
|
|
|
2020-12-02 08:57:31 -05:00
|
|
|
< "$COVERAGE_FILE" sort -t: -k1 | grep -vw "testing" | grep -v ".pb.go" > "$COV_SORTED"
|
2020-06-19 15:07:58 -04:00
|
|
|
echo "mode: set" | cat - "${COV_SORTED}" > "${COVERAGE_FILE}"
|
|
|
|
|
2020-12-02 08:57:31 -05:00
|
|
|
bash <(curl -s https://codecov.io/bash) || echo 'Codecov failed to upload'
|