| 1 |
#!/bin/bash |
| 2 |
# SPDX-License-Identifier: MPL-2.0 |
| 3 |
|
| 4 |
# Copyright (C) 2024-2025 Aleksa Sarai <[email protected]> |
| 5 |
# Copyright (C) 2024-2025 SUSE LLC |
| 6 |
# |
| 7 |
# This Source Code Form is subject to the terms of the Mozilla Public |
| 8 |
# License, v. 2.0. If a copy of the MPL was not distributed with this |
| 9 |
# file, You can obtain one at https://mozilla.org/MPL/2.0/. |
| 10 |
|
| 11 |
set -Eeuo pipefail |
| 12 |
|
| 13 |
root="$(readlink -f "$(dirname "${BASH_SOURCE[0]}")/..")" |
| 14 |
pushd "$root" |
| 15 |
|
| 16 |
GO="${GO:-go}" |
| 17 |
|
| 18 |
silent= |
| 19 |
verbose= |
| 20 |
long= |
| 21 |
while getopts "svL" opt; do |
| 22 |
case "$opt" in |
| 23 |
s) |
| 24 |
silent=1 |
| 25 |
;; |
| 26 |
v) |
| 27 |
verbose=1 |
| 28 |
;; |
| 29 |
L) |
| 30 |
long=1 |
| 31 |
;; |
| 32 |
*) |
| 33 |
echo "$0 [-s(ilent)]" |
| 34 |
exit 1 |
| 35 |
esac |
| 36 |
done |
| 37 |
|
| 38 |
gocoverdir="$(mktemp --tmpdir -d gocoverdir.XXXXXXXX)" |
| 39 |
trap 'rm -rf $gocoverdir' EXIT |
| 40 |
|
| 41 |
test_args=("-count=1" "-cover" "-coverpkg=./...") |
| 42 |
[ -n "$verbose" ] && test_args+=("-v") |
| 43 |
[ -z "$long" ] && test_args+=("-short") |
| 44 |
|
| 45 |
"$GO" test "${test_args[@]}" ./... -args -test.gocoverdir="$gocoverdir" |
| 46 |
sudo "$GO" test "${test_args[@]}" ./... -args -test.gocoverdir="$gocoverdir" |
| 47 |
|
| 48 |
"$GO" tool covdata percent -i "$gocoverdir" |
| 49 |
[ -n "$silent" ] || "$GO" tool covdata func -i "$gocoverdir" | sort -k 3gr |
| 50 |
|
| 51 |
gocoverage="$(mktemp gocoverage.XXXXXXXX)" |
| 52 |
trap 'rm $gocoverage' EXIT |
| 53 |
|
| 54 |
"$GO" tool covdata textfmt -i "$gocoverdir" -o "$gocoverage" |
| 55 |
[ -n "$silent" ] || "$GO" tool cover -html="$gocoverage" |