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

x/tools/cmd/cover: for increment statement is not covered #10467

Closed
dvyukov opened this issue Apr 15, 2015 · 1 comment
Closed

x/tools/cmd/cover: for increment statement is not covered #10467

dvyukov opened this issue Apr 15, 2015 · 1 comment
Milestone

Comments

@dvyukov
Copy link
Member

dvyukov commented Apr 15, 2015

cover instruments the following program:

func foo() {
    type Node struct {
        next *Node
        v int
    }
    for p := new(Node); p != nil; p = p.next {
        println("here")
        if p.v == 0 {
            break
        }
    }
}

as:

func foo() {
    GoCover.Count[0] = 1
    type Node struct {
        next    *Node
        v   int
    }
    for p := new(Node); p != nil; p = p.next {
        GoCover.Count[1] = 1
        println("here")
        if p.v == 0 {
            GoCover.Count[2] = 1
            break
        }
    }
}

As the result it is not possible to understand whether 'p = p.next' statement covered or not.

One way to fix it would be to emit coverage instrumentation before continue statements and at loop end. For example, in this case the following would do:

    for p := new(Node); p != nil; p = p.next {
        GoCover.Count[1] = 1
        println("here")
        if p.v == 0 {
            GoCover.Count[2] = 1
            break
        }
        GoCover.Count[3] = 1
    }
@dvyukov dvyukov added this to the Go1.5 milestone Apr 15, 2015
@dvyukov dvyukov changed the title cmd/cover: for increment statement is not covered x/tools/cmd/cover: for increment statement is not covered Apr 15, 2015
@robpike
Copy link
Contributor

robpike commented Apr 15, 2015

A known and minor weakness of the source-oriented design. I do not intend to fix this.

@robpike robpike closed this as completed Apr 15, 2015
@golang golang locked and limited conversation to collaborators Jun 25, 2016
@rsc rsc unassigned robpike Jun 23, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants