Commit 08270c3e authored by Russ Cox's avatar Russ Cox

cmd/cover: do not report coverage for assembly functions

cover -func mode was reporting a coverage for function
declarations without bodies - assembly functions.
Since we are not annotating their code, we have no data
for those functions and should not report them at all.

Fixes #6880.

Change-Id: I4b8cd90805accf61f54e3ee167f54f4dc10c7c59
Reviewed-on: https://go-review.googlesource.com/77152Reviewed-by: 's avatarIan Lance Taylor <iant@golang.org>
parent 2a39d1e9
......@@ -113,6 +113,10 @@ type FuncVisitor struct {
func (v *FuncVisitor) Visit(node ast.Node) ast.Visitor {
switch n := node.(type) {
case *ast.FuncDecl:
if n.Body == nil {
// Do not count declarations of assembly functions.
break
}
start := v.fset.Position(n.Pos())
end := v.fset.Position(n.End())
fe := &FuncExtent{
......
......@@ -2457,6 +2457,19 @@ func TestCoverageErrorLine(t *testing.T) {
}
}
func TestCoverageFunc(t *testing.T) {
tg := testgo(t)
defer tg.cleanup()
tg.parallel()
tg.makeTempdir()
tg.setenv("GOPATH", filepath.Join(tg.pwd(), "testdata"))
tg.run("test", "-coverprofile="+filepath.Join(tg.tempdir, "cover.out"), "coverasm")
tg.run("tool", "cover", "-func="+filepath.Join(tg.tempdir, "cover.out"))
tg.grepStdout(`\tg\t*100.0%`, "did not find g 100% covered")
tg.grepStdoutNot(`\tf\t*[0-9]`, "reported coverage for assembly function f")
}
func TestPluginNonMain(t *testing.T) {
wd, err := os.Getwd()
if err != nil {
......
package p
func f()
func g() {
println("g")
}
// empty asm file,
// so go test doesn't complain about declaration of f in p.go.
package p
import "testing"
func Test(t *testing.T) {
g()
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment