-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathtest
executable file
·61 lines (49 loc) · 1.13 KB
/
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
51
52
53
54
55
56
57
58
59
60
61
#!/usr/bin/env bash
#
# Run all tests
# ./test
# ./test -v
#
# Run tests for one package
# PKG=./foo ./test
#
set -e
cd $(dirname $0)
# A replacement for `go fmt` that calls gofmt without -w
gofmt-l() {
pushd "${GOPATH}/src" >/dev/null
c=$(gofmt -l "$@" | tee /dev/stderr | wc -c)
popd >/dev/null
if [[ $c -ne 0 ]]; then
echo "gofmt check failed" >&2
return 1
fi
}
source ./env
# Use an alternate bin to avoid clobbering output from ./build
export GOBIN="${GOPATH}/_testbin"
# cd via the symlink so ./... and so on resolves correctly.
cd gopath/src/${REPO_PATH}
# PKG may be passed in from ./cover
[[ -z "$PKG" ]] && PKG="./..."
# Expand PKG, excluding the vendor directory.
pkgs=$(go list $PKG | grep -v /vendor/)
echo "Building tests..."
go test -i "$@" $pkgs
go install $pkgs
echo "Running tests..."
go test -cover "$@" $pkgs
echo "Checking gofmt..."
if [[ "$@" == "-v" ]]; then
gofmt-l -d $pkgs
else
gofmt-l $pkgs
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"