mirror of
https://github.com/golang/go
synced 2024-11-19 20:54:39 -07:00
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/77152 Reviewed-by: Ian Lance Taylor <iant@golang.org>
This commit is contained in:
parent
2a39d1e96a
commit
08270c3e18
@ -113,6 +113,10 @@ type FuncVisitor struct {
|
|||||||
func (v *FuncVisitor) Visit(node ast.Node) ast.Visitor {
|
func (v *FuncVisitor) Visit(node ast.Node) ast.Visitor {
|
||||||
switch n := node.(type) {
|
switch n := node.(type) {
|
||||||
case *ast.FuncDecl:
|
case *ast.FuncDecl:
|
||||||
|
if n.Body == nil {
|
||||||
|
// Do not count declarations of assembly functions.
|
||||||
|
break
|
||||||
|
}
|
||||||
start := v.fset.Position(n.Pos())
|
start := v.fset.Position(n.Pos())
|
||||||
end := v.fset.Position(n.End())
|
end := v.fset.Position(n.End())
|
||||||
fe := &FuncExtent{
|
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) {
|
func TestPluginNonMain(t *testing.T) {
|
||||||
wd, err := os.Getwd()
|
wd, err := os.Getwd()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
7
src/cmd/go/testdata/src/coverasm/p.go
vendored
Normal file
7
src/cmd/go/testdata/src/coverasm/p.go
vendored
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
package p
|
||||||
|
|
||||||
|
func f()
|
||||||
|
|
||||||
|
func g() {
|
||||||
|
println("g")
|
||||||
|
}
|
2
src/cmd/go/testdata/src/coverasm/p.s
vendored
Normal file
2
src/cmd/go/testdata/src/coverasm/p.s
vendored
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
// empty asm file,
|
||||||
|
// so go test doesn't complain about declaration of f in p.go.
|
7
src/cmd/go/testdata/src/coverasm/p_test.go
vendored
Normal file
7
src/cmd/go/testdata/src/coverasm/p_test.go
vendored
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
package p
|
||||||
|
|
||||||
|
import "testing"
|
||||||
|
|
||||||
|
func Test(t *testing.T) {
|
||||||
|
g()
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user