-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathgotest
More file actions
executable file
·33 lines (27 loc) · 886 Bytes
/
gotest
File metadata and controls
executable file
·33 lines (27 loc) · 886 Bytes
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
#!/bin/bash
set -eu
find_go_mod() {
cwd="$(pwd)"
while :; do
if [ -e "$cwd/go.mod" ]; then
echo $cwd
return
elif [ "$cwd" = "/" ]; then
echo "E: go.mod not found in parent path. Aborting!"
exit 1
else
cwd="$(dirname "$cwd")"
fi
done
}
projectroot="$(find_go_mod)"
cov_dir="${projectroot}/coverage"
mkdir -p "${cov_dir}"
# start http server on 6061 if none
if ! $(nc -z localhost 6061); then
nohup python3 -m http.server --directory "${cov_dir}" 6061 1>/dev/null 2>&1 &
fi
go test $@ -coverprofile="${cov_dir}/coverage.out" -coverpkg=./...
grep -vE testutils "${cov_dir}/coverage.out" > "${cov_dir}/coverage.out.filtered"
go tool cover -html="${cov_dir}/coverage.out.filtered" -o "${cov_dir}/index.html"
echo "Coverage report available at http://localhost:6061/index.html"