mirror of
https://blitiri.com.ar/repos/chasquid
synced 2025-12-17 14:37:02 +00:00
test: Update coverage tests to Go 1.20
Go 1.20 finally includes proper support for instrumenting binaries for coverage. This allows us to drop quite a few hacks and workarounds that we used for it, and we can now also test exiting cases. The downside is that coverage tests now require Go 1.20, but it is an acceptable price to pay for the more accurate results. Normal integration tests are unchanged. This patch updates the coverage testing infrastructure to make use of the new Go 1.20 features.
This commit is contained in:
@@ -1,92 +0,0 @@
|
||||
//usr/bin/env go run "$0" "$@"; exit $?
|
||||
//
|
||||
// From: https://git.lukeshu.com/go/cmd/gocovcat/
|
||||
//
|
||||
//go:build !coverage
|
||||
// +build !coverage
|
||||
|
||||
// Copyright 2017 Luke Shumaker <lukeshu@parabola.nu>
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
// Command gocovcat combines multiple go cover runs, and prints the
|
||||
// result on stdout.
|
||||
package main
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"fmt"
|
||||
"os"
|
||||
"sort"
|
||||
"strconv"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func handleErr(err error) {
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "%v\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
|
||||
func main() {
|
||||
modeBool := false
|
||||
blocks := map[string]int{}
|
||||
for _, filename := range os.Args[1:] {
|
||||
file, err := os.Open(filename)
|
||||
handleErr(err)
|
||||
buf := bufio.NewScanner(file)
|
||||
for buf.Scan() {
|
||||
line := buf.Text()
|
||||
|
||||
if strings.HasPrefix(line, "mode: ") {
|
||||
m := strings.TrimPrefix(line, "mode: ")
|
||||
switch m {
|
||||
case "set":
|
||||
modeBool = true
|
||||
case "count", "atomic":
|
||||
// do nothing
|
||||
default:
|
||||
fmt.Fprintf(os.Stderr, "Unrecognized mode: %s\n", m)
|
||||
os.Exit(1)
|
||||
}
|
||||
} else {
|
||||
sp := strings.LastIndexByte(line, ' ')
|
||||
block := line[:sp]
|
||||
cntStr := line[sp+1:]
|
||||
cnt, err := strconv.Atoi(cntStr)
|
||||
handleErr(err)
|
||||
blocks[block] += cnt
|
||||
}
|
||||
}
|
||||
handleErr(buf.Err())
|
||||
}
|
||||
keys := make([]string, 0, len(blocks))
|
||||
for key := range blocks {
|
||||
keys = append(keys, key)
|
||||
}
|
||||
sort.Strings(keys)
|
||||
modeStr := "count"
|
||||
if modeBool {
|
||||
modeStr = "set"
|
||||
}
|
||||
fmt.Printf("mode: %s\n", modeStr)
|
||||
for _, block := range keys {
|
||||
cnt := blocks[block]
|
||||
if modeBool && cnt > 1 {
|
||||
cnt = 1
|
||||
}
|
||||
fmt.Printf("%s %d\n", block, cnt)
|
||||
}
|
||||
}
|
||||
@@ -27,9 +27,8 @@ function init() {
|
||||
}
|
||||
|
||||
function chasquid() {
|
||||
if [ "${COVER_DIR}" != "" ]; then
|
||||
chasquid_cover "$@"
|
||||
return
|
||||
if [ "${GOCOVERDIR}" != "" ]; then
|
||||
GOFLAGS="-cover -covermode=count -o chasquid $GOFLAGS"
|
||||
fi
|
||||
|
||||
# shellcheck disable=SC2086
|
||||
@@ -44,26 +43,6 @@ function chasquid() {
|
||||
"${TBASE}/../../chasquid" "$@"
|
||||
}
|
||||
|
||||
function chasquid_cover() {
|
||||
# Build the coverage-enabled binary.
|
||||
# See coverage_test.go for more details.
|
||||
# shellcheck disable=SC2086
|
||||
( cd "${TBASE}/../../" || exit 1;
|
||||
go test -covermode=count -coverpkg=./... -c \
|
||||
-tags="coveragebin $GOTAGS" $GOFLAGS )
|
||||
|
||||
# Run the coverage-enabled binary, named "chasquid.test" for hacky
|
||||
# reasons. See the chasquid function above for details on the
|
||||
# environment variables.
|
||||
HOSTALIASES=${TBASE}/hosts \
|
||||
PATH=${UTILDIR}:${PATH} \
|
||||
MDA_DIR=${TBASE}/.mail \
|
||||
"${TBASE}/../../chasquid.test" \
|
||||
-test.run "^TestRunMain$" \
|
||||
-test.coverprofile="$COVER_DIR/test-$(date +%s.%N).out" \
|
||||
"$@"
|
||||
}
|
||||
|
||||
# Add a user with chasquid-util. Because this is somewhat cryptographically
|
||||
# intensive, it can slow down the tests significantly, so most of the time we
|
||||
# use the simpler add_user (below) for testing purposes.
|
||||
|
||||
Reference in New Issue
Block a user