From: Tobias Klauser Date: Tue, 14 Oct 2025 09:40:26 +0000 (+0200) Subject: all: remove unnecessary loop variable copies in tests X-Git-Tag: go1.26rc1~591 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=b5aefe07e5afe2fd5d49c6a4219cc826b3e4e34e;p=gostls13.git all: remove unnecessary loop variable copies in tests Copying the loop variable is no longer necessary since Go 1.22. Change-Id: Iebb21dac44a20ec200567f1d786f105a4ee4999d Reviewed-on: https://go-review.googlesource.com/c/go/+/711640 Reviewed-by: Florian Lehner Auto-Submit: Damien Neil Reviewed-by: Dmitri Shuralyov Reviewed-by: Damien Neil Auto-Submit: Tobias Klauser LUCI-TryBot-Result: Go LUCI --- diff --git a/src/archive/zip/reader_test.go b/src/archive/zip/reader_test.go index 410b2d037e..cb8a0c2871 100644 --- a/src/archive/zip/reader_test.go +++ b/src/archive/zip/reader_test.go @@ -1213,7 +1213,6 @@ func TestFS(t *testing.T) { []string{"a/b/c"}, }, } { - test := test t.Run(test.file, func(t *testing.T) { t.Parallel() z, err := OpenReader(test.file) @@ -1247,7 +1246,6 @@ func TestFSWalk(t *testing.T) { wantErr: true, }, } { - test := test t.Run(test.file, func(t *testing.T) { t.Parallel() z, err := OpenReader(test.file) diff --git a/src/context/x_test.go b/src/context/x_test.go index 0cf19688c3..aeb5470399 100644 --- a/src/context/x_test.go +++ b/src/context/x_test.go @@ -838,7 +838,6 @@ func TestCause(t *testing.T) { cause: parentCause, }, } { - test := test t.Run(test.name, func(t *testing.T) { t.Parallel() ctx := test.ctx() diff --git a/src/crypto/cipher/ctr_aes_test.go b/src/crypto/cipher/ctr_aes_test.go index 3394246778..9b7d30e216 100644 --- a/src/crypto/cipher/ctr_aes_test.go +++ b/src/crypto/cipher/ctr_aes_test.go @@ -145,7 +145,6 @@ func TestCTR_AES_multiblock_random_IV(t *testing.T) { const Size = 100 for _, keySize := range []int{16, 24, 32} { - keySize := keySize t.Run(fmt.Sprintf("keySize=%d", keySize), func(t *testing.T) { key := randBytes(t, r, keySize) aesBlock, err := aes.NewCipher(key) @@ -164,10 +163,8 @@ func TestCTR_AES_multiblock_random_IV(t *testing.T) { // individually using multiblock implementation to catch edge cases. for part1 := 0; part1 <= Size; part1++ { - part1 := part1 t.Run(fmt.Sprintf("part1=%d", part1), func(t *testing.T) { for part2 := 0; part2 <= Size-part1; part2++ { - part2 := part2 t.Run(fmt.Sprintf("part2=%d", part2), func(t *testing.T) { _, multiblockCtr := makeTestingCiphers(aesBlock, iv) multiblockCiphertext := make([]byte, len(plaintext)) @@ -216,7 +213,6 @@ func TestCTR_AES_multiblock_overflow_IV(t *testing.T) { } for _, keySize := range []int{16, 24, 32} { - keySize := keySize t.Run(fmt.Sprintf("keySize=%d", keySize), func(t *testing.T) { for _, iv := range ivs { key := randBytes(t, r, keySize) @@ -227,7 +223,6 @@ func TestCTR_AES_multiblock_overflow_IV(t *testing.T) { t.Run(fmt.Sprintf("iv=%s", hex.EncodeToString(iv)), func(t *testing.T) { for _, offset := range []int{0, 1, 16, 1024} { - offset := offset t.Run(fmt.Sprintf("offset=%d", offset), func(t *testing.T) { genericCtr, multiblockCtr := makeTestingCiphers(aesBlock, iv) @@ -260,7 +255,6 @@ func TestCTR_AES_multiblock_XORKeyStreamAt(t *testing.T) { plaintext := randBytes(t, r, Size) for _, keySize := range []int{16, 24, 32} { - keySize := keySize t.Run(fmt.Sprintf("keySize=%d", keySize), func(t *testing.T) { key := randBytes(t, r, keySize) iv := randBytes(t, r, aesBlockSize) diff --git a/src/crypto/rsa/rsa_test.go b/src/crypto/rsa/rsa_test.go index 0d5b6e08f0..b9e85bd8ff 100644 --- a/src/crypto/rsa/rsa_test.go +++ b/src/crypto/rsa/rsa_test.go @@ -212,7 +212,6 @@ func TestEverything(t *testing.T) { max = 2048 } for size := min; size <= max; size++ { - size := size t.Run(fmt.Sprintf("%d", size), func(t *testing.T) { t.Parallel() priv, err := GenerateKey(rand.Reader, size) diff --git a/src/crypto/tls/handshake_client_test.go b/src/crypto/tls/handshake_client_test.go index 9c94016f13..6020c0f055 100644 --- a/src/crypto/tls/handshake_client_test.go +++ b/src/crypto/tls/handshake_client_test.go @@ -2693,7 +2693,6 @@ func TestTLS13OnlyClientHelloCipherSuite(t *testing.T) { }, } for _, tt := range tls13Tests { - tt := tt t.Run(tt.name, func(t *testing.T) { t.Parallel() testTLS13OnlyClientHelloCipherSuite(t, tt.ciphers) diff --git a/src/crypto/tls/tls_test.go b/src/crypto/tls/tls_test.go index bfcc62ccfb..6539009df6 100644 --- a/src/crypto/tls/tls_test.go +++ b/src/crypto/tls/tls_test.go @@ -1880,7 +1880,6 @@ func testVerifyCertificates(t *testing.T, version uint16) { rootCAs.AddCert(issuer) for _, test := range tests { - test := test t.Run(test.name, func(t *testing.T) { t.Parallel() diff --git a/src/crypto/x509/platform_test.go b/src/crypto/x509/platform_test.go index b425e02f3b..44ceff43f4 100644 --- a/src/crypto/x509/platform_test.go +++ b/src/crypto/x509/platform_test.go @@ -202,7 +202,6 @@ func TestPlatformVerifier(t *testing.T) { } for _, tc := range tests { - tc := tc t.Run(tc.name, func(t *testing.T) { t.Parallel() parent := testRoot diff --git a/src/database/sql/sql_test.go b/src/database/sql/sql_test.go index f706610b87..c3f228ef0b 100644 --- a/src/database/sql/sql_test.go +++ b/src/database/sql/sql_test.go @@ -2939,7 +2939,6 @@ func TestConnExpiresFreshOutOfPool(t *testing.T) { db.SetMaxOpenConns(1) for _, ec := range execCases { - ec := ec name := fmt.Sprintf("expired=%t,badReset=%t", ec.expired, ec.badReset) t.Run(name, func(t *testing.T) { db.clearAllConns(t) diff --git a/src/debug/buildinfo/buildinfo_test.go b/src/debug/buildinfo/buildinfo_test.go index 1c22f1ccdb..ceab14e8bf 100644 --- a/src/debug/buildinfo/buildinfo_test.go +++ b/src/debug/buildinfo/buildinfo_test.go @@ -238,16 +238,13 @@ func TestReadFile(t *testing.T) { } for _, p := range platforms { - p := p t.Run(p.goos+"_"+p.goarch, func(t *testing.T) { if p != runtimePlatform && !*flagAll { t.Skipf("skipping platforms other than %s_%s because -all was not set", runtimePlatform.goos, runtimePlatform.goarch) } for _, mode := range buildModes { - mode := mode t.Run(mode, func(t *testing.T) { for _, tc := range cases { - tc := tc t.Run(tc.name, func(t *testing.T) { t.Parallel() name := tc.build(t, p.goos, p.goarch, mode) diff --git a/src/debug/elf/file_test.go b/src/debug/elf/file_test.go index 0c1a7cf18a..b796cdb95b 100644 --- a/src/debug/elf/file_test.go +++ b/src/debug/elf/file_test.go @@ -1040,7 +1040,6 @@ var relocationTests = []relocationTest{ func TestDWARFRelocations(t *testing.T) { for _, test := range relocationTests { - test := test t.Run(test.file, func(t *testing.T) { t.Parallel() f, err := Open(test.file) diff --git a/src/encoding/binary/varint_test.go b/src/encoding/binary/varint_test.go index 5c3ea318c3..dbb615070b 100644 --- a/src/encoding/binary/varint_test.go +++ b/src/encoding/binary/varint_test.go @@ -181,7 +181,6 @@ func TestBufferTooBigWithOverflow(t *testing.T) { } for _, tt := range tests { - tt := tt t.Run(tt.name, func(t *testing.T) { value, n := Uvarint(tt.in) if g, w := n, tt.wantN; g != w { diff --git a/src/go/printer/printer_test.go b/src/go/printer/printer_test.go index 2a9c8be300..604b8e5aea 100644 --- a/src/go/printer/printer_test.go +++ b/src/go/printer/printer_test.go @@ -548,7 +548,6 @@ func TestBaseIndent(t *testing.T) { } for indent := 0; indent < 4; indent++ { - indent := indent t.Run(fmt.Sprint(indent), func(t *testing.T) { t.Parallel() var buf bytes.Buffer diff --git a/src/go/types/api_test.go b/src/go/types/api_test.go index 2798b9e0c4..f31b9d30c5 100644 --- a/src/go/types/api_test.go +++ b/src/go/types/api_test.go @@ -2432,7 +2432,6 @@ type K = Nested[string] ) var wg sync.WaitGroup for i := 0; i < 2; i++ { - i := i wg.Add(1) go func() { defer wg.Done() @@ -2613,7 +2612,6 @@ func fn() { }) for _, test := range tests { - test := test t.Run(test.name, func(t *testing.T) { if got := len(idents[test.name]); got != 1 { t.Fatalf("found %d identifiers named %s, want 1", got, test.name) diff --git a/src/go/types/sizes_test.go b/src/go/types/sizes_test.go index 157faf87d4..e0ca14e11b 100644 --- a/src/go/types/sizes_test.go +++ b/src/go/types/sizes_test.go @@ -187,7 +187,6 @@ func main() { func TestGCSizes(t *testing.T) { types.DefPredeclaredTestFuncs() for _, tc := range gcSizesTests { - tc := tc t.Run(tc.name, func(t *testing.T) { t.Parallel() conf := types.Config{ diff --git a/src/go/types/stdlib_test.go b/src/go/types/stdlib_test.go index eb838b2c88..e7ef39fd5b 100644 --- a/src/go/types/stdlib_test.go +++ b/src/go/types/stdlib_test.go @@ -70,8 +70,6 @@ func TestStdlib(t *testing.T) { var wg sync.WaitGroup for dir := range dirFiles { - dir := dir - cpulimit <- struct{}{} wg.Add(1) go func() { diff --git a/src/internal/fuzz/encoding_test.go b/src/internal/fuzz/encoding_test.go index a46a347403..5f2af4476b 100644 --- a/src/internal/fuzz/encoding_test.go +++ b/src/internal/fuzz/encoding_test.go @@ -260,7 +260,6 @@ func BenchmarkMarshalCorpusFile(b *testing.B) { } for sz := 1; sz <= len(buf); sz <<= 1 { - sz := sz b.Run(strconv.Itoa(sz), func(b *testing.B) { for i := 0; i < b.N; i++ { b.SetBytes(int64(sz)) @@ -280,7 +279,6 @@ func BenchmarkUnmarshalCorpusFile(b *testing.B) { } for sz := 1; sz <= len(buf); sz <<= 1 { - sz := sz data := marshalCorpusFile(buf[:sz]) b.Run(strconv.Itoa(sz), func(b *testing.B) { for i := 0; i < b.N; i++ { diff --git a/src/internal/fuzz/minimize_test.go b/src/internal/fuzz/minimize_test.go index e7e23e5a05..79d986374f 100644 --- a/src/internal/fuzz/minimize_test.go +++ b/src/internal/fuzz/minimize_test.go @@ -132,7 +132,6 @@ func TestMinimizeInput(t *testing.T) { } for _, tc := range cases { - tc := tc t.Run(tc.name, func(t *testing.T) { t.Parallel() ws := &workerServer{ diff --git a/src/internal/fuzz/worker_test.go b/src/internal/fuzz/worker_test.go index d0b21da783..9420248d2c 100644 --- a/src/internal/fuzz/worker_test.go +++ b/src/internal/fuzz/worker_test.go @@ -182,7 +182,6 @@ func BenchmarkWorkerMinimize(b *testing.B) { bytes := make([]byte, 1024) ctx := context.Background() for sz := 1; sz <= len(bytes); sz <<= 1 { - sz := sz input := []any{bytes[:sz]} encodedVals := marshalCorpusFile(input...) mem = <-ws.memMu diff --git a/src/internal/reflectlite/reflect_mirror_test.go b/src/internal/reflectlite/reflect_mirror_test.go index 8d13641516..c5642d092d 100644 --- a/src/internal/reflectlite/reflect_mirror_test.go +++ b/src/internal/reflectlite/reflect_mirror_test.go @@ -101,7 +101,6 @@ func TestMirrorWithReflect(t *testing.T) { {".", "reflectlite", rl}, {reflectDir, "reflect", r}, } { - tc := tc wg.Add(1) go func() { defer wg.Done() diff --git a/src/internal/trace/reader_test.go b/src/internal/trace/reader_test.go index 39ae77471e..e0733b827d 100644 --- a/src/internal/trace/reader_test.go +++ b/src/internal/trace/reader_test.go @@ -33,7 +33,6 @@ func TestReaderGolden(t *testing.T) { t.Fatalf("failed to glob for tests: %v", err) } for _, testPath := range matches { - testPath := testPath testName, err := filepath.Rel("./testdata", testPath) if err != nil { t.Fatalf("failed to relativize testdata path: %v", err) diff --git a/src/internal/trace/tracev1_test.go b/src/internal/trace/tracev1_test.go index 42a8371887..355a6ff529 100644 --- a/src/internal/trace/tracev1_test.go +++ b/src/internal/trace/tracev1_test.go @@ -21,7 +21,6 @@ func TestTraceV1(t *testing.T) { } var testedUserRegions bool for _, p := range traces { - p := p testName, err := filepath.Rel("./internal/tracev1/testdata", p) if err != nil { t.Fatalf("failed to relativize testdata path: %s", err) diff --git a/src/internal/zstd/fse_test.go b/src/internal/zstd/fse_test.go index 6f106b65b7..20365745a5 100644 --- a/src/internal/zstd/fse_test.go +++ b/src/internal/zstd/fse_test.go @@ -68,7 +68,6 @@ func TestPredefinedTables(t *testing.T) { }, } for _, test := range tests { - test := test t.Run(test.name, func(t *testing.T) { var r Reader table := make([]fseEntry, 1<= N { b.Logf("bad") // just to capture b diff --git a/src/sync/atomic/value_test.go b/src/sync/atomic/value_test.go index 721da965e3..b8bc8b8851 100644 --- a/src/sync/atomic/value_test.go +++ b/src/sync/atomic/value_test.go @@ -185,7 +185,6 @@ func TestValueSwapConcurrent(t *testing.T) { n = 1000 } for i := uint64(0); i < m*n; i += n { - i := i g.Add(1) go func() { var c uint64 @@ -256,7 +255,6 @@ func TestValueCompareAndSwapConcurrent(t *testing.T) { n = 100 } for i := 0; i < m; i++ { - i := i w.Add(1) go func() { for j := i; j < m*n; runtime.Gosched() { diff --git a/src/syscall/exec_linux_test.go b/src/syscall/exec_linux_test.go index 69d4916944..ac04e51b14 100644 --- a/src/syscall/exec_linux_test.go +++ b/src/syscall/exec_linux_test.go @@ -51,7 +51,6 @@ func whoamiNEWUSER(t *testing.T, uid, gid int, setgroups bool) *exec.Cmd { func TestCloneNEWUSERAndRemap(t *testing.T) { for _, setgroups := range []bool{false, true} { - setgroups := setgroups t.Run(fmt.Sprintf("setgroups=%v", setgroups), func(t *testing.T) { uid := os.Getuid() gid := os.Getgid() diff --git a/src/testing/flag_test.go b/src/testing/flag_test.go index 6a7754425d..fb65e15928 100644 --- a/src/testing/flag_test.go +++ b/src/testing/flag_test.go @@ -25,7 +25,6 @@ func TestFlag(t *testing.T) { testenv.MustHaveExec(t) for _, flag := range []string{"", "-test.v", "-test.v=test2json"} { - flag := flag t.Run(flag, func(t *testing.T) { t.Parallel() cmd := exec.Command(testenv.Executable(t), "-test.run=^TestFlag$", "-test_flag_arg="+flag) diff --git a/src/testing/panic_test.go b/src/testing/panic_test.go index fc84175ee6..01a34b0801 100644 --- a/src/testing/panic_test.go +++ b/src/testing/panic_test.go @@ -198,7 +198,6 @@ func TestPanicHelper(t *testing.T) { } }) for i := 0; i < 3; i++ { - i := i t.Run(fmt.Sprintf("%v", i), func(t *testing.T) { chosen := t.Name() == *testPanicTest if chosen && *testPanicCleanup { diff --git a/src/testing/sub_test.go b/src/testing/sub_test.go index bb5586d9fc..5d5573ccec 100644 --- a/src/testing/sub_test.go +++ b/src/testing/sub_test.go @@ -988,7 +988,6 @@ func TestConcurrentCleanup(t *T) { var wg sync.WaitGroup wg.Add(2) for i := 0; i < 2; i++ { - i := i go func() { t.Cleanup(func() { // Although the calls to Cleanup are concurrent, the functions passed diff --git a/src/time/sleep_test.go b/src/time/sleep_test.go index b9e81b98fe..c87f420f8f 100644 --- a/src/time/sleep_test.go +++ b/src/time/sleep_test.go @@ -937,7 +937,6 @@ func BenchmarkParallelTimerLatency(b *testing.B) { wg.Add(timerCount) atomic.StoreInt32(&count, 0) for j := 0; j < timerCount; j++ { - j := j expectedWakeup := Now().Add(delay) AfterFunc(delay, func() { late := Since(expectedWakeup) @@ -1011,7 +1010,6 @@ func BenchmarkStaggeredTickerLatency(b *testing.B) { var wg sync.WaitGroup wg.Add(tickerCount) for j := 0; j < tickerCount; j++ { - j := j doWork(delay / Duration(gmp)) expectedWakeup := Now().Add(delay) ticker := NewTicker(delay)