Debian Codegraph @

go/analysis/passes/inline/testdata/src/issue76190.txtar

raw
1 This test checks that calls are not inlined when the call appears in a specific
2 test of the function. (Even deprecated functions deserve tests.)
3
4 A test is specific if either:
5 - it is named for the symbol (e.g TestF -> F) (#76190), or
6 - its filename a_test.go matches the declaring file a.go (#79272).
7
8 Symbol name variants:
9 - functions (TestF) vs methods (TestT_F)
10 - optional comment suffixes (TestSYMBOL_comment)
11 - in-package test vs external test
12 - test of same or different package from symbol
13
14 -- go.mod --
15 module example.com
16
17 -- a/a.go --
18 package a
19
20 //go:fix inline
21 func F() { print("F") } // want F:"goFixInline a.F"
22 //go:fix inline
23 func G() { print("G") } // want G:"goFixInline a.G"
24
25 type T int
26 //go:fix inline
27 func (T) F() { print("T.F") } // want F:`goFixInline \(a.T\).F`
28 //go:fix inline
29 func (T) G() { print("T.G") } // want G:`goFixInline \(a.T\).G`
30
31 //go:fix inline
32 type A = T // want A:`goFixInline alias`
33
34 //go:fix inline
35 const K = One // want K:`goFixInline const "example.com/a".One`
36
37 const One = 1
38
39 -- a/a_test.go --
40 package a
41
42 import "testing"
43
44 func TestWithAnyName(t *testing.T) {
45 F() // not inlined
46 G() // not inlined
47 print(K) // not inlined
48 var _ A // not inlined
49 }
50
51 -- a/other_test.go --
52 package a
53
54 import "testing"
55
56 func Test(t *testing.T) {
57 F() // want "Call of a.F should be inlined"
58 G() // want "Call of a.G should be inlined"
59 print(K) // want "Constant K should be inlined"
60 var _ A // want "Type alias A should be inlined"
61 }
62
63 func TestG_comment(t *testing.T) {
64 F() // want "Call of a.F should be inlined"
65 G() // not inlined
66 }
67
68 func TestT_F(t *testing.T) {
69 T(0).F() // not inlined
70 T(0).G() // want `Call of \(a.T\).G should be inlined`
71 }
72
73 func TestT_G(t *testing.T) {
74 T(0).F() // want `Call of \(a.T\).F should be inlined`
75 T(0).G() // not inlined
76 }
77
78 func TestK(t *testing.T) {
79 print(K) // not inlined
80 }
81
82 func TestA(t *testing.T) {
83 var _ A // not inlined
84 }
85
86 -- a/a_test.go.golden --
87 package a
88
89 import "testing"
90
91 func TestF(t *testing.T) {
92 F() // not inlined
93 print("G") // want "Call of a.G should be inlined"
94 }
95
96 func TestG_comment(t *testing.T) {
97 print("F") // want "Call of a.F should be inlined"
98 G() // not inlined
99 }
100
101 func TestT_F(t *testing.T) {
102 T(0).F() // not inlined
103 print("T.G") // want `Call of \(a.T\).G should be inlined`
104 }
105
106 func TestT_G(t *testing.T) {
107 print("T.F") // want `Call of \(a.T\).F should be inlined`
108 T(0).G() // not inlined
109 }
110
111 -- a/other_test.go.golden --
112 package a
113
114 import "testing"
115
116 func Test(t *testing.T) {
117 print("F") // want "Call of a.F should be inlined"
118 print("G") // want "Call of a.G should be inlined"
119 print(One) // want "Constant K should be inlined"
120 var _ T // want "Type alias A should be inlined"
121 }
122
123 func TestG_comment(t *testing.T) {
124 print("F") // want "Call of a.F should be inlined"
125 G() // not inlined
126 }
127
128 func TestT_F(t *testing.T) {
129 T(0).F() // not inlined
130 print("T.G") // want `Call of \(a.T\).G should be inlined`
131 }
132
133 func TestT_G(t *testing.T) {
134 print("T.F") // want `Call of \(a.T\).F should be inlined`
135 T(0).G() // not inlined
136 }
137
138 func TestK(t *testing.T) {
139 print(K) // not inlined
140 }
141
142 func TestA(t *testing.T) {
143 var _ A // not inlined
144 }
145
146 -- a/a_x_test.go --
147 package a_test
148
149 import (
150 "example.com/a"
151 "testing"
152 )
153
154 func TestF(t *testing.T) {
155 a.F() // not inlined
156 a.G() // want "Call of a.G should be inlined"
157 }
158
159 func TestG_comment(t *testing.T) {
160 a.F() // want "Call of a.F should be inlined"
161 a.G() // not inlined
162 }
163
164 func TestT_F(t *testing.T) {
165 a.T(0).F() // not inlined
166 a.T(0).G() // want `Call of \(a.T\).G should be inlined`
167 }
168
169 func TestT_G(t *testing.T) {
170 a.T(0).F() // want `Call of \(a.T\).F should be inlined`
171 a.T(0).G() // not inlined
172 }
173
174 -- a/a_x_test.go.golden --
175 package a_test
176
177 import (
178 "example.com/a"
179 "testing"
180 )
181
182 func TestF(t *testing.T) {
183 a.F() // not inlined
184 print("G") // want "Call of a.G should be inlined"
185 }
186
187 func TestG_comment(t *testing.T) {
188 print("F") // want "Call of a.F should be inlined"
189 a.G() // not inlined
190 }
191
192 func TestT_F(t *testing.T) {
193 a.T(0).F() // not inlined
194 print("T.G") // want `Call of \(a.T\).G should be inlined`
195 }
196
197 func TestT_G(t *testing.T) {
198 print("T.F") // want `Call of \(a.T\).F should be inlined`
199 a.T(0).G() // not inlined
200 }
201
202 -- b/b_test.go --
203 package b_test
204
205 import (
206 "example.com/a"
207 "testing"
208 )
209
210 func TestF(t *testing.T) {
211 a.F() // want "Call of a.F should be inlined"
212 }
213
214 -- b/b_test.go.golden --
215 package b_test
216
217 import (
218 "testing"
219 )
220
221 func TestF(t *testing.T) {
222 print("F") // want "Call of a.F should be inlined"
223 }