test 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. #!/bin/bash -e
  2. #
  3. # Run all tests (not including functional)
  4. # ./test
  5. # ./test -v
  6. #
  7. # Run tests for one package
  8. # PKG=./unit ./test
  9. # PKG=ssh ./test
  10. #
  11. # Invoke ./cover for HTML output
  12. COVER=${COVER:-"-cover"}
  13. source ./build
  14. TESTABLE="cryptoutil flagutil timeutil netutil yamlutil httputil health multierror dlopen"
  15. FORMATTABLE="$TESTABLE capnslog"
  16. # user has not provided PKG override
  17. if [ -z "$PKG" ]; then
  18. TEST=$TESTABLE
  19. FMT=$FORMATTABLE
  20. # user has provided PKG override
  21. else
  22. # strip out slashes and dots from PKG=./foo/
  23. TEST=${PKG//\//}
  24. TEST=${TEST//./}
  25. # only run gofmt on packages provided by user
  26. FMT="$TEST"
  27. fi
  28. # split TEST into an array and prepend repo path to each local package
  29. split=(${TEST// / })
  30. TEST=${split[@]/#/github.com/coreos/pkg/}
  31. echo "Running tests..."
  32. go test ${COVER} $@ ${TEST}
  33. echo "Checking gofmt..."
  34. fmtRes=$(gofmt -l $FMT)
  35. if [ -n "${fmtRes}" ]; then
  36. echo -e "gofmt checking failed:\n${fmtRes}"
  37. exit 255
  38. fi
  39. echo "Checking govet..."
  40. vetRes=$(go vet $TEST)
  41. if [ -n "${vetRes}" ]; then
  42. echo -e "govet checking failed:\n${vetRes}"
  43. exit 255
  44. fi
  45. echo "Success"