1
0
mirror of https://blitiri.com.ar/repos/chasquid synced 2025-12-18 14:47:03 +00:00

test: Add tools to generate test coverage information

This patch adds some tooling and scripts to generate test coverage
information.

Unfortunately, this involves some hacks as Go does not have support for
generating coverage-enabled binaries, or merging coverage reports; but
overall it's not very intrusive.
This commit is contained in:
Alberto Bertogli
2018-02-25 01:24:00 +00:00
parent 751fbd4b55
commit bb90274edd
11 changed files with 221 additions and 0 deletions

39
coverage_test.go Normal file
View File

@@ -0,0 +1,39 @@
// Test file used to build a coverage-enabled chasquid binary.
//
// Go lacks support for properly building a coverage binary, it can only build
// coverage test binaries. As a workaround, we have a test that just runs
// main. We then build a binary of this test, which we use instead of chasquid
// in integration tests.
//
// This is hacky and horrible.
//
// The test has a build label so it's not accidentally executed during normal
// "go test" invocations.
// +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
}