1
0
mirror of https://github.com/golang/go synced 2024-09-30 01:24:33 -06:00

testing/cover: improve message when a package has no statements

Fixes #25492

Change-Id: Ic1496857524dad0c0a77f3bb80fa084c9bf00aa9
Reviewed-on: https://go-review.googlesource.com/c/go/+/155777
Run-TryBot: Agniva De Sarker <agniva.quicksilver@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rob Pike <r@golang.org>
This commit is contained in:
Agniva De Sarker 2018-12-23 15:01:11 +05:30 committed by Agniva De Sarker
parent 0ff9df6b53
commit b6544a2a87
4 changed files with 24 additions and 1 deletions

View File

@ -2612,6 +2612,14 @@ func TestCoverageDepLoop(t *testing.T) {
tg.grepStdout("coverage: 100.0% of statements", "expected 100.0% coverage")
}
func TestCoverageNoStatements(t *testing.T) {
tooSlow(t)
tg := testgo(t)
defer tg.cleanup()
tg.run("test", "-cover", "./testdata/testcover/pkg4")
tg.grepStdout("[no statements]", "expected [no statements] for pkg4")
}
func TestCoverageImportMainLoop(t *testing.T) {
skipIfGccgo(t, "gccgo has no cover tool")
tg := testgo(t)

View File

@ -0,0 +1,5 @@
package pkg4
type T struct {
X bool
}

View File

@ -0,0 +1,9 @@
package pkg4
import (
"testing"
)
func TestT(t *testing.T) {
_ = T{}
}

View File

@ -109,7 +109,8 @@ func coverReport() {
}
}
if total == 0 {
total = 1
fmt.Println("coverage: [no statements]")
return
}
fmt.Printf("coverage: %.1f%% of statements%s\n", 100*float64(active)/float64(total), cover.CoveredPackages)
}