Skip to content

Commit 6a3ee21

Browse files
abhinavemidoots
andauthored
all: use modern Go syntax (e.g. any instead of interface{}) (#59)
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) Co-authored-by: Emi <emi@hexops.com>
1 parent 1eb963d commit 6a3ee21

5 files changed

Lines changed: 7 additions & 10 deletions

File tree

autogold.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ func update() bool {
4545
//
4646
// If the input value is of type Raw, its contents will be directly used instead of the value being
4747
// formatted as a Go literal.
48-
func ExpectFile(t *testing.T, got interface{}, opts ...Option) {
48+
func ExpectFile(t *testing.T, got any, opts ...Option) {
4949
t.Helper()
5050
dir := testdataDir(opts)
5151
fileName := testName(t, opts)

diff.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ func diff(got, want string, opts []Option) string {
1717
// Raw denotes a raw string.
1818
type Raw string
1919

20-
func stringify(v interface{}, opts []Option) string {
20+
func stringify(v any, opts []Option) string {
2121
var (
2222
allowRaw, trailingNewline bool
2323
valastOpt = &valast.Options{}

expect.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,15 @@ import (
2424
// Value describes a desired value for a Go test, see Expect for more information.
2525
type Value interface {
2626
// Equal checks if `got` matches the desired test value, invoking t.Fatal otherwise.
27-
Equal(t *testing.T, got interface{}, opts ...Option)
27+
Equal(t *testing.T, got any, opts ...Option)
2828
}
2929

3030
type value struct {
3131
line int
32-
equal func(t *testing.T, got interface{}, opts ...Option)
32+
equal func(t *testing.T, got any, opts ...Option)
3333
}
3434

35-
func (v value) Equal(t *testing.T, got interface{}, opts ...Option) {
35+
func (v value) Equal(t *testing.T, got any, opts ...Option) {
3636
t.Helper()
3737
v.equal(t, got, opts...)
3838
}
@@ -88,11 +88,11 @@ find:
8888
// When `-update` is specified, autogold will find and replace in the test file by looking for an
8989
// invocation of `autogold.Expect(...)` at the same line as the callstack indicates for this function
9090
// call, rewriting the `want` value parameter for you.
91-
func Expect(want interface{}) Value {
91+
func Expect(want any) Value {
9292
_, _, line, _ := runtime.Caller(1)
9393
return value{
9494
line: line,
95-
equal: func(t *testing.T, got interface{}, opts ...Option) {
95+
equal: func(t *testing.T, got any, opts ...Option) {
9696
t.Helper()
9797
var (
9898
profGetPackageNameAndPath time.Duration

expect_test.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,6 @@ func Test_replaceExpect_multiple(t *testing.T) {
163163
}
164164

165165
for _, r := range replacements {
166-
r := r
167166
_, err := replaceExpect(t, tmpFile, r.testName, r.line, r.replacement, true)
168167
if err != nil {
169168
t.Log("\ngot:\n", err, "\nwant:\n", err)
@@ -244,7 +243,6 @@ func testEqualSubtestSameNames(t *testing.T) {
244243
}
245244

246245
for _, name := range testTable {
247-
name := name
248246

249247
t.Run(name, func(t *testing.T) {
250248
// Subtests are intentionally not run in parallel, as that makes this issue more easily reproducible

parallel_test.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ func testParallel(t *testing.T, prefix string) {
2323
}
2424

2525
for _, name := range testTable {
26-
name := name
2726

2827
t.Run(name, func(t *testing.T) {
2928
t.Parallel()

0 commit comments

Comments
 (0)