From: Agniva De Sarker Date: Sun, 23 Dec 2018 09:31:11 +0000 (+0530) Subject: testing/cover: improve message when a package has no statements X-Git-Tag: go1.13beta1~1070 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=b6544a2a87b17f552c3ab4f7f0f082e48b56d5fa;p=gostls13.git 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 TryBot-Result: Gobot Gobot Reviewed-by: Rob Pike --- diff --git a/src/cmd/go/go_test.go b/src/cmd/go/go_test.go index f25d6f4503..60e02e7532 100644 --- a/src/cmd/go/go_test.go +++ b/src/cmd/go/go_test.go @@ -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) diff --git a/src/cmd/go/testdata/testcover/pkg4/a.go b/src/cmd/go/testdata/testcover/pkg4/a.go new file mode 100644 index 0000000000..cf09e6f1b0 --- /dev/null +++ b/src/cmd/go/testdata/testcover/pkg4/a.go @@ -0,0 +1,5 @@ +package pkg4 + +type T struct { + X bool +} diff --git a/src/cmd/go/testdata/testcover/pkg4/a_test.go b/src/cmd/go/testdata/testcover/pkg4/a_test.go new file mode 100644 index 0000000000..12b8685294 --- /dev/null +++ b/src/cmd/go/testdata/testcover/pkg4/a_test.go @@ -0,0 +1,9 @@ +package pkg4 + +import ( + "testing" +) + +func TestT(t *testing.T) { + _ = T{} +} diff --git a/src/testing/cover.go b/src/testing/cover.go index 17c03f5e5e..62ee5ac9c0 100644 --- a/src/testing/cover.go +++ b/src/testing/cover.go @@ -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) }