File: test.sh

package info (click to toggle)
golang-github-cyphar-filepath-securejoin 0.5.1-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 704 kB
  • sloc: sh: 36; makefile: 8
file content (55 lines) | stat: -rwxr-xr-x 1,317 bytes parent folder | download | duplicates (2)
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
#!/bin/bash
# SPDX-License-Identifier: MPL-2.0

# Copyright (C) 2024-2025 Aleksa Sarai <cyphar@cyphar.com>
# Copyright (C) 2024-2025 SUSE LLC
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at https://mozilla.org/MPL/2.0/.

set -Eeuo pipefail

root="$(readlink -f "$(dirname "${BASH_SOURCE[0]}")/..")"
pushd "$root"

GO="${GO:-go}"

silent=
verbose=
long=
while getopts "svL" opt; do
	case "$opt" in
		s)
			silent=1
			;;
		v)
			verbose=1
			;;
		L)
			long=1
			;;
		*)
			echo "$0 [-s(ilent)]"
			exit 1
	esac
done

gocoverdir="$(mktemp --tmpdir -d gocoverdir.XXXXXXXX)"
trap 'rm -rf $gocoverdir' EXIT

test_args=("-count=1" "-cover" "-coverpkg=./...")
[ -n "$verbose" ] && test_args+=("-v")
[ -z "$long" ] && test_args+=("-short")

"$GO" test "${test_args[@]}" ./... -args -test.gocoverdir="$gocoverdir"
sudo "$GO" test "${test_args[@]}" ./... -args -test.gocoverdir="$gocoverdir"

"$GO" tool covdata percent -i "$gocoverdir"
[ -n "$silent" ] || "$GO" tool covdata func -i "$gocoverdir" | sort -k 3gr

gocoverage="$(mktemp gocoverage.XXXXXXXX)"
trap 'rm $gocoverage' EXIT

"$GO" tool covdata textfmt -i "$gocoverdir" -o "$gocoverage"
[ -n "$silent" ] || "$GO" tool cover -html="$gocoverage"