github.com/Uhtred009/v2ray-core-1@v4.31.2+incompatible/testing/coverage/coverall2 (about)

     1  #!/bin/bash
     2  
     3  COVERAGE_FILE=${PWD}/coverage.txt
     4  COV_SORTED=${PWD}/coverallsorted.out
     5  
     6  touch "$COVERAGE_FILE"
     7  
     8  function test_package {
     9    DIR=".$1"
    10    DEP=$(go list -f '{{ join .Deps "\n" }}' "$DIR" | grep v2ray | tr '\n' ',')
    11    DEP=${DEP}$DIR
    12    RND_NAME=$(openssl rand -hex 16)
    13    COV_PROFILE=${RND_NAME}.out
    14    go test -coverprofile="$COV_PROFILE" -coverpkg="$DEP" "$DIR" || return
    15  }
    16  
    17  TEST_FILES=(./*_test.go)
    18  if [ -f "${TEST_FILES[0]}" ]; then
    19    test_package ""
    20  fi
    21  
    22  # shellcheck disable=SC2044
    23  for DIR in $(find ./* -type d ! -path "*.git*" ! -path "*vendor*" ! -path "*external*"); do
    24    TEST_FILES=("$DIR"/*_test.go)
    25    if [ -f "${TEST_FILES[0]}" ]; then
    26      test_package "/$DIR"
    27    fi
    28  done
    29  
    30  # merge out
    31  while IFS= read -r -d '' OUT_FILE
    32  do
    33    echo "Merging file ${OUT_FILE}"
    34    < "${OUT_FILE}" grep -v "mode: set" >> "$COVERAGE_FILE"
    35  done <   <(find ./* -name "*.out" -print0)
    36  
    37  < "$COVERAGE_FILE" sort -t: -k1 | grep -vw "testing" | grep -v ".pb.go" | grep -vw "vendor" | grep -vw "external" > "$COV_SORTED"
    38  echo "mode: set" | cat - "${COV_SORTED}" > "${COVERAGE_FILE}"
    39  
    40  bash <(curl -s https://codecov.io/bash) || echo 'Codecov failed to upload'