Skip to content

Commit

Permalink
testing/cover: improve message when a package has no statements
Browse files Browse the repository at this point in the history
Fixes golang#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]>
  • Loading branch information
agnivade committed Mar 13, 2019
1 parent 0ff9df6 commit b6544a2
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 1 deletion.
8 changes: 8 additions & 0 deletions src/cmd/go/go_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
5 changes: 5 additions & 0 deletions src/cmd/go/testdata/testcover/pkg4/a.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package pkg4

type T struct {
X bool
}
9 changes: 9 additions & 0 deletions src/cmd/go/testdata/testcover/pkg4/a_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package pkg4

import (
"testing"
)

func TestT(t *testing.T) {
_ = T{}
}
3 changes: 2 additions & 1 deletion src/testing/cover.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

0 comments on commit b6544a2

Please sign in to comment.