1
1
#! /usr/bin/env zsh
2
2
3
- root=" $( git rev-parse --show-toplevel ) "
3
+ root=" $( git rev-parse --show-toplevel 2> /dev/null ) "
4
4
testdir=" ${root} /testenv"
5
5
iplist=" ${root} /info.plist"
6
6
covfile=" ${root} /coverage.out"
7
7
covhtml=" ${root} /coverage.html"
8
8
9
9
verbose=false
10
+ runinstall=false
10
11
runlint=false
11
12
runtests=true
12
13
opencover=false
@@ -30,6 +31,18 @@ installed() {
30
31
return $?
31
32
}
32
33
34
+ # install <import-address> | Install Go program if it's not already installed
35
+ install () {
36
+ local p=$1
37
+ local name=${p: t}
38
+ installed " $name " || {
39
+ log " installing $name ..."
40
+ GO111MODULE=off go get -u $gopts $p
41
+ [[ $? -eq 0 ]] || fail " install $name failed"
42
+ success " installed $name "
43
+ }
44
+ }
45
+
33
46
# success <arg>... | Write message in green to STDOUT
34
47
success () {
35
48
$verbose || return 0
@@ -110,7 +123,6 @@ while getopts ":CcghilrtvV" opt; do
110
123
vopt=' -v'
111
124
;;
112
125
v)
113
- gopts+=(-v)
114
126
verbose=true
115
127
;;
116
128
h)
@@ -131,11 +143,13 @@ $runlint && {
131
143
}
132
144
success " all files formatted correctly"
133
145
134
- go run golang.org/x/lint/golint -set_exit_status ./...
146
+ install golang.org/x/lint/golint
147
+ golint -set_exit_status ./...
135
148
[[ $? -eq 0 ]] || fail " linting with golint failed"
136
149
success " golint found no issues"
137
150
138
- go run github.com/golangci/golangci-lint/cmd/golangci-lint run -c .golangci.toml
151
+ install github.com/golangci/golangci-lint/cmd/golangci-lint
152
+ golangci-lint run -c .golangci.toml
139
153
[[ $? -eq 0 ]] || fail " linting with golangci-lint failed"
140
154
success " golangci-lint found no issues"
141
155
exit 0
@@ -158,7 +172,8 @@ pkgs=(./...)
158
172
159
173
st=0
160
174
$runtests && {
161
- go test -cover -json $gopts $pkgs | go run github.com/mfridman/tparse
175
+ install github.com/mfridman/tparse
176
+ go test -cover -json $gopts $pkgs | tparse
162
177
# gotestsum -- $gopts $pkgs
163
178
st=$?
164
179
[[ $st -eq 0 ]] && success " unit tests passed"
170
185
171
186
$opencover && {
172
187
$usegocov && {
173
- go run github.com/axw/gocov/gocov convert " $covfile " \
174
- | go run github.com/matm/gocov-html > " $covhtml "
188
+ install github.com/axw/gocov/gocov
189
+ install github.com/matm/gocov-html
190
+ gocov convert " $covfile " | gocov-html > " $covhtml "
175
191
open " $covhtml "
176
192
} || {
177
193
go tool cover -html=" $covfile "
0 commit comments