Commit f7180362 authored by Rob Pike's avatar Rob Pike

cmd/go: fix bad error message in coverage for package without non-test files

Was checking for nil map; must check for empty map instead.

Fixes #6065

Before:

go test -cover
# testmain
/var/folders/00/013l0000h01000cxqpysvccm0004fc/T/go-build233480051/_/Users/r/issue/_test/_testmain.go:11: imported and not used: "_/Users/r/issue"
FAIL	_/Users/r/issue [build failed]

Now:

go test -cover
testing: warning: no tests to run
PASS
coverage: 0.0% of statements
ok  	_/Users/r/issue	0.021s

R=golang-dev, bradfitz
CC=golang-dev
https://golang.org/cl/12916043
parent 727b2b6f
...@@ -1010,7 +1010,7 @@ type coverInfo struct { ...@@ -1010,7 +1010,7 @@ type coverInfo struct {
func writeTestmain(out string, pmain, p *Package) error { func writeTestmain(out string, pmain, p *Package) error {
var cover []coverInfo var cover []coverInfo
for _, cp := range pmain.imports { for _, cp := range pmain.imports {
if cp.coverVars != nil { if len(cp.coverVars) > 0 {
cover = append(cover, coverInfo{cp, cp.coverVars}) cover = append(cover, coverInfo{cp, cp.coverVars})
} }
} }
......
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