Skip to content
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: inconsistent treatment of comments #22545

Open
alandonovan opened this issue Nov 2, 2017 · 1 comment

Comments

@alandonovan
Copy link
Contributor

commented Nov 2, 2017

Run coverage on the following program using these commands:

$ cd $GOROOT/src/test
$ cat test.go
package test

func f() {
        if true {
                println("A")
        }
        // comment
        if true {
                // comment
                if false {
                        println("B")
                }
        } else {
                // comment
                println("D")
        }
}
$ cat test_test.go 
package test

import "testing"

func Test(t *testing.T) { f() }
$ go test -coverprofile=c.out test
ok      test    0.015s  coverage: 66.7% of statements
$ command go tool cover -html=c.out

This is the rendered HTML output:

coverage

Observe that the first comment is grey, not green, even though it was covered. Is this a simple bookkeeping error, or is there a design reason why we shouldn't consider the entire span from func f() { up to if false as covered, and render it green?

(This is Google internal issue 68650370.)

@dsymonds

This comment has been minimized.

Copy link
Member

commented May 28, 2018

I've been observing this and similar. Comments and function headers (the bit before the opening brace) should be grey, because they are not executable statements. (I shouldn't decrease my code's coverage simply by adding a bunch more comments, for instance.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants
You can’t perform that action at this time.