onsi / ginkgo

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

coverprofile not creating output file in the location specified #1459

Closed plastikfan closed 2 months ago

plastikfan commented 2 months ago

If I run this locally in my project:

ginkgo run ./... --json-report ./coverage/ginkgo.report -coverpkg=./... -coverprofile=./coverage/coverage.out

[1725970208] Traverse Suite - 20/20 specs •••••••••••••••••••• SUCCESS! 749.712178ms PASS
[1725970208] Collections Suite - 69/69 specs ••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••• SUCCESS! 14.417377ms PASS
[1725970208] Core Suite - 14/14 specs •••••••••••••• SUCCESS! 2.954423ms PASS
[1725970208] Cycle Suite - 31/31 specs ••••••••••••••••••••••••••••••• SUCCESS! 8.429037ms PASS
[1725970208] Filter Suite - 0/0 specs  SUCCESS! 239.488µs PASS
[1725970208] Hibernate Suite - 9/9 specs ••••••••• SUCCESS! 176.781817ms PASS
[1725970208] Sampling Suite - 29/29 specs ••••••••••••••••••••••••••••• SUCCESS! 120.169954ms PASS
[1725970208] Filtering Suite - 49/49 specs ••••••••••••••••••••••••••••••••••••••••••••••••• SUCCESS! 544.110106ms PASS
[1725970208] Kernel Suite - 13/13 specs ••••••••••••• SUCCESS! 189.048426ms PASS
[1725970208] Broker Suite - 22/22 specs •••••••••••••••••••••• SUCCESS! 6.925855ms PASS
[1725970208] Locale Suite - 6/6 specs •••••• SUCCESS! 49.06771ms PASS
[1725970208] Nfs Suite - 11/11 specs ••••••••••• SUCCESS! 8.52585ms PASS
[1725970208] Pref Suite - 0/0 specs  SUCCESS! 337.464µs PASS
[1725970208] Tapable Suite - 15/15 specs ••••••••••••••• SUCCESS! 83.392708ms PASS

Ginkgo ran 14 suites in 53.839917882s
Test Suite Passed

The coverage runs, but there is no output file in localation specified by the coverprofile flag

Listing the contents of the path shows no content.

And actually, there is no ginkgo.report either.

Something weird is happening here, but this looks to be a straight forward use case. I have seen these files created before, but the circumstances are very murky so I can't specify the conditions where it works.

It would also be useful, to explicitly show the location where output files are generated.

onsi commented 2 months ago

@plastikfan - json-report and cover-profile don’ take full paths, just a single file name. can you please try just

ginkgo run ./... --json-report ginkgo.report -coverpkg=./... -coverprofile=coverage.out

locally and let me know what you see? there should be a ginkgo.report and a coverage.out in the directory from which you invoke ginkgo

plastikfan commented 2 months ago

ok the ginkgo.report file comes out, but still no coverage.out file

onsi commented 2 months ago

ok, great - can you share the command you’re running and all the output that you’re seeing?

plastikfan commented 2 months ago

ginkgo run ./... --json-report ginkgo.report -coverpkg=./... -coverprofile=coverage.out

plastikfan commented 2 months ago

Oh and same output as before, everything seems to run ok

onsi commented 2 months ago

you should see a “coverage” percentage at the end of the test run, or a message explaining why coverage wasn’t calculated

actually, also, it’s a small gotcha but can you run

ginkgo  -r -json-report ginkgo.report -coverpkg=./... -coverprofile=coverage.out

instead - i just noticed that the list of packages “./…” is to the left of the arguments

plastikfan commented 2 months ago

Oh jeez, now that does make a difference. I am now seeing the coverage.out file. I recompiled ginkgo with some debug statements which were not coming out beforea and now they are.

So I assume, if I wanted to send those outputs to a different directory, I could use that other flag, I think its output-dir (I need to look this up, but I remember seeing it)

plastikfan commented 2 months ago

AH found it: --output-dir

plastikfan commented 2 months ago

and the good thing about ginkgo coverage is that it is way more accurate and less buggy than trying to run coverage with the go test command. This is why I've been determned to get ginkgo coverage working.

plastikfan commented 2 months ago

Thank you @onsi

onsi commented 2 months ago

hey glad we figured it out!