Skip to content

cmd/cover: inconsistent treatment of comments #22545

@alandonovan

Description

@alandonovan

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.)

Metadata

Metadata

Assignees

No one assigned

    Labels

    NeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.compiler/runtimeIssues related to the Go compiler and/or runtime.help wanted

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions