1
0
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:
Alberto Bertogli
2023-02-01 23:05:00 +00:00
parent 795f2a7ceb
commit 7d6a59ba77
8 changed files with 25 additions and 224 deletions

View File

@@ -1,34 +0,0 @@
// This package is tested externally (see test.sh).
// However, we need this to do coverage tests.
//
// See coverage_test.go for the details, this is the same horrible hack.
//
//go:build coveragebin
// +build coveragebin
package main
import (
"os"
"os/signal"
"syscall"
"testing"
)
func TestRunMain(t *testing.T) {
done := make(chan bool)
signals := make(chan os.Signal, 1)
go func() {
<-signals
done <- true
}()
signal.Notify(signals, os.Interrupt, os.Kill, syscall.SIGTERM)
go func() {
main()
done <- true
}()
<-done
}

View File

@@ -1,7 +0,0 @@
#!/bin/bash
#
# Wrapper for dovecot-auth-cli to run when we build it in coverage mode.
exec ./dovecot-auth-cli.test -test.run ^TestRunMain$ \
-test.coverprofile="$COVER_DIR/test-`date +%s.%N`.out" \
"$@"

View File

@@ -8,15 +8,13 @@ init
# Build the binary once, so we can use it and launch it in chamuyero scripts.
# Otherwise, we not only spend time rebuilding it over and over, but also "go
# run" masks the exit code, which is something we care about.
# shellcheck disable=SC2086
if [ "${COVER_DIR}" != "" ]; then
go test -covermode=count -coverpkg=../../... -c \
$GOFLAGS -tags="coveragebin $GOTAGS"
cp coverage_wrapper dovecot-auth-cli
else
go build $GOFLAGS -tags="$GOTAGS" dovecot-auth-cli.go
if [ "${GOCOVERDIR}" != "" ]; then
GOFLAGS="-cover -covermode=count -o dovecot-auth-cli $GOFLAGS"
fi
# shellcheck disable=SC2086
go build $GOFLAGS -tags="$GOTAGS" .
if ! ./dovecot-auth-cli lalala 2>&1 | grep -q "invalid arguments"; then
echo "cli worked with invalid arguments"
exit 1