Skip to content

Commit 1553864

Browse files
committed
hack: add local test script
Signed-off-by: Aleksa Sarai <[email protected]>
1 parent a52051e commit 1553864

File tree

1 file changed

+50
-0
lines changed

1 file changed

+50
-0
lines changed

hack/test.sh

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
#!/bin/bash
2+
# Copyright (C) 2024-2025 SUSE LLC. All rights reserved.
3+
# Use of this source code is governed by a BSD-style
4+
# license that can be found in the LICENSE file.
5+
6+
set -Eeuo pipefail
7+
8+
root="$(readlink -f "$(dirname "${BASH_SOURCE[0]}")/..")"
9+
pushd "$root"
10+
11+
GO="${GO:-go}"
12+
13+
silent=
14+
verbose=
15+
long=
16+
while getopts "svL" opt; do
17+
case "$opt" in
18+
s)
19+
silent=1
20+
;;
21+
v)
22+
verbose=1
23+
;;
24+
L)
25+
long=1
26+
;;
27+
*)
28+
echo "$0 [-s(ilent)]"
29+
exit 1
30+
esac
31+
done
32+
33+
gocoverdir="$(mktemp --tmpdir -d gocoverdir.XXXXXXXX)"
34+
trap 'rm -rf $gocoverdir' EXIT
35+
36+
test_args=()
37+
[ -n "$verbose" ] && test_args+=("-v")
38+
[ -z "$long" ] && test_args+=("-short")
39+
40+
"$GO" test -count 1 -cover -test.gocoverdir="$gocoverdir" "${test_args[@]}" ./...
41+
sudo "$GO" test -count 1 -cover -test.gocoverdir="$gocoverdir" "${test_args[@]}" ./...
42+
43+
"$GO" tool covdata percent -i "$gocoverdir"
44+
[ -n "$silent" ] || "$GO" tool covdata func -i "$gocoverdir" | sort -k 3gr
45+
46+
gocoverage="$(mktemp gocoverage.XXXXXXXX)"
47+
trap 'rm $gocoverage' EXIT
48+
49+
"$GO" tool covdata textfmt -i "$gocoverdir" -o "$gocoverage"
50+
[ -n "$silent" ] || "$GO" tool cover -html="$gocoverage"

0 commit comments

Comments
 (0)