test 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. #!/bin/bash -e
  2. #
  3. # Run all tests
  4. # ./test
  5. # ./test -v
  6. #
  7. # Run tests for one package
  8. # PKG=./foo ./test
  9. # PKG=bar ./test
  10. #
  11. # Invoke ./cover for HTML output
  12. COVER=${COVER:-"-cover"}
  13. PROJ="go-systemd"
  14. ORG_PATH="github.com/coreos"
  15. REPO_PATH="${ORG_PATH}/${PROJ}"
  16. # As a convenience, set up a self-contained GOPATH if none set
  17. if [ -z "$GOPATH" ]; then
  18. if [ ! -h gopath/src/${REPO_PATH} ]; then
  19. mkdir -p gopath/src/${ORG_PATH}
  20. ln -s ../../../.. gopath/src/${REPO_PATH} || exit 255
  21. fi
  22. export GOPATH=${PWD}/gopath
  23. go get -u github.com/godbus/dbus
  24. fi
  25. TESTABLE="activation journal login1 machine1 unit"
  26. FORMATTABLE="$TESTABLE sdjournal dbus"
  27. if [ -e "/run/systemd/system/" ]; then
  28. TESTABLE="${TESTABLE} sdjournal"
  29. if [ "$EUID" == "0" ]; then
  30. # testing actual systemd behaviour requires root
  31. TESTABLE="${TESTABLE} dbus"
  32. fi
  33. fi
  34. # user has not provided PKG override
  35. if [ -z "$PKG" ]; then
  36. TEST=$TESTABLE
  37. FMT=$FORMATTABLE
  38. # user has provided PKG override
  39. else
  40. # strip out slashes and dots from PKG=./foo/
  41. TEST=${PKG//\//}
  42. TEST=${TEST//./}
  43. # only run gofmt on packages provided by user
  44. FMT="$TEST"
  45. fi
  46. # split TEST into an array and prepend REPO_PATH to each local package
  47. split=(${TEST// / })
  48. TEST=${split[@]/#/${REPO_PATH}/}
  49. echo "Running tests..."
  50. go test ${COVER} $@ ${TEST}
  51. echo "Checking gofmt..."
  52. fmtRes=$(gofmt -l $FMT)
  53. if [ -n "${fmtRes}" ]; then
  54. echo -e "gofmt checking failed:\n${fmtRes}"
  55. exit 255
  56. fi
  57. echo "Checking govet..."
  58. vetRes=$(go vet $TEST)
  59. if [ -n "${vetRes}" ]; then
  60. echo -e "govet checking failed:\n${vetRes}"
  61. exit 255
  62. fi
  63. echo "Success"