-
Notifications
You must be signed in to change notification settings - Fork 17.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
cmd/go: fix problems with coverage percentage reporting w/ -coverpkg
This patch resolves a set of problems with "percent covered" metrics reported when the "-coverpkg" is in effect; these bugs were introduced in Go 1.22 with the rollout of CL 495452 and related changes. Specifically, for runs with multiple packages selected but without -coverpkg, "percent covered" metrics were generated for package P not based just on P's statements but on the entire corpus of statements. Fixes #65570. Change-Id: I38d61886cb46ebd38d8c4313c326d671197c3568 Reviewed-on: https://go-review.googlesource.com/c/go/+/592205 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Michael Matloob <matloob@golang.org>
- Loading branch information
Showing
5 changed files
with
87 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
# Without -coverpkg, we should get the same value for a given | ||
# package regardless of how many other packages are selected | ||
# (see issue 65570). | ||
|
||
[short] skip | ||
|
||
go test -count=1 -cover ./a ./b ./main | ||
stdout '^ok\s+M/main\s+\S+\s+coverage: 75.0% of statements' | ||
go test -count=1 -cover ./main | ||
stdout '^ok\s+M/main\s+\S+\s+coverage: 75.0% of statements' | ||
|
||
-- go.mod -- | ||
module M | ||
|
||
go 1.21 | ||
-- a/a.go -- | ||
package a | ||
|
||
func AFunc() int { | ||
return 42 | ||
} | ||
-- b/b.go -- | ||
package b | ||
|
||
func BFunc() int { | ||
return -42 | ||
} | ||
-- main/main.go -- | ||
package main | ||
|
||
import ( | ||
"M/a" | ||
) | ||
|
||
func MFunc() string { | ||
return "42" | ||
} | ||
|
||
func M2Func() int { | ||
return a.AFunc() | ||
} | ||
|
||
func init() { | ||
println("package 'main' init") | ||
} | ||
|
||
func main() { | ||
println(a.AFunc()) | ||
} | ||
-- main/main_test.go -- | ||
package main | ||
|
||
import "testing" | ||
|
||
func TestMain(t *testing.T) { | ||
if MFunc() != "42" { | ||
t.Fatalf("bad!") | ||
} | ||
if M2Func() != 42 { | ||
t.Fatalf("also bad!") | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters