This repository has been archived by the owner on May 19, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathcodecheck.sh
executable file
·98 lines (84 loc) · 2.05 KB
/
codecheck.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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#!/bin/bash
# Fail fast on errors
set -e
# Download the fgt tool which returns a non-zero value if a command prints anything to stdout
# And grab coverage / lint tools
go get \
github.com/GeertJohan/fgt \
github.com/golang/lint/golint \
golang.org/x/tools/cmd/cover
export TEST_ROOT_PATH=$(cd $(dirname $0); pwd -P)
# The value of the exit status for the script.
scriptreturn=0
# Will modify the scriptreturn if anything non-zero comes back from fgt.
function testCmd() {
eval "$@"
ret=$?
if (($ret > 0)); then
scriptreturn=$ret
echo "FAILURE: $@"
fi
}
# This will set the return to non zero if output is returned. useful for go fmt.
# uses fgt instead of eval
function testCmdOutput() {
set +e
fgt "$@"
ret=$?
set -e
if (($ret > 0)); then
scriptreturn=$ret
echo "FAILURE: $@"
fi
}
# Get the list of packages.
pkgs=`go list ./...`
# Lint check
echo
echo
echo '---------------------------------------------------------'
echo 'Doing a lint check on go code'
echo '---------------------------------------------------------'
for pkg in $pkgs
do
testCmdOutput golint $pkg
done
# Vet check
echo
echo
echo '---------------------------------------------------------'
echo 'Doing a vet check on go code'
echo '---------------------------------------------------------'
for pkg in $pkgs
do
testCmdOutput go vet $pkg
done
# Fmt Check
echo
echo
echo '---------------------------------------------------------'
echo 'Doing a format / style check on go code'
echo '---------------------------------------------------------'
for pkg in $pkgs
do
testCmdOutput go fmt $pkg
done
# Coverage Check
echo
echo
echo '---------------------------------------------------------'
echo 'Doing a code coverage check on go code'
echo '---------------------------------------------------------'
echo "mode: count" > profile.cov
for pkg in $pkgs
do
echo "testing package $pkg"
testCmd go test -v -covermode=count $pkg -coverprofile=tmp.cov
if [ -f tmp.cov ]
then
cat tmp.cov | tail -n +2 >> profile.cov
rm tmp.cov
fi
done
testCmd go tool cover -func profile.cov
exit $scriptreturn