2017-11-05 07:48:11 +08:00
|
|
|
#!/bin/bash
|
|
|
|
|
2017-11-05 11:13:14 +08:00
|
|
|
## Only uncomment the below for debugging
|
|
|
|
#set -euxo pipefail
|
2017-11-05 07:48:11 +08:00
|
|
|
|
2017-11-07 03:26:08 +08:00
|
|
|
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
|
|
|
|
|
2017-11-05 07:48:11 +08:00
|
|
|
# Hold the package names that contain failures
|
2017-11-05 11:13:14 +08:00
|
|
|
FAIL_PACKAGES=()
|
2017-11-05 07:48:11 +08:00
|
|
|
|
2017-11-15 01:08:41 +08:00
|
|
|
# OpenCV components to link in CGO compile
|
2018-02-14 20:54:41 +08:00
|
|
|
OPENCV_LDFLAGS="-lopencv_core -lopencv_face -lopencv_videoio -lopencv_imgproc -lopencv_highgui -lopencv_imgcodecs -lopencv_objdetect -lopencv_features2d -lopencv_video -lopencv_dnn -lopencv_xfeatures2d"
|
2017-11-15 01:08:41 +08:00
|
|
|
|
|
|
|
# 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
|
|
|
|
|
|
|
|
|
2017-11-05 07:48:11 +08:00
|
|
|
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 \
|
2017-11-07 03:26:08 +08:00
|
|
|
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
|
2017-11-05 11:13:14 +08:00
|
|
|
FAIL_PACKAGES+=($package);
|
2017-11-05 07:48:11 +08:00
|
|
|
fi;
|
2017-11-05 11:13:14 +08:00
|
|
|
echo "$result"
|
2017-11-05 07:48:11 +08:00
|
|
|
if [ -f tmp.cov ]; then
|
|
|
|
cat tmp.cov >> profile.cov;
|
|
|
|
rm tmp.cov;
|
|
|
|
fi;
|
|
|
|
done
|
|
|
|
|
|
|
|
# exit 1 if there have been any test failures
|
2017-11-05 11:13:14 +08:00
|
|
|
if [ ${#FAIL_PACKAGES[@]} -ne 0 ]; then
|
2017-11-05 07:48:11 +08:00
|
|
|
exit 1
|
|
|
|
fi;
|
|
|
|
popd
|