golang/go

x/tools/gopls: source.addTest: emit t.Context() when module is Go 1.24+

Geschlossen

#79.647 geöffnet am 25.05.2026

 (2 Kommentare) (1 Reaktion) (0 zugewiesene Personen)Go (19.008 Forks)batch import
Toolsgoplshelp wanted

Repository-Metriken

Stars
 (133.883 Sterne)
PR-Merge-Metriken
 (Keine gemergten PRs in 30 T)

Beschreibung

Proposal

The source.addTest code action ("Add test for FUNC") passes context.Background() whenever the function under test takes context.Context as its first parameter:

got := a.Foo(context.Background(), tt.in)

When the module's go.mod declares Go 1.24 or later, the generated scaffolding should use t.Context() instead:

got := a.Foo(t.Context(), tt.in)

Implementation

I have a draft CL ready. It gates on versions.AtLeast(fileVersion, versions.Go1_24); older modules keep the current context.Background() behavior.

Contributor Guide