-
Notifications
You must be signed in to change notification settings - Fork 28
/
Copy pathrun-go-tests
executable file
·66 lines (55 loc) · 1.72 KB
/
run-go-tests
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
#!/usr/bin/env bash
# Runs all unit tests and performs static code analysis.
#
# Options:
#
# --full Include slower, more exhaustive tests and capture test coverage
# results (outputs to .coverage.html).
# Exit on first failure.
set -e
# Echo commands before executing them, by default to stderr.
set -x
# Fail when piped commands fail.
set -o pipefail
full_test=""
# Without netgo and osusergo, compilation fails under Nix.
go_test_flags=("-tags=netgo,osusergo")
readonly COVERAGE_FILE_RAW=".coverage.out"
readonly COVERAGE_FILE_HTML=".coverage.html"
if [[ "$1" = "--full" ]]; then
full_test="1"
go_test_flags+=("-v")
go_test_flags+=("-race")
go_test_flags+=("--coverprofile=${COVERAGE_FILE_RAW}")
fi
# Exit on unset variable.
set -u
# Change directory to repository root.
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
readonly SCRIPT_DIR
cd "${SCRIPT_DIR}/.."
go test "${go_test_flags[@]}" ./...
if [[ -n "$full_test" ]]; then
go tool cover -html "${COVERAGE_FILE_RAW}" -o "${COVERAGE_FILE_HTML}"
fi
go vet ./...
# Install staticcheck if it's not present.
STATICCHECK_PATH="$(go env GOPATH)/bin/staticcheck"
readonly STATICCHECK_PATH
readonly STATICCHECK_VERSION="v0.4.6"
if [[ ! -f "${STATICCHECK_PATH}" ]]; then
go install \
-ldflags=-linkmode=external \
"honnef.co/go/tools/cmd/staticcheck@${STATICCHECK_VERSION}"
fi
"${STATICCHECK_PATH}" ./...
# Install errcheck if it's not present.
ERRCHECK_PATH="$(go env GOPATH)/bin/errcheck"
readonly ERRCHECK_PATH
readonly ERRCHECK_VERSION="v1.6.2"
if [[ ! -f "${ERRCHECK_PATH}" ]]; then
go install \
-ldflags=-linkmode=external \
"github.com/kisielk/errcheck@${ERRCHECK_VERSION}"
fi
"${ERRCHECK_PATH}" -ignoretests ./...