Skip to content

Commit b6544a2

Browse files
committed
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 <[email protected]> TryBot-Result: Gobot Gobot <[email protected]> Reviewed-by: Rob Pike <[email protected]>
1 parent 0ff9df6 commit b6544a2

File tree

4 files changed

+24
-1
lines changed

4 files changed

+24
-1
lines changed

src/cmd/go/go_test.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2612,6 +2612,14 @@ func TestCoverageDepLoop(t *testing.T) {
26122612
tg.grepStdout("coverage: 100.0% of statements", "expected 100.0% coverage")
26132613
}
26142614

2615+
func TestCoverageNoStatements(t *testing.T) {
2616+
tooSlow(t)
2617+
tg := testgo(t)
2618+
defer tg.cleanup()
2619+
tg.run("test", "-cover", "./testdata/testcover/pkg4")
2620+
tg.grepStdout("[no statements]", "expected [no statements] for pkg4")
2621+
}
2622+
26152623
func TestCoverageImportMainLoop(t *testing.T) {
26162624
skipIfGccgo(t, "gccgo has no cover tool")
26172625
tg := testgo(t)
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package pkg4
2+
3+
type T struct {
4+
X bool
5+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package pkg4
2+
3+
import (
4+
"testing"
5+
)
6+
7+
func TestT(t *testing.T) {
8+
_ = T{}
9+
}

src/testing/cover.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,8 @@ func coverReport() {
109109
}
110110
}
111111
if total == 0 {
112-
total = 1
112+
fmt.Println("coverage: [no statements]")
113+
return
113114
}
114115
fmt.Printf("coverage: %.1f%% of statements%s\n", 100*float64(active)/float64(total), cover.CoveredPackages)
115116
}

0 commit comments

Comments
 (0)