Hmm, my previous response got deleted for no reason. So here we go: the new 
mechanism is more general, and as you can see in my example I actually run 
the "same" unit tests twice. The reason is because some code paths might be 
only exercised when not being run as root, especially error handling. So 
there is some value in the new mechanism even "just" for unit tests. 
Admittedly, not all will need that in their unit tests.

On Wednesday, August 16, 2023 at 8:53:56 PM UTC+2 Jan wrote:

> Thanks, that's very helpful! 
>
> I was doing something similar 
> <https://github.com/janpfeifer/gonb/blob/main/docs/development.md#generate-coverage>,
>  
> but I was extracting the temporary coverage directory created by Go because 
> I didn't know about the --test.gocoverdir flag. 
>
> Still it feels wrong one has to do the trick of creating a temporary 
> directory (or extract it from the go tool) , where for unit tests only it's 
> not needed ... I wonder if this is done deliberately, or just a bug ?
>
> cheers
>
> On Wednesday, August 16, 2023 at 8:33:23 PM UTC+2 TheDiveO wrote:
>
>> Maybe similar to this? 
>> https://github.com/thediveo/lxkns/blob/cef5a31d7517cb126378f81628f51672cb793527/scripts/cov.sh#L28
>>
>> On Wednesday, August 16, 2023 at 1:54:48 PM UTC+2 Jan wrote:
>>
>>> hi all, 
>>>
>>> After reading the documentation 
>>> <https://go.dev/blog/integration-test-coverage>, I managed to set up a 
>>> process in which I compile and run my integration tests, and get coverage 
>>> from them in the `$GOCOVERDIR` subdirectory.
>>>
>>> Now I would like to have a combined unit tests + integration tests 
>>> report, all in one go, and I'm not sure how to get that.
>>>
>>> I was expecting that, if I go to my modules root directory, and I do:
>>>
>>> ```
>>> go test --cover --coverpkg=./... --coverprofile=/tmp/cover_profile.out 
>>> ./...
>>> go tool cover -func /tmp/cover_profile.out > /tmp/cover_func.out
>>> ```
>>>
>>> I  would get all the results, including integration tests (since they 
>>> are called with GOCOVERDIR set). But instead I only see the coverage of the 
>>> unit tests, and the information from the integration tests seems to be 
>>> ignored, even though it is generated.
>>>
>>> I'm sure it is generated because if I run the command above with 
>>> `--work` (preserve the temporary files), and log the value of $GOCOVERDIR I 
>>> can see where the test stores the coverage data files. And if I manually do:
>>>
>>> ```
>>> go tool covdata func -i /tmp/go-build287472875/b001/gocoverdir
>>> ```
>>> (where /tmp/go-build..../gocoverdir is the temporary directory reported 
>>> for GOCOVERDIR)
>>>
>>> I see the results I expected (some of my functions that I want to make 
>>> sure are covered) are there. But they are not reported in 
>>> `/tmp/cover_func.out` above.
>>>
>>> Any ideas why ? 
>>>
>>> Or any other suggestions on how to merge the report from unit tests 
>>> (`/tmp/cover_profile.out` in my example) and integration tests ? 
>>>
>>> thanks!
>>>
>>>
>>>
>>>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/65058e99-0502-4b2d-bcd3-1639853672bbn%40googlegroups.com.

Reply via email to