forked from deanishe/awgo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
run-tests.sh
executable file
·176 lines (150 loc) · 3.28 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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
#!/usr/bin/env zsh
root="$( git rev-parse --show-toplevel )"
testdir="${root}/testenv"
iplist="${root}/info.plist"
covfile="${root}/coverage.out"
covjson="${root}/coverage.json"
covhtml="${root}/coverage.html"
verbose=false
runtests=true
opencover=false
usegocov=false
cover=false
mkip=false
vopt=
gopts=()
# log <arg>... | Echo arguments to STDERR
log() {
echo "$@" >&2
}
# installed <prog> | Check whether program is installed
installed() {
hash "$1" &>/dev/null
return $?
}
# info <arg>.. | Write args to STDERR if VERBOSE is true
info() {
$verbose && log $(print -P "%F{blue}.. %f") "$@"
return 0
}
# success <arg>.. | Write green "ok" and args to STDERR if VERBOSE is true
success() {
# $verbose && log $(print -P "%F{green}ok %f") "$@"
log $(print -P "%F{green}#####################################%f")
log $(print -P "%F{green}# $@ %f")
log $(print -P "%F{green}#####################################%f")
return 0
}
# error <arg>.. | Write red "error" and args to STDERR
error() {
log $(print -P '%F{red}err%f') "$@"
}
# fail <arg>.. | Write red "error" and args to STDERR, then exit with status 1
fail() {
log $(print -P "%F{red}#####################################%f")
log $(print -P "%F{red}# $@ %f")
log $(print -P "%F{red}#####################################%f")
# error "$@"
exit 1
}
usage() {
cat <<EOF
run-tests.sh [options] [<module>...]
Run unit tests in a workflow-like environment.
Usage:
run-tests.sh [-v|-V] [-c] [-i] [-g] [-H]
run-tests.sh [-g] -r
run-tests.sh -h
Options:
-c Write coverage report
-C Open HTML coverage report
-r Just open coverage report
-g Use gocov for coverage report (implies -c)
-i Create a dummy info.plist
-h Show this help message and exit
-v Be verbose
-V Be even more verbose
EOF
}
while getopts ":CcghirvV" opt; do
case $opt in
c)
cover=true
;;
g)
usegocov=true
cover=true
;;
C)
opencover=true
cover=true
;;
i)
mkip=true
;;
r)
opencover=true
runtests=false
;;
V)
gopts+=(-v)
verbose=true
vopt='-v'
;;
v)
gopts+=(-v)
verbose=true
;;
h)
usage
exit 0
;;
\?)
fail "invalid option: -$OPTARG";;
esac
done
shift $((OPTIND-1))
$cover && gopts+=(-coverprofile="$covfile")
command mkdir $vopt -p "${testdir}"/{data,cache}
$mkip && touch $vopt "$iplist"
cd "$root"
source "env.sh"
export alfred_version=
export alfred_workflow_data="${testdir}/data"
export alfred_workflow_cache="${testdir}/cache"
[[ $#@ -eq 0 ]] && {
pkgs=(./...)
} || {
pkgs=($@)
}
st=0
$runtests && {
go test $gopts $pkgs
st=$?
[[ $st -eq 0 ]] && {
success "tests passed"
}
command rm $vopt -rf "$testdir"/*
}
test -f "$iplist" && command rm $vopt -f "$iplist"
cd -
[[ $st -ne 0 ]] && {
fail "tests failed"
}
$opencover && {
$usegocov && {
gocov convert "$covfile" > "$covjson"
gocov-html > "$covhtml" < "$covjson"
open "$covhtml"
} || {
go tool cover -html="$covfile"
}
}
# $cover && installed gocov && {
# gocov convert "$covfile" > "$covjson"
# installed gocov-html && {
# gocov-html > "$covhtml" < "$covjson"
# }
# }
exit 0
# vim: set ft=zsh ts=2 sw=2 tw=100 et :