...
Text file
src/cmd/go/testdata/script/cover_coverprofile_multipkg.txt
1
2# Testcase for #63356. In this bug we're doing a "go test -coverprofile"
3# run for a collection of packages, mostly independent (hence tests can
4# be done in parallel) and in the original bug, temp coverage profile
5# files were not being properly qualified and were colliding, resulting
6# in a corrupted final profile. Actual content of the packages doesn't
7# especially matter as long as we have a mix of packages with tests and
8# multiple packages without tests.
9
10[short] skip
11
12# Kick off test.
13go test -p=10 -vet=off -count=1 -coverprofile=cov.p ./...
14
15# Make sure resulting profile is digestible.
16go tool cover -func=cov.p
17
18# No extraneous extra files please.
19! exists _cover_.out
20
21-- a/a.go --
22package a
23
24func init() {
25 println("package 'a' init: launch the missiles!")
26}
27
28func AFunc() int {
29 return 42
30}
31-- a/a_test.go --
32package a
33
34import "testing"
35
36func TestA(t *testing.T) {
37 if AFunc() != 42 {
38 t.Fatalf("bad!")
39 }
40}
41-- aa/aa.go --
42package aa
43
44import "M/it"
45
46func AA(y int) int {
47 c := it.Conc{}
48 x := it.Callee(&c)
49 println(x, y)
50 return 0
51}
52-- aa/aa_test.go --
53package aa
54
55import "testing"
56
57func TestMumble(t *testing.T) {
58 AA(3)
59}
60-- b/b.go --
61package b
62
63func init() {
64 println("package 'b' init: release the kraken")
65}
66
67func BFunc() int {
68 return -42
69}
70-- b/b_test.go --
71package b
72
73import "testing"
74
75func TestB(t *testing.T) {
76 if BFunc() != -42 {
77 t.Fatalf("bad!")
78 }
79}
80-- deadstuff/deadstuff.go --
81package deadstuff
82
83func downStreamOfPanic(x int) {
84 panic("bad")
85 if x < 10 {
86 println("foo")
87 }
88}
89-- deadstuff/deadstuff_test.go --
90package deadstuff
91
92import "testing"
93
94func TestMumble(t *testing.T) {
95 defer func() {
96 if x := recover(); x != nil {
97 println("recovered")
98 }
99 }()
100 downStreamOfPanic(10)
101}
102-- go.mod --
103module M
104
105go 1.21
106-- it/it.go --
107package it
108
109type Ctr interface {
110 Count() int
111}
112
113type Conc struct {
114 X int
115}
116
117func (c *Conc) Count() int {
118 return c.X
119}
120
121func DoCall(c *Conc) {
122 c2 := Callee(c)
123 println(c2.Count())
124}
125
126func Callee(ii Ctr) Ctr {
127 q := ii.Count()
128 return &Conc{X: q}
129}
130-- main/main.go --
131package main
132
133import (
134 "M/a"
135 "M/b"
136)
137
138func MFunc() string {
139 return "42"
140}
141
142func M2Func() int {
143 return a.AFunc() + b.BFunc()
144}
145
146func init() {
147 println("package 'main' init")
148}
149
150func main() {
151 println(a.AFunc() + b.BFunc())
152}
153-- main/main_test.go --
154package main
155
156import "testing"
157
158func TestMain(t *testing.T) {
159 if MFunc() != "42" {
160 t.Fatalf("bad!")
161 }
162 if M2Func() != 0 {
163 t.Fatalf("also bad!")
164 }
165}
166-- n/n.go --
167package n
168
169type N int
170-- onlytest/mumble_test.go --
171package onlytest
172
173import "testing"
174
175func TestFoo(t *testing.T) {
176 t.Logf("Whee\n")
177}
178-- x/x.go --
179package x
180
181func XFunc() int {
182 return 2 * 2
183}
184-- xinternal/i.go --
185package i
186
187func I() int { return 32 }
188-- xinternal/q/q.go --
189package q
190
191func Q() int {
192 return 42
193}
View as plain text