test.sh 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. #!/bin/bash
  2. set -o errexit
  3. CDIR=$(cd `dirname "$0"` && pwd)
  4. cd "$CDIR"
  5. ORG_PATH="github.com/cloudflare"
  6. REPO_PATH="${ORG_PATH}/cfssl"
  7. ARCH="$(uname -m)"
  8. export GOPATH="${CDIR}/gopath"
  9. export PATH="${PATH}:${GOPATH}/bin"
  10. eval $(go env)
  11. if [ ! -h gopath/src/${REPO_PATH} ]; then
  12. mkdir -p gopath/src/${ORG_PATH}
  13. ln -s ../../../.. gopath/src/${REPO_PATH} || exit 255
  14. fi
  15. echo "${GOPATH}/src/${REPO_PATH}"
  16. PACKAGES=""
  17. if [ "$#" != 0 ]; then
  18. for pkg in "$@"; do
  19. PACKAGES="$PACKAGES $REPO_PATH/$pkg"
  20. done
  21. else
  22. PACKAGES=$(go list ./... | grep -v /vendor/ | grep ^_)
  23. # Escape current cirectory
  24. CDIR_ESC=$(printf "%q" "$CDIR/")
  25. # Remove current directory from the package path
  26. PACKAGES=${PACKAGES//$CDIR_ESC/}
  27. # Remove underscores
  28. PACKAGES=${PACKAGES//_/}
  29. # split PACKAGES into an array and prepend REPO_PATH to each local package
  30. split=(${PACKAGES// / })
  31. PACKAGES=${split[@]/#/${REPO_PATH}/}
  32. fi
  33. # Build and install cfssl executable in PATH
  34. go install -tags "$BUILD_TAGS" ${REPO_PATH}/cmd/cfssl
  35. COVPROFILES=""
  36. for package in $(go list -f '{{if len .TestGoFiles}}{{.ImportPath}}{{end}}' $PACKAGES)
  37. do
  38. if echo $package | grep -q "/scan/crypto"; then
  39. echo "skipped $package"
  40. continue
  41. fi
  42. profile="$GOPATH/src/$package/.coverprofile"
  43. if [ $ARCH = 'x86_64' ]; then
  44. go test -race -tags "$BUILD_TAGS" --coverprofile=$profile $package
  45. else
  46. go test -tags "$BUILD_TAGS" --coverprofile=$profile $package
  47. fi
  48. [ -s $profile ] && COVPROFILES="$COVPROFILES $profile"
  49. done
  50. cat $COVPROFILES > coverprofile.txt
  51. if ! command -v fgt > /dev/null ; then
  52. go get github.com/GeertJohan/fgt
  53. fi
  54. if ! command -v golint > /dev/null ; then
  55. go get golang.org/x/lint/golint
  56. fi
  57. for package in $PACKAGES
  58. do
  59. if echo $package | grep -q "/scan/crypto"; then
  60. continue
  61. fi
  62. echo "fgt golint ${package}"
  63. fgt golint "${package}"
  64. done