golang/go

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

已關閉

#79,647 建立於 2026年5月25日

 (2 則留言) (1 個反應) (0 位負責人)Go (19,008 個分叉)batch import
Toolsgoplshelp wanted

倉庫指標

星標
 (133,883 顆星)
PR 合併指標
 (30 天內沒有已合併 PR)

描述

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.

貢獻者指南