2019-08-20 17:04:13 +02:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2020-05-24 17:43:42 +02:00
|
|
|
"fmt"
|
2019-08-20 17:04:13 +02:00
|
|
|
"os"
|
|
|
|
"strings"
|
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
|
|
|
// Idea taken from
|
|
|
|
// https://github.com/openSUSE/umoci/blob/v0.2.1/cmd/umoci/main_test.go
|
|
|
|
//
|
2019-09-29 18:44:59 +02:00
|
|
|
/* How to generate coverage:
|
|
|
|
go test -c -covermode=atomic -cover -coverpkg github.com/zrepl/zrepl/...
|
|
|
|
sudo ../logmockzfs/logzfsenv /tmp/zrepl_platform_test.log /usr/bin/zfs \
|
|
|
|
./harness.test -test.coverprofile=/tmp/harness.out \
|
|
|
|
-test.v __DEVEL--i-heard-you-like-tests \
|
|
|
|
-imagepath /tmp/testpool.img -poolname zreplplatformtest
|
|
|
|
go tool cover -html=/tmp/harness.out -o /tmp/harness.html
|
|
|
|
*/
|
2019-08-20 17:04:13 +02:00
|
|
|
// Merge with existing coverage reports using gocovmerge:
|
|
|
|
// https://github.com/wadey/gocovmerge
|
|
|
|
|
|
|
|
func TestMain(t *testing.T) {
|
2020-05-24 17:43:42 +02:00
|
|
|
fmt.Println("incoming args: ", os.Args)
|
|
|
|
|
2019-08-20 17:04:13 +02:00
|
|
|
var (
|
2020-05-24 17:43:42 +02:00
|
|
|
args []string
|
|
|
|
run bool
|
|
|
|
startCaptureArgs bool
|
2019-08-20 17:04:13 +02:00
|
|
|
)
|
|
|
|
|
2020-05-24 17:43:42 +02:00
|
|
|
for i, arg := range os.Args {
|
2019-08-20 17:04:13 +02:00
|
|
|
switch {
|
|
|
|
case arg == "__DEVEL--i-heard-you-like-tests":
|
|
|
|
run = true
|
2020-05-24 17:43:42 +02:00
|
|
|
startCaptureArgs = true
|
2019-08-20 17:04:13 +02:00
|
|
|
case strings.HasPrefix(arg, "-test"):
|
|
|
|
case strings.HasPrefix(arg, "__DEVEL"):
|
2020-05-24 17:43:42 +02:00
|
|
|
case i == 0:
|
|
|
|
args = append(args, arg)
|
|
|
|
case startCaptureArgs:
|
2019-08-20 17:04:13 +02:00
|
|
|
args = append(args, arg)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
os.Args = args
|
2020-05-24 17:43:42 +02:00
|
|
|
fmt.Println("using args: ", os.Args)
|
2019-08-20 17:04:13 +02:00
|
|
|
|
|
|
|
if run {
|
|
|
|
main()
|
|
|
|
}
|
|
|
|
}
|