| 1 |
# Without -coverpkg, we should get the same value for a given |
| 2 |
# package regardless of how many other packages are selected |
| 3 |
# (see issue 65570). |
| 4 |
|
| 5 |
[short] skip |
| 6 |
|
| 7 |
go test -count=1 -cover ./a ./b ./main |
| 8 |
stdout '^ok\s+M/main\s+\S+\s+coverage: 75.0% of statements' |
| 9 |
go test -count=1 -cover ./main |
| 10 |
stdout '^ok\s+M/main\s+\S+\s+coverage: 75.0% of statements' |
| 11 |
|
| 12 |
-- go.mod -- |
| 13 |
module M |
| 14 |
|
| 15 |
go 1.21 |
| 16 |
-- a/a.go -- |
| 17 |
package a |
| 18 |
|
| 19 |
func AFunc() int { |
| 20 |
return 42 |
| 21 |
} |
| 22 |
-- b/b.go -- |
| 23 |
package b |
| 24 |
|
| 25 |
func BFunc() int { |
| 26 |
return -42 |
| 27 |
} |
| 28 |
-- main/main.go -- |
| 29 |
package main |
| 30 |
|
| 31 |
import ( |
| 32 |
"M/a" |
| 33 |
) |
| 34 |
|
| 35 |
func MFunc() string { |
| 36 |
return "42" |
| 37 |
} |
| 38 |
|
| 39 |
func M2Func() int { |
| 40 |
return a.AFunc() |
| 41 |
} |
| 42 |
|
| 43 |
func init() { |
| 44 |
println("package 'main' init") |
| 45 |
} |
| 46 |
|
| 47 |
func main() { |
| 48 |
println(a.AFunc()) |
| 49 |
} |
| 50 |
-- main/main_test.go -- |
| 51 |
package main |
| 52 |
|
| 53 |
import "testing" |
| 54 |
|
| 55 |
func TestMain(t *testing.T) { |
| 56 |
if MFunc() != "42" { |
| 57 |
t.Fatalf("bad!") |
| 58 |
} |
| 59 |
if M2Func() != 42 { |
| 60 |
t.Fatalf("also bad!") |
| 61 |
} |
| 62 |
} |
| 63 |
|