-
Notifications
You must be signed in to change notification settings - Fork 7
/
test.sh
executable file
·49 lines (43 loc) · 862 Bytes
/
test.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
#!/bin/bash -e
packages=$(go list ./... | grep -v vendor | xargs)
usage() {
cat <<EOF
commands:
test - run linter, vetter, and tests
EOF
}
go_fmt() {
echo 'running go fmt on all packages...'
fmt=$(go fmt $packages 2>&1)
if [[ $fmt ]]; then
echo $fmt
exit 1
fi
}
go_vet() {
echo 'running go vet on all packages...'
go vet $packages
}
go_test() {
echo 'running go test on all packages...'
for pkg in $packages
do
pkg_name=$(echo "$pkg" | tr / -)
pkg_cov="${pkg_name}.cov"
go test -v -race -covermode=count -coverprofile="$pkg_cov" "$pkg"
if [ -f "$pkg_cov" ]
then
go tool cover -html="$pkg_cov" -o "${pkg_name}.html"
fi
done
}
case $1 in
test)
go_fmt
go_vet
go_test
;;
*)
usage
;;
esac