Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.Sign up
GitHub is where the world builds software
Millions of developers and companies build, ship, and maintain their software on GitHub — the largest and most advanced development platform in the world.
cmd/cover: incomplete coverage when using goto #16624
I looked into this for a while because it was biting me as well. Not being familiar with the code I wasn't able to create a quick fix but here's what I learned.
The shortcoming is in how labeled statements are handled. The logic is all there for statements that can be departure points for control flow (i.e., goto statements are not the problem), but the logic is missing for statements that can be arrival points for control flow (i.e., labeled statements are the problem).
The problem can be understood by considering a labeled statement that can itself affect control flow:
The instrumentation must insert a counter between the label and the statement, but this is delicate surgery because in the ast representation the label contains the statement. The label could be removed from the flowChangingStmt and attached to an immediately preceding new counter statement. However, labeled 'for','switch',or 'select' statements must not have their label removed. It may be that the 'for', 'switch', and 'select' statements are not harmed by the lack of a counter between the label and the statement, so inserting the counter and re-attaching the label may only be necessary for non-'for','switch','select' statements.
I hope this helps. Unfortunately I don't have time to dig deeper. An example file and its as-presently-created cover rewrite are shown below.