From fd050c425070cea297198935e7a11af5d6039865 Mon Sep 17 00:00:00 2001 From: Abhinav Gupta Date: Sat, 23 Aug 2025 13:29:27 -0700 Subject: [PATCH] all: use modern Go syntax (e.g. any instead of interface{}) This change was generated by running: ``` go run golang.org/x/tools/gopls/internal/analysis/modernize/cmd/modernize@latest -fix -test ./... ``` Two things are changed: - All `interface{}` types are changed to `any`. This has been available since Go 1.18. - Stops capturing loop variables for closures inside loops. This has been unnecessary since Go 1.22. (https://go.dev/blog/loopvar-preview) --- autogold.go | 2 +- diff.go | 2 +- expect.go | 10 +++++----- expect_test.go | 2 -- parallel_test.go | 1 - 5 files changed, 7 insertions(+), 10 deletions(-) diff --git a/autogold.go b/autogold.go index 5c1f364..d2a0196 100644 --- a/autogold.go +++ b/autogold.go @@ -46,7 +46,7 @@ func update() bool { // // If the input value is of type Raw, its contents will be directly used instead of the value being // formatted as a Go literal. -func ExpectFile(t *testing.T, got interface{}, opts ...Option) { +func ExpectFile(t *testing.T, got any, opts ...Option) { dir := testdataDir(opts) fileName := testName(t, opts) outFile := filepath.Join(dir, fileName+".golden") diff --git a/diff.go b/diff.go index a954513..2992c68 100644 --- a/diff.go +++ b/diff.go @@ -17,7 +17,7 @@ func diff(got, want string, opts []Option) string { // Raw denotes a raw string. type Raw string -func stringify(v interface{}, opts []Option) string { +func stringify(v any, opts []Option) string { var ( allowRaw, trailingNewline bool valastOpt = &valast.Options{} diff --git a/expect.go b/expect.go index 09c3057..93f4f97 100644 --- a/expect.go +++ b/expect.go @@ -25,15 +25,15 @@ import ( // Value describes a desired value for a Go test, see Expect for more information. type Value interface { // Equal checks if `got` matches the desired test value, invoking t.Fatal otherwise. - Equal(t *testing.T, got interface{}, opts ...Option) + Equal(t *testing.T, got any, opts ...Option) } type value struct { line int - equal func(t *testing.T, got interface{}, opts ...Option) + equal func(t *testing.T, got any, opts ...Option) } -func (v value) Equal(t *testing.T, got interface{}, opts ...Option) { +func (v value) Equal(t *testing.T, got any, opts ...Option) { t.Helper() v.equal(t, got, opts...) } @@ -90,11 +90,11 @@ find: // When `-update` is specified, autogold will find and replace in the test file by looking for an // invocation of `autogold.Expect(...)` at the same line as the callstack indicates for this function // call, rewriting the `want` value parameter for you. -func Expect(want interface{}) Value { +func Expect(want any) Value { _, _, line, _ := runtime.Caller(1) return value{ line: line, - equal: func(t *testing.T, got interface{}, opts ...Option) { + equal: func(t *testing.T, got any, opts ...Option) { t.Helper() var ( profGetPackageNameAndPath time.Duration diff --git a/expect_test.go b/expect_test.go index e1db47b..cc295ee 100644 --- a/expect_test.go +++ b/expect_test.go @@ -163,7 +163,6 @@ func Test_replaceExpect_multiple(t *testing.T) { } for _, r := range replacements { - r := r _, err := replaceExpect(t, tmpFile, r.testName, r.line, r.replacement, true) if err != nil { t.Log("\ngot:\n", err, "\nwant:\n", err) @@ -244,7 +243,6 @@ func testEqualSubtestSameNames(t *testing.T) { } for _, name := range testTable { - name := name t.Run(name, func(t *testing.T) { // Subtests are intentionally not run in parallel, as that makes this issue more easily reproducible diff --git a/parallel_test.go b/parallel_test.go index 975228c..81de2d3 100644 --- a/parallel_test.go +++ b/parallel_test.go @@ -23,7 +23,6 @@ func testParallel(t *testing.T, prefix string) { } for _, name := range testTable { - name := name t.Run(name, func(t *testing.T) { t.Parallel()