Go 1.26 https://go.dev/play/p/CSH38BByd-v?v=gotip func TestFoo(t *testing.T) { fmt.Println(t.ArtifactDir()) } // go test -artifacts 未指定 なら t.TempDir() と同様 // go test -artifacts <dirpath>指定あり なら 指定したパスが返される go test -artifactsフラグを設定しない場 合はt.TempDir()と同様にテンポラリの ディレクトリを返します。 go test -artifactsフラグを設定した場合 はそのディレクトリを返します。
// Go < 1.26 goplsのmodernizeを利用する場合 $ go run golang.org/x/tools/gopls/internal/analysis/modernize/cmd/modernize@latest -fix -test ./… // Go 1.26 go fixに統合 $ go fix ./… goplsのmodernizeやgofixをgoの標準 コマンドのfixで利用出来るようにする。 package pkg import pkg2 "pkg/v2" //go:fix inline func F() { pkg2.F(nil) } // Go < 1.26 goplsのfixを利用する場合 $ go run golang.org/x/tools/gopls/internal/analysis/gofix/cmd/gofix@latest -test ./... // Go 1.26 $ go fix ./… ? optionはどうなるか不明そのまま動く?
goplsのmodernize -fix -testと同等の機能がそのまま実装されそう https://pkg.go.dev/golang.org/x/tools/gopls/internal/analysis/modernize go fix -diff で 実際にfixせずにdiffのみ表示する機能を提供予定 • forvar: remove x := x variable declarations made unnecessary by the new semantics of loops in go1.22. • slicescontains: replace 'for i, elem := range s { if elem == needle { ...; break }' by a call to slices.Contains, added in go1.21. • minmax: replace an if/else conditional assignment by a call to the built-in min or max functions added in go1.21. • sortslice: replace sort.Slice(s, func(i, j int) bool) { return s[i] < s[j] } by a call to slices.Sort(s), added in go1.21. • efaceany: replace interface{} by the 'any' type added in go1.18. • mapsloop: replace a loop around an m[k]=v map update by a call to one of the Collect, Copy, Clone, or Insert functions from the maps package, added in go1.21. • fmtappendf: replace []byte(fmt.Sprintf...) by fmt.Appendf(nil, ...), added in go1.19.
• testingcontext: replace uses of context.WithCancel in tests with t.Context, added in go1.24. • omitzero: replace omitempty by omitzero on structs, added in go1.24. • bloop: replace "for i := range b.N" or "for range b.N" in a benchmark with "for b.Loop()", and remove any preceding calls to b.StopTimer, b.StartTimer, and b.ResetTimer. B.Loop intentionally defeats compiler optimizations such as inlining so that the benchmark is not entirely optimized away. Currently, however, it may cause benchmarks to become slower in some cases due to increased allocation; see https://go.dev/issue/73137. • rangeint: replace a 3-clause "for i := 0; i < n; i++" loop by "for i := range n", added in go1.22. • stringsseq: replace Split in "for range strings.Split(...)" by go1.24's more efficient SplitSeq, or Fields with FieldSeq. • stringscutprefix: replace some uses of HasPrefix followed by TrimPrefix with CutPrefix, added to the strings package in go1.20. • waitgroup: replace old complex usages of sync.WaitGroup by less complex WaitGroup.Go method in go1.25.