onsi / ginkgo

A Modern Testing Framework for Go
http://onsi.github.io/ginkgo/
MIT License
8.38k stars 660 forks source link

Go 1.20 : -test.gocoverdir #1175

Open gfyrag opened 1 year ago

gfyrag commented 1 year ago

Hi!

I'm using Ginkgo for integration testings and would like to use the flag -test.gocoverdir introduced with Go 1.20. If using plain "go test", it works as expected, but not with the ginkgo cli. Unfortunately, using "go test" involve no parallel testing. I tried to "go test" with the flags -ginkgo.parallel.XXX, but ginkgo complains about it. Not surprising as i'm not supposed to do that.

Do you have any plan tu support it? Or maybe a workaround?

onsi commented 1 year ago

hey there i haven't played with it myself yet but my understanding from the integration coverage docs and the latest set of go test flags is they you simply set a GOCOVERDIR environment variable to have your precompiled binaries emit coverage information. each invocation of the binary will generate a new file that you can inspect and merge with go tool covdata and i would assume that the go community has done the work to ensure that concurrent invocations of the binary do not generate issue so you can simply run GOCOVERDIR=/path/to/dir ginkgo -p and things should work. My only recommendation is that you use an absolute path for GOCOVERDIR as Ginkgo will change the working directory when invoking specs in subdirectories.

Give it a try!

amanhigh commented 1 year ago

I have a Similar Issue.

Here Running go test works but i have used Labels to exclude few tests which i am unable to do.

export GOCOVERDIR=`pwd`
ginkgo -r '--label-filter=!setup'

This is not Generating Binary Coverage Files which can be processed by covdata.

Eg go tool covdata percent -i=.

gfyrag commented 1 month ago

Come back on this issue (I had forget it to be honnest...). I have tried your suggestion @onsi , and the directory stay empty. I used that command: GOCOVERDIR=$PWD/coverage/e2e ginkgo -tags it -cover -p ./test/...