Skip to content

Commit 066484e

Browse files
adonovangopherbot
authored andcommitted
gopls/internal/test/integration/misc: test "annotations" setting
This CL adds a test that the "annotations" config setting is honored by the "Toggle compiler optimization details" setting. (The test resulted from the investigation of the comment at golang/go#71888 (comment).) Updates golang/go#71888 Change-Id: I002d945fe8883ecd2dc95a2d43c0ccf2aa93a2c2 Reviewed-on: https://go-review.googlesource.com/c/tools/+/658555 Reviewed-by: Robert Findley <[email protected]> Auto-Submit: Alan Donovan <[email protected]> LUCI-TryBot-Result: Go LUCI <[email protected]>
1 parent e06efb4 commit 066484e

File tree

1 file changed

+63
-0
lines changed

1 file changed

+63
-0
lines changed

gopls/internal/test/integration/misc/compileropt_test.go

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,3 +166,66 @@ func H(x int) any { return &x }
166166
)
167167
})
168168
}
169+
170+
// TestCompilerOptDetails_config exercises that the "want optimization
171+
// details" flag honors the "annotation" configuration setting.
172+
func TestCompilerOptDetails_config(t *testing.T) {
173+
if runtime.GOOS == "android" {
174+
t.Skipf("the compiler optimization details code action doesn't work on Android")
175+
}
176+
177+
const mod = `
178+
-- go.mod --
179+
module mod.com
180+
go 1.18
181+
182+
-- a/a.go --
183+
package a
184+
185+
func F(x int) any { return &x } // escape(x escapes to heap)
186+
func G() { defer func(){} () } // cannotInlineFunction(unhandled op DEFER)
187+
`
188+
189+
for _, escape := range []bool{true, false} {
190+
WithOptions(
191+
Settings{"annotations": map[string]any{"inline": true, "escape": escape}},
192+
).Run(t, mod, func(t *testing.T, env *Env) {
193+
env.OpenFile("a/a.go")
194+
actions := env.CodeActionForFile("a/a.go", nil)
195+
196+
docAction, err := codeActionByKind(actions, settings.GoToggleCompilerOptDetails)
197+
if err != nil {
198+
t.Fatal(err)
199+
}
200+
params := &protocol.ExecuteCommandParams{
201+
Command: docAction.Command.Command,
202+
Arguments: docAction.Command.Arguments,
203+
}
204+
env.ExecuteCommand(params, nil)
205+
206+
env.OnceMet(
207+
CompletedWork(server.DiagnosticWorkTitle(server.FromToggleCompilerOptDetails), 1, true),
208+
cond(escape, Diagnostics, NoDiagnostics)(
209+
ForFile("a/a.go"),
210+
AtPosition("a/a.go", 2, 7),
211+
WithMessage("x escapes to heap"),
212+
WithSeverityTags("optimizer details", protocol.SeverityInformation, nil),
213+
),
214+
Diagnostics(
215+
ForFile("a/a.go"),
216+
AtPosition("a/a.go", 3, 5),
217+
WithMessage("cannotInlineFunction(unhandled op DEFER)"),
218+
WithSeverityTags("optimizer details", protocol.SeverityInformation, nil),
219+
),
220+
)
221+
})
222+
}
223+
}
224+
225+
func cond[T any](cond bool, x, y T) T {
226+
if cond {
227+
return x
228+
} else {
229+
return y
230+
}
231+
}

0 commit comments

Comments
 (0)