forked from decred/dcrd
-
Notifications
You must be signed in to change notification settings - Fork 0
/
run_tests.sh
executable file
·82 lines (67 loc) · 2.57 KB
/
run_tests.sh
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#!/usr/bin/env bash
# usage:
# ./run_tests.sh # local, go 1.12
# GOVERSION=1.11 ./run_tests.sh # local, go 1.11
# ./run_tests.sh docker # docker, go 1.12
# GOVERSION=1.11 ./run_tests.sh docker # docker, go 1.11
# ./run_tests.sh podman # podman, go 1.12
# GOVERSION=1.11 ./run_tests.sh podman # podman, go 1.11
set -ex
# The script does automatic checking on a Go package and its sub-packages,
# including:
# 1. gofmt (http://golang.org/cmd/gofmt/)
# 2. gosimple (https://github.com/dominikh/go-simple)
# 3. unconvert (https://github.com/mdempsky/unconvert)
# 4. ineffassign (https://github.com/gordonklaus/ineffassign)
# 5. misspell (https://github.com/client9/misspell)
# 6. race detector (http://blog.golang.org/race-detector)
# golangci-lint (github.com/golangci/golangci-lint) is used to run each each
# static checker.
# To run on docker on windows, symlink /mnt/c to /c and then execute the script
# from the repo path under /c. See:
# https://github.com/Microsoft/BashOnWindows/issues/1854
# for more details.
# Default GOVERSION
[[ ! "$GOVERSION" ]] && GOVERSION=1.12
REPO=dcrd
testrepo () {
GO=go
$GO version
# binary needed for RPC tests
env CC=gcc $GO build
cp "$REPO" "$GOPATH/bin/"
# run tests on all modules
ROOTPATH=$($GO list -m -f {{.Dir}} 2>/dev/null)
ROOTPATHPATTERN=$(echo $ROOTPATH | sed 's/\\/\\\\/g' | sed 's/\//\\\//g')
MODPATHS=$($GO list -m -f {{.Dir}} all 2>/dev/null | grep "^$ROOTPATHPATTERN"\
| sed -e "s/^$ROOTPATHPATTERN//" -e 's/^\\//' -e 's/^\///')
MODPATHS=". $MODPATHS"
for module in $MODPATHS; do
echo "==> ${module}"
env GORACE='halt_on_error=1' CC=gcc $GO test -short -race \
-tags rpctest ./${module}/...
# check linters
golangci-lint run --build-tags rpctest --disable-all --deadline=10m \
--enable=gofmt \
--enable=gosimple \
--enable=unconvert \
--enable=ineffassign \
--enable=misspell ./${module}/...
done
echo "------------------------------------------"
echo "Tests completed successfully!"
}
DOCKER=
[[ "$1" == "docker" || "$1" == "podman" ]] && DOCKER=$1
if [ ! "$DOCKER" ]; then
testrepo
exit
fi
# use Travis cache with docker
DOCKER_IMAGE_TAG=decred-golang-builder-$GOVERSION
$DOCKER pull decred/$DOCKER_IMAGE_TAG
$DOCKER run --rm -it -v $(pwd):/src:Z decred/$DOCKER_IMAGE_TAG /bin/bash -c "\
rsync -ra --filter=':- .gitignore' \
/src/ /go/src/github.com/decred/$REPO/ && \
cd github.com/decred/$REPO/ && \
env GOVERSION=$GOVERSION GO111MODULE=on bash run_tests.sh"