diff --git a/.gitignore b/.gitignore index 2e51d654..f75ddbea 100644 --- a/.gitignore +++ b/.gitignore @@ -8,3 +8,5 @@ count.out /parts /prime /stage +vendor/ +.idea/ diff --git a/.travis.yml b/.travis.yml index 040e914b..399fdda4 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,7 +3,6 @@ sudo: required dist: trusty go_import_path: gobot.io/x/gobot go: - - 1.7.6 - 1.8.5 - 1.9.2 - tip @@ -43,18 +42,19 @@ before_install: - sudo ln /dev/null /dev/raw1394 - cd $HOME/gopath/src/gobot.io/x/gobot - go get github.com/axw/gocov/gocov + - go get -u github.com/golang/dep/cmd/dep before_cache: - - rm -f $HOME/fresh-cache + - rm -f $HOME/fresh-cache install: - - make deps + - dep ensure before_script: - export DISPLAY=:99.0 - sh -e /etc/init.d/xvfb start script: - - export CGO_CPPFLAGS="-I${HOME}/usr/include" - - export CGO_LDFLAGS="-L${HOME}/usr/lib -lopencv_core -lopencv_videoio -lopencv_imgproc -lopencv_highgui -lopencv_imgcodecs -lopencv_objdetect -lopencv_calib3d -lopencv_video" - - echo "Ensuring code is well formatted"; ! gofmt -s -d . | read - - bash -c 'set -e; echo "" > coverage.txt; for d in $(go list ./...); do go test -covermode=set -coverprofile=p.out $d; if [ -f p.out ]; then cat p.out >> coverage.txt; rm p.out; fi; done' + - echo "Running tests" + - make test_with_coverage + - echo "Checking that code is well-formatted" + - make fmt_check after_success: - bash <(curl -s https://codecov.io/bash) branches: diff --git a/Gopkg.lock b/Gopkg.lock new file mode 100644 index 00000000..54eb8cee --- /dev/null +++ b/Gopkg.lock @@ -0,0 +1,171 @@ +# This file is autogenerated, do not edit; changes may be undone by the next 'dep ensure'. + + +[[projects]] + branch = "master" + name = "github.com/bmizerany/pat" + packages = ["."] + revision = "6226ea591a40176dd3ff9cd8eff81ed6ca721a00" + +[[projects]] + name = "github.com/codegangsta/cli" + packages = ["."] + revision = "cfb38830724cc34fedffe9a2a29fb54fa9169cd1" + version = "v1.20.0" + +[[projects]] + branch = "master" + name = "github.com/creack/goselect" + packages = ["."] + revision = "1bd5ca702c6154bccc56ecd598932ee8b295cab2" + +[[projects]] + branch = "master" + name = "github.com/donovanhide/eventsource" + packages = ["."] + revision = "3ed64d21fb0b6bd8b49bcfec08f3004daee8723d" + +[[projects]] + name = "github.com/eclipse/paho.mqtt.golang" + packages = [".","packets"] + revision = "aff15770515e3c57fc6109da73d42b0d46f7f483" + version = "v1.1.0" + +[[projects]] + branch = "master" + name = "github.com/go-ble/ble" + packages = [".","darwin","linux","linux/adv","linux/att","linux/gatt","linux/hci","linux/hci/cmd","linux/hci/evt","linux/hci/socket"] + revision = "788214691384e85e345bff9fd5eeb046f5983594" + +[[projects]] + branch = "master" + name = "github.com/hashicorp/errwrap" + packages = ["."] + revision = "7554cd9344cec97297fa6649b055a8c98c2a1e55" + +[[projects]] + branch = "master" + name = "github.com/hashicorp/go-multierror" + packages = ["."] + revision = "83588e72410abfbe4df460eeb6f30841ae47d4c4" + +[[projects]] + branch = "master" + name = "github.com/hybridgroup/go-ardrone" + packages = ["client","client/commands","client/navdata"] + revision = "b9750d8d7b78f9638e5fdd899835e99d46b5a56c" + +[[projects]] + name = "github.com/mattn/go-colorable" + packages = ["."] + revision = "167de6bfdfba052fa6b2d3664c8f5272e23c9072" + version = "v0.0.9" + +[[projects]] + name = "github.com/mattn/go-isatty" + packages = ["."] + revision = "0360b2af4f38e8d38c7fce2a9f4e702702d73a39" + version = "v0.0.3" + +[[projects]] + branch = "master" + name = "github.com/mgutz/ansi" + packages = ["."] + revision = "9520e82c474b0a04dd04f8a40959027271bab992" + +[[projects]] + name = "github.com/mgutz/logxi" + packages = ["v1"] + revision = "aebf8a7d67ab4625e0fd4a665766fef9a709161b" + version = "v1" + +[[projects]] + name = "github.com/nats-io/go-nats" + packages = ["encoders/builtin","util"] + revision = "29f9728a183bf3fa7e809e14edac00b33be72088" + version = "v1.3.0" + +[[projects]] + name = "github.com/nats-io/nats" + packages = ["."] + revision = "29f9728a183bf3fa7e809e14edac00b33be72088" + version = "v1.3.0" + +[[projects]] + name = "github.com/nats-io/nuid" + packages = ["."] + revision = "289cccf02c178dc782430d534e3c1f5b72af807f" + version = "v1.0.0" + +[[projects]] + name = "github.com/pkg/errors" + packages = ["."] + revision = "645ef00459ed84a119197bfb8d8205042c6df63d" + version = "v0.8.0" + +[[projects]] + branch = "master" + name = "github.com/raff/goble" + packages = ["xpc"] + revision = "b12b34f940c4cf4363660073539b5fa9fd96bd16" + +[[projects]] + branch = "master" + name = "github.com/sigurn/crc8" + packages = ["."] + revision = "e55481d6f45c5a8f040343bace9013571dae103e" + +[[projects]] + branch = "master" + name = "github.com/sigurn/utils" + packages = ["."] + revision = "f19e41f79f8f006116f682c1af454591bc278ad4" + +[[projects]] + branch = "master" + name = "github.com/tarm/serial" + packages = ["."] + revision = "794054cb266296569307c08d1b475f44505dfab1" + +[[projects]] + name = "github.com/veandco/go-sdl2" + packages = ["sdl"] + revision = "30f30965227962032c13bd0b12a89e6a5107c768" + version = "v0.2" + +[[projects]] + branch = "master" + name = "go.bug.st/serial.v1" + packages = [".","unixutils"] + revision = "eae1344f9f90101f887b08d13391c34399f97873" + +[[projects]] + name = "gocv.io/x/gocv" + packages = ["."] + revision = "db20428799339d78526356473b0f5f00dccf075b" + version = "v0.3.1" + +[[projects]] + branch = "master" + name = "golang.org/x/exp" + packages = ["io/spi","io/spi/driver"] + revision = "be09b602c40b1028d91bf805b38a6f54741fc34d" + +[[projects]] + branch = "master" + name = "golang.org/x/net" + packages = ["proxy","websocket"] + revision = "01c190206fbdffa42f334f4b2bf2220f50e64920" + +[[projects]] + branch = "master" + name = "golang.org/x/sys" + packages = ["unix","windows"] + revision = "8eb05f94d449fdf134ec24630ce69ada5b469c1c" + +[solve-meta] + analyzer-name = "dep" + analyzer-version = 1 + inputs-digest = "0a749d34ff067c74d2473ddacb9a8e0036294d5fcb64e656bd5c552b983b3c72" + solver-name = "gps-cdcl" + solver-version = 1 diff --git a/Gopkg.toml b/Gopkg.toml new file mode 100644 index 00000000..d124d0c8 --- /dev/null +++ b/Gopkg.toml @@ -0,0 +1,86 @@ + +# Gopkg.toml example +# +# Refer to https://github.com/golang/dep/blob/master/docs/Gopkg.toml.md +# for detailed Gopkg.toml documentation. +# +# required = ["github.com/user/thing/cmd/thing"] +# ignored = ["github.com/user/project/pkgX", "bitbucket.org/user/project/pkgA/pkgY"] +# +# [[constraint]] +# name = "github.com/user/project" +# version = "1.0.0" +# +# [[constraint]] +# name = "github.com/user/project2" +# branch = "dev" +# source = "github.com/myfork/project2" +# +# [[override]] +# name = "github.com/x/y" +# version = "2.4.0" + + +[[constraint]] + branch = "master" + name = "github.com/bmizerany/pat" + +[[constraint]] + name = "github.com/codegangsta/cli" + version = "1.20.0" + +[[constraint]] + branch = "master" + name = "github.com/donovanhide/eventsource" + +[[constraint]] + name = "github.com/eclipse/paho.mqtt.golang" + version = "1.1.0" + +[[constraint]] + branch = "master" + name = "github.com/go-ble/ble" + +[[constraint]] + branch = "master" + name = "github.com/hashicorp/go-multierror" + +[[constraint]] + branch = "master" + name = "github.com/hybridgroup/go-ardrone" + +[[constraint]] + name = "github.com/nats-io/nats" + version = "1.3.0" + +[[constraint]] + name = "github.com/pkg/errors" + version = "0.8.0" + +[[constraint]] + branch = "master" + name = "github.com/sigurn/crc8" + +[[constraint]] + branch = "master" + name = "github.com/tarm/serial" + +[[constraint]] + name = "github.com/veandco/go-sdl2" + version = "0.2.0" + +[[constraint]] + branch = "master" + name = "go.bug.st/serial.v1" + +[[constraint]] + name = "gocv.io/x/gocv" + version = "0.3.1" + +[[constraint]] + branch = "master" + name = "golang.org/x/exp" + +[[constraint]] + branch = "master" + name = "golang.org/x/net" diff --git a/Makefile b/Makefile index a0753118..581a6450 100644 --- a/Makefile +++ b/Makefile @@ -1,20 +1,29 @@ -.PHONY: test race cover robeaux examples deps +.PHONY: test race cover robeaux examples deps test_with_coverage fmt_check +excluding_vendor := $(shell go list ./... | grep -v /vendor/) + +# Run tests on all non-vendor directories test: - go test ./... + go test -v $(excluding_vendor) +# Run tests with race detection on all non-vendor directories race: - go test ./... -race + go test -race $(excluding_vendor) + +# Check for code well-formedness +fmt_check: + ./ci/format.sh + +# Test and generate coverage +test_with_coverage: + ./ci/test.sh + +deps: +ifeq (,$(shell which dep)) + $(error dep tool not found! https://github.com/golang/dep is required to install Gobot deps) +endif + dep ensure -cover: - echo "" > profile.cov - for package in $$(go list ./...) ; do \ - go test -covermode=count -coverprofile=tmp.cov $$package ; \ - if [ -f tmp.cov ]; then \ - cat tmp.cov >> profile.cov ; \ - rm tmp.cov ; \ - fi ; \ - done robeaux: ifeq (,$(shell which go-bindata)) @@ -40,22 +49,3 @@ examples: for example in $(EXAMPLES) ; do \ go build -o /tmp/$$example examples/$$example ; \ done ; \ - -deps: - go get -d -v \ - github.com/bmizerany/pat \ - github.com/codegangsta/cli \ - github.com/go-ble/ble \ - github.com/donovanhide/eventsource \ - github.com/eclipse/paho.mqtt.golang \ - github.com/hashicorp/go-multierror \ - github.com/hybridgroup/go-ardrone/client \ - gocv.io/x/gocv \ - github.com/mgutz/logxi/v1 \ - github.com/nats-io/nats \ - github.com/sigurn/crc8 \ - go.bug.st/serial.v1 \ - github.com/veandco/go-sdl2/sdl \ - golang.org/x/net/websocket \ - golang.org/x/exp/io/spi \ - golang.org/x/sys/unix diff --git a/ci/format.sh b/ci/format.sh new file mode 100755 index 00000000..5fc93243 --- /dev/null +++ b/ci/format.sh @@ -0,0 +1,19 @@ +#!/bin/bash + +## Only uncomment the below for debugging +#set -euxo pipefail + +pushd $PWD/.. + GO_FILES_EXCLUDING_VENDOR=$(find . -type f -name '*.go' -not -path "./vendor/*") + FMT_RESULTS=$(gofmt -l $GO_FILES_EXCLUDING_VENDOR) + FMT_RESULTS_COUNT=$(echo $FMT_RESULTS | wc -l) # returns one empty line when everything passes + if [ "$FMT_RESULTS_COUNT" -gt 1 ]; then + # some files have formatting errors + echo "--- gofmt found errors found in the following files:" + echo $FMT_RESULTS + exit 1 + else + # no files have formatting errors + exit 0 + fi +popd diff --git a/ci/test.sh b/ci/test.sh new file mode 100755 index 00000000..02553769 --- /dev/null +++ b/ci/test.sh @@ -0,0 +1,58 @@ +#!/bin/bash + +## Only uncomment the below for debugging +#set -euxo pipefail + +LOCAL_GO_VERSION=$(go version | awk -F' ' '{print $3}' | tr -d '[:space:]') +GO_VERSION="${TRAVIS_GO_VERSION:=$LOCAL_GO_VERSION}" +TIP_VERSION_IDENTIFIER="tip" +echo $GO_VERSION + +# Hold the package names that contain failures +FAIL_PACKAGES=() + +# OpenCV components to link in CGO compile +OPENCV_LDFLAGS="-lopencv_core -lopencv_videoio -lopencv_imgproc -lopencv_highgui -lopencv_imgcodecs -lopencv_objdetect -lopencv_calib3d -lopencv_video" + +# Use $HOME on Travis +# Use /usr/local on local +if [[ $TRAVIS == "true" ]]; then + export CGO_CPPFLAGS="-I${HOME}/usr/include" + export CGO_LDFLAGS="-L${HOME}/usr/lib $OPENCV_LDFLAGS" +else + export CGO_CPPFLAGS="-I/usr/local/include" + export CGO_LDFLAGS="-L/usr/local/lib $OPENCV_LDFLAGS" +fi + + +pushd $PWD/.. + # Set up coverage report file + COVERAGE_REPORT_LOCATION="./profile.cov" + echo "" > $COVERAGE_REPORT_LOCATION + + # Exclude vendor in the same way as Makefile does + EXCLUDING_VENDOR=$(go list ./... | grep -v /vendor/) + + # Iterate over all non-vendor packages and run tests with coverage + for package in $EXCLUDING_VENDOR; do \ + if [ $GO_VERSION == $TIP_VERSION_IDENTIFIER ]; then + # `go test` runs a vet subset as of this Change https://go-review.googlesource.com/c/go/+/74356 + result=$(go test -vet=off -covermode=count -coverprofile=tmp.cov $package) + else + result=$(go test -covermode=count -coverprofile=tmp.cov $package) + fi + if [ $? -ne 0 ]; then + FAIL_PACKAGES+=($package); + fi; + echo "$result" + if [ -f tmp.cov ]; then + cat tmp.cov >> profile.cov; + rm tmp.cov; + fi; + done + + # exit 1 if there have been any test failures + if [ ${#FAIL_PACKAGES[@]} -ne 0 ]; then + exit 1 + fi; +popd