test.sh 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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. export GOPATH="${CDIR}/gopath"
  8. export PATH="${PATH}:${GOPATH}/bin"
  9. eval $(go env)
  10. if [ ! -h gopath/src/${REPO_PATH} ]; then
  11. mkdir -p gopath/src/${ORG_PATH}
  12. ln -s ../../../.. gopath/src/${REPO_PATH} || exit 255
  13. fi
  14. ls "${GOPATH}/src/${REPO_PATH}"
  15. PACKAGES=""
  16. if [ "$#" != 0 ]; then
  17. for pkg in "$@"; do
  18. PACKAGES="$PACKAGES $REPO_PATH/$pkg"
  19. done
  20. else
  21. PACKAGES=$(go list ./... | grep -v /vendor/ | grep ^_)
  22. # Escape current cirectory
  23. CDIR_ESC=$(printf "%q" "$CDIR/")
  24. # Remove current directory from the package path
  25. PACKAGES=${PACKAGES//$CDIR_ESC/}
  26. # Remove underscores
  27. PACKAGES=${PACKAGES//_/}
  28. # split PACKAGES into an array and prepend REPO_PATH to each local package
  29. split=(${PACKAGES// / })
  30. PACKAGES=${split[@]/#/${REPO_PATH}/}
  31. fi
  32. # Build and install cfssl executable in PATH
  33. go install -tags "$BUILD_TAGS" ${REPO_PATH}/cmd/cfssl
  34. COVPROFILES=""
  35. for package in $(go list -f '{{if len .TestGoFiles}}{{.ImportPath}}{{end}}' $PACKAGES)
  36. do
  37. profile="$GOPATH/src/$package/.coverprofile"
  38. go test -race -tags "$BUILD_TAGS" --coverprofile=$profile $package
  39. [ -s $profile ] && COVPROFILES="$COVPROFILES $profile"
  40. done
  41. cat $COVPROFILES > coverprofile.txt
  42. go vet $PACKAGES
  43. if ! command -v fgt > /dev/null ; then
  44. go get github.com/GeertJohan/fgt
  45. fi
  46. if ! command -v golint > /dev/null ; then
  47. go get github.com/golang/lint/golint
  48. fi
  49. for package in $PACKAGES
  50. do
  51. fgt golint "${package}"
  52. done
  53. if ! command -v staticcheck > /dev/null ; then
  54. go get -u honnef.co/go/tools/cmd/staticcheck
  55. fi
  56. for package in $PACKAGES
  57. do
  58. fgt staticcheck "${package}"
  59. done
  60. # check go fmt
  61. for package in $PACKAGES
  62. do
  63. echo "gofmt $package"
  64. test -z "$(gofmt -s -l -d $GOPATH/src/$package/ | tee /dev/stderr)"
  65. done