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 go test -count=1 -cover ./a ./b ./main
6 stdout '^ok\s+M/main\s+\S+\s+coverage: 75.0% of statements'
7 go test -count=1 -cover ./main
8 stdout '^ok\s+M/main\s+\S+\s+coverage: 75.0% of statements'
9
10 -- go.mod --
11 module M
12
13 go 1.21
14 -- a/a.go --
15 package a
16
17 func AFunc() int {
18 return 42
19 }
20 -- b/b.go --
21 package b
22
23 func BFunc() int {
24 return -42
25 }
26 -- main/main.go --
27 package main
28
29 import (
30 "M/a"
31 )
32
33 func MFunc() string {
34 return "42"
35 }
36
37 func M2Func() int {
38 return a.AFunc()
39 }
40
41 func init() {
42 println("package 'main' init")
43 }
44
45 func main() {
46 println(a.AFunc())
47 }
48 -- main/main_test.go --
49 package main
50
51 import "testing"
52
53 func TestMain(t *testing.T) {
54 if MFunc() != "42" {
55 t.Fatalf("bad!")
56 }
57 if M2Func() != 42 {
58 t.Fatalf("also bad!")
59 }
60 }
61
62
View as plain text