-
Notifications
You must be signed in to change notification settings - Fork 17.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
cmd/cover: go test coverage report incorrect when using loop in conjunction with parallel #19845
Comments
Pretty sure this is because you're missing See cmd/go docs:
|
@bradfitz this is not true. The test above has been done using |
Sorry, missed that. |
Do you see races, though? |
This looks like In the same example, if you use
Looking into why |
@SmaugTheGreat : When you say it's shown as not covered, do you mean it's shown in red color? Or grey? In my local run, line |
@Dhananjay92 It's shown in red color and the cover.out file is also listing the lines as not covered (not just the HTML representation) I just tested it on my Windows machine at home with the same result (OP is Mac OS X). Here's a screen-shot with all the relevant data: http://imgur.com/vyjuQkK |
I can reproduce this both on go1.8 and on tip on a Linux system. Coverage is 66% and html shows the first return line in red (= no coverage). |
Thanks. I can also repro 66.7% coverage now. (Silly me; Earlier, I had commented Looking closely at the If you copy func TestSomeFunction(t *testing.T) {
someList := []bool {
true, false,
}
for _, v := range someList {
v2 := v
t.Run("testx", func(t *testing.T) {
t.Parallel()
someFunction(v2)
})
}
} |
Ah! This is also noted in the testing package documentation: https://golang.org/pkg/testing/#hdr-Subtests_and_Sub_benchmarks
Looks like this is working as intended; the error is in the code. |
Indeed. |
What version of Go are you using (
go version
)?1.8
What operating system and processor architecture are you using (
go env
)?darwin/amd64
What did you do?
main.go:
main_test.go:
run the command
go test -coverprofile cover.out -covermode atomic
What did you expect to see?
Full coverage
What did you see instead?
The line with the
return 1
is displayed as not covered.Additional info
Manually unrolling the for-loop in
TestSomeFunction
fixes the problem:Removing the
t.Parallel()
fixes the problem as well.Switching the order of false and true (i.e. false first and true second) also switches the line that is displayed as not being covered.
The text was updated successfully, but these errors were encountered: