-
Notifications
You must be signed in to change notification settings - Fork 13
/
test
executable file
·50 lines (39 loc) · 915 Bytes
/
test
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#!/usr/bin/env bash
#
# Run all tests
# ./test
# ./test -v
#
# Run tests for one package
# PKG=./foo ./test
#
set -e
cd $(dirname $0)
source ./env
# Use an alternate bin to avoid clobbering output from ./build
export GOBIN="$(pwd)/_testbin"
trap "rm -rf _testbin/" EXIT
# PKG may be passed in from ./cover
[[ -z "$PKG" ]] && PKG="./..."
# Expand PKG, excluding the vendor directory.
pkgs=$(go list $PKG | grep -v /vendor/)
src=$(find . -name '*.go' -not -path "./vendor/*")
echo "Building"
go install -mod=vendor $pkgs
echo "Running tests..."
go test -mod=vendor -cover "$@" $pkgs
echo "Checking gofmt..."
res=$(gofmt -d -e $src)
if [ -n "${res}" ]; then
echo "${res}"
echo "gofmt check failed" >&2
exit 1
fi
echo "Checking govet..."
go vet $pkgs
echo "Running commands..."
for cmd in ${GOBIN}/*; do
echo " Running $(basename ${cmd})..."
${cmd} --help > /dev/null
done
echo "Success"