coverall 1015 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. #!/bin/bash
  2. FAIL=0
  3. COVERAGE_FILE=coverage.txt
  4. function test_package {
  5. DIR="github.com/v2ray/v2ray-core/$1"
  6. DEP=$(go list -f '{{ join .Deps "\n" }}' $DIR | grep v2ray | tr '\n' ',')
  7. DEP=${DEP}$DIR
  8. go test -tags json -coverprofile=coversingle.out -coverpkg=$DEP $DIR || FAIL=1
  9. if [ -f coversingle.out ]; then
  10. cat coversingle.out | grep -v "mode: set" >> ${COVERAGE_FILE}
  11. rm coversingle.out
  12. fi
  13. }
  14. touch ${COVERAGE_FILE}
  15. TEST_FILES=(./*_test.go)
  16. if [ -f ${TEST_FILES[0]} ]; then
  17. test_package ""
  18. fi
  19. for DIR in $(find * -type d -not -path "*.git*"); do
  20. TEST_FILES=($DIR/*_test.go)
  21. if [ -f ${TEST_FILES[0]} ]; then
  22. test_package $DIR
  23. fi
  24. done
  25. cat ${COVERAGE_FILE} | sort -t: -k1 | grep -vw "testing" > coverallsorted.out
  26. echo "mode: set" | cat - coverallsorted.out > ${COVERAGE_FILE}
  27. rm coverallsorted.out
  28. if [ "$FAIL" -eq 0 ]; then
  29. bash <(curl -s https://codecov.io/bash) -f ${COVERAGE_FILE} || echo "Codecov did not collect coverage reports."
  30. fi
  31. rm -f ${COVERAGE_FILE}
  32. exit $FAIL