aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTobias Klauser <tklauser@distanz.ch>2025-10-14 11:40:26 +0200
committerGopher Robot <gobot@golang.org>2025-10-17 13:10:27 -0700
commitb5aefe07e5afe2fd5d49c6a4219cc826b3e4e34e (patch)
tree3b3576e22ccc48d21f106c65d3bd10f368aaabf6
parent5137c473b64cb157380eb6deb1b60bf6780402b3 (diff)
downloadgo-b5aefe07e5afe2fd5d49c6a4219cc826b3e4e34e.tar.xz
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 <lehner.florian86@gmail.com> Auto-Submit: Damien Neil <dneil@google.com> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com> Reviewed-by: Damien Neil <dneil@google.com> Auto-Submit: Tobias Klauser <tobias.klauser@gmail.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
-rw-r--r--src/archive/zip/reader_test.go2
-rw-r--r--src/context/x_test.go1
-rw-r--r--src/crypto/cipher/ctr_aes_test.go6
-rw-r--r--src/crypto/rsa/rsa_test.go1
-rw-r--r--src/crypto/tls/handshake_client_test.go1
-rw-r--r--src/crypto/tls/tls_test.go1
-rw-r--r--src/crypto/x509/platform_test.go1
-rw-r--r--src/database/sql/sql_test.go1
-rw-r--r--src/debug/buildinfo/buildinfo_test.go3
-rw-r--r--src/debug/elf/file_test.go1
-rw-r--r--src/encoding/binary/varint_test.go1
-rw-r--r--src/go/printer/printer_test.go1
-rw-r--r--src/go/types/api_test.go2
-rw-r--r--src/go/types/sizes_test.go1
-rw-r--r--src/go/types/stdlib_test.go2
-rw-r--r--src/internal/fuzz/encoding_test.go2
-rw-r--r--src/internal/fuzz/minimize_test.go1
-rw-r--r--src/internal/fuzz/worker_test.go1
-rw-r--r--src/internal/reflectlite/reflect_mirror_test.go1
-rw-r--r--src/internal/trace/reader_test.go1
-rw-r--r--src/internal/trace/tracev1_test.go1
-rw-r--r--src/internal/zstd/fse_test.go1
-rw-r--r--src/internal/zstd/zstd_test.go2
-rw-r--r--src/log/syslog/syslog_test.go1
-rw-r--r--src/math/rand/default_test.go1
-rw-r--r--src/net/conn_test.go1
-rw-r--r--src/net/dial_test.go1
-rw-r--r--src/net/error_test.go1
-rw-r--r--src/net/http/fs_test.go1
-rw-r--r--src/net/http/httptest/recorder_test.go1
-rw-r--r--src/net/http/serve_test.go1
-rw-r--r--src/net/http/transport_test.go1
-rw-r--r--src/net/net_test.go6
-rw-r--r--src/net/server_test.go2
-rw-r--r--src/net/timeout_test.go1
-rw-r--r--src/net/unixsock_test.go2
-rw-r--r--src/os/exec/exec_posix_test.go2
-rw-r--r--src/os/signal/signal_test.go4
-rw-r--r--src/path/filepath/path_test.go1
-rw-r--r--src/reflect/all_test.go3
-rw-r--r--src/reflect/visiblefields_test.go1
-rw-r--r--src/runtime/chan_test.go2
-rw-r--r--src/runtime/checkptr_test.go2
-rw-r--r--src/runtime/crash_cgo_test.go2
-rw-r--r--src/runtime/map_benchmark_test.go1
-rw-r--r--src/runtime/memmove_test.go2
-rw-r--r--src/runtime/mgcpacer_test.go1
-rw-r--r--src/runtime/mgcscavenge_test.go3
-rw-r--r--src/runtime/mpagealloc_test.go5
-rw-r--r--src/runtime/mpagecache_test.go2
-rw-r--r--src/runtime/mpallocbits_test.go4
-rw-r--r--src/runtime/proc_test.go1
-rw-r--r--src/sync/atomic/value_test.go2
-rw-r--r--src/syscall/exec_linux_test.go1
-rw-r--r--src/testing/flag_test.go1
-rw-r--r--src/testing/panic_test.go1
-rw-r--r--src/testing/sub_test.go1
-rw-r--r--src/time/sleep_test.go2
58 files changed, 0 insertions, 99 deletions
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<<test.tableBits)
diff --git a/src/internal/zstd/zstd_test.go b/src/internal/zstd/zstd_test.go
index f2a2e1b585..eb06af8a14 100644
--- a/src/internal/zstd/zstd_test.go
+++ b/src/internal/zstd/zstd_test.go
@@ -112,7 +112,6 @@ var tests = []struct {
func TestSamples(t *testing.T) {
for _, test := range tests {
- test := test
t.Run(test.name, func(t *testing.T) {
r := NewReader(strings.NewReader(test.compressed))
got, err := io.ReadAll(r)
@@ -131,7 +130,6 @@ func TestReset(t *testing.T) {
input := strings.NewReader("")
r := NewReader(input)
for _, test := range tests {
- test := test
t.Run(test.name, func(t *testing.T) {
input.Reset(test.compressed)
r.Reset(input)
diff --git a/src/log/syslog/syslog_test.go b/src/log/syslog/syslog_test.go
index cec225f751..0d94bcbc4c 100644
--- a/src/log/syslog/syslog_test.go
+++ b/src/log/syslog/syslog_test.go
@@ -145,7 +145,6 @@ func TestWithSimulated(t *testing.T) {
continue
}
- tr := tr
t.Run(tr, func(t *testing.T) {
t.Parallel()
diff --git a/src/math/rand/default_test.go b/src/math/rand/default_test.go
index 0ba51b4dbd..25c24244c4 100644
--- a/src/math/rand/default_test.go
+++ b/src/math/rand/default_test.go
@@ -34,7 +34,6 @@ func TestDefaultRace(t *testing.T) {
t.Parallel()
for i := 0; i < 6; i++ {
- i := i
t.Run(strconv.Itoa(i), func(t *testing.T) {
t.Parallel()
cmd := testenv.Command(t, testenv.Executable(t), "-test.run=^TestDefaultRace$")
diff --git a/src/net/conn_test.go b/src/net/conn_test.go
index d1e1e7bf1c..87097e10ee 100644
--- a/src/net/conn_test.go
+++ b/src/net/conn_test.go
@@ -19,7 +19,6 @@ const someTimeout = 1 * time.Hour
func TestConnAndListener(t *testing.T) {
for i, network := range []string{"tcp", "unix", "unixpacket"} {
- i, network := i, network
t.Run(network, func(t *testing.T) {
if !testableNetwork(network) {
t.Skipf("skipping %s test", network)
diff --git a/src/net/dial_test.go b/src/net/dial_test.go
index 829b80c33a..07a9b46ddb 100644
--- a/src/net/dial_test.go
+++ b/src/net/dial_test.go
@@ -232,7 +232,6 @@ func TestDialParallel(t *testing.T) {
}
for i, tt := range testCases {
- i, tt := i, tt
t.Run(fmt.Sprint(i), func(t *testing.T) {
dialTCP := func(ctx context.Context, network string, laddr, raddr *TCPAddr) (*TCPConn, error) {
n := "tcp6"
diff --git a/src/net/error_test.go b/src/net/error_test.go
index ff25433621..8026144c3d 100644
--- a/src/net/error_test.go
+++ b/src/net/error_test.go
@@ -155,7 +155,6 @@ func TestDialError(t *testing.T) {
d := Dialer{Timeout: someTimeout}
for i, tt := range dialErrorTests {
- i, tt := i, tt
t.Run(fmt.Sprint(i), func(t *testing.T) {
c, err := d.Dial(tt.network, tt.address)
if err == nil {
diff --git a/src/net/http/fs_test.go b/src/net/http/fs_test.go
index 9b34ad080e..32fb696fee 100644
--- a/src/net/http/fs_test.go
+++ b/src/net/http/fs_test.go
@@ -1540,7 +1540,6 @@ func testServeFileRejectsInvalidSuffixLengths(t *testing.T, mode testMode) {
}
for _, tt := range tests {
- tt := tt
t.Run(tt.r, func(t *testing.T) {
req, err := NewRequest("GET", cst.URL+"/index.html", nil)
if err != nil {
diff --git a/src/net/http/httptest/recorder_test.go b/src/net/http/httptest/recorder_test.go
index 0996976514..9d1c4430c9 100644
--- a/src/net/http/httptest/recorder_test.go
+++ b/src/net/http/httptest/recorder_test.go
@@ -374,7 +374,6 @@ func TestRecorderPanicsOnNonXXXStatusCode(t *testing.T) {
-100, 0, 99, 1000, 20000,
}
for _, badCode := range badCodes {
- badCode := badCode
t.Run(fmt.Sprintf("Code=%d", badCode), func(t *testing.T) {
defer func() {
if r := recover(); r == nil {
diff --git a/src/net/http/serve_test.go b/src/net/http/serve_test.go
index aee6288f3b..4a16ba02af 100644
--- a/src/net/http/serve_test.go
+++ b/src/net/http/serve_test.go
@@ -6701,7 +6701,6 @@ func testTimeoutHandlerSuperfluousLogs(t *testing.T, mode testMode) {
}
for _, tt := range tests {
- tt := tt
t.Run(tt.name, func(t *testing.T) {
exitHandler := make(chan bool, 1)
defer close(exitHandler)
diff --git a/src/net/http/transport_test.go b/src/net/http/transport_test.go
index 75dbd25d22..8ab4107fb7 100644
--- a/src/net/http/transport_test.go
+++ b/src/net/http/transport_test.go
@@ -4526,7 +4526,6 @@ func TestTransportContentEncodingCaseInsensitive(t *testing.T) {
}
func testTransportContentEncodingCaseInsensitive(t *testing.T, mode testMode) {
for _, ce := range []string{"gzip", "GZIP"} {
- ce := ce
t.Run(ce, func(t *testing.T) {
const encodedString = "Hello Gopher"
ts := newClientServerTest(t, mode, HandlerFunc(func(w ResponseWriter, r *Request) {
diff --git a/src/net/net_test.go b/src/net/net_test.go
index 7269db8f2b..637c95540f 100644
--- a/src/net/net_test.go
+++ b/src/net/net_test.go
@@ -24,7 +24,6 @@ func TestCloseRead(t *testing.T) {
t.Parallel()
for _, network := range []string{"tcp", "unix", "unixpacket"} {
- network := network
t.Run(network, func(t *testing.T) {
if !testableNetwork(network) {
t.Skipf("network %s is not testable on the current platform", network)
@@ -83,7 +82,6 @@ func TestCloseWrite(t *testing.T) {
}
for _, network := range []string{"tcp", "unix", "unixpacket"} {
- network := network
t.Run(network, func(t *testing.T) {
if !testableNetwork(network) {
t.Skipf("network %s is not testable on the current platform", network)
@@ -185,7 +183,6 @@ func TestCloseWrite(t *testing.T) {
func TestConnClose(t *testing.T) {
t.Parallel()
for _, network := range []string{"tcp", "unix", "unixpacket"} {
- network := network
t.Run(network, func(t *testing.T) {
if !testableNetwork(network) {
t.Skipf("network %s is not testable on the current platform", network)
@@ -227,7 +224,6 @@ func TestConnClose(t *testing.T) {
func TestListenerClose(t *testing.T) {
t.Parallel()
for _, network := range []string{"tcp", "unix", "unixpacket"} {
- network := network
t.Run(network, func(t *testing.T) {
if !testableNetwork(network) {
t.Skipf("network %s is not testable on the current platform", network)
@@ -265,7 +261,6 @@ func TestListenerClose(t *testing.T) {
func TestPacketConnClose(t *testing.T) {
t.Parallel()
for _, network := range []string{"udp", "unixgram"} {
- network := network
t.Run(network, func(t *testing.T) {
if !testableNetwork(network) {
t.Skipf("network %s is not testable on the current platform", network)
@@ -349,7 +344,6 @@ func TestAcceptIgnoreAbortedConnRequest(t *testing.T) {
func TestZeroByteRead(t *testing.T) {
t.Parallel()
for _, network := range []string{"tcp", "unix", "unixpacket"} {
- network := network
t.Run(network, func(t *testing.T) {
if !testableNetwork(network) {
t.Skipf("network %s is not testable on the current platform", network)
diff --git a/src/net/server_test.go b/src/net/server_test.go
index eb6b111f1f..cc9e985709 100644
--- a/src/net/server_test.go
+++ b/src/net/server_test.go
@@ -250,7 +250,6 @@ var udpServerTests = []struct {
func TestUDPServer(t *testing.T) {
for i, tt := range udpServerTests {
- i, tt := i, tt
t.Run(fmt.Sprint(i), func(t *testing.T) {
if !testableListenArgs(tt.snet, tt.saddr, tt.taddr) {
t.Skipf("skipping %s %s<-%s test", tt.snet, tt.saddr, tt.taddr)
@@ -340,7 +339,6 @@ func TestUnixgramServer(t *testing.T) {
}
for i, tt := range unixgramServerTests {
- i, tt := i, tt
t.Run(fmt.Sprint(i), func(t *testing.T) {
if !testableListenArgs("unixgram", tt.saddr, "") {
t.Skipf("skipping unixgram %s<-%s test", tt.saddr, tt.caddr)
diff --git a/src/net/timeout_test.go b/src/net/timeout_test.go
index 0d009f6999..b7f8c613b4 100644
--- a/src/net/timeout_test.go
+++ b/src/net/timeout_test.go
@@ -180,7 +180,6 @@ func TestAcceptTimeout(t *testing.T) {
}
for _, timeout := range timeouts {
- timeout := timeout
t.Run(fmt.Sprintf("%v", timeout), func(t *testing.T) {
t.Parallel()
diff --git a/src/net/unixsock_test.go b/src/net/unixsock_test.go
index 6758afddca..f6c5679f42 100644
--- a/src/net/unixsock_test.go
+++ b/src/net/unixsock_test.go
@@ -247,7 +247,6 @@ func TestUnixConnLocalAndRemoteNames(t *testing.T) {
handler := func(ls *localServer, ln Listener) {}
for _, laddr := range []string{"", testUnixAddr(t)} {
- laddr := laddr
taddr := testUnixAddr(t)
ta, err := ResolveUnixAddr("unix", taddr)
if err != nil {
@@ -306,7 +305,6 @@ func TestUnixgramConnLocalAndRemoteNames(t *testing.T) {
}
for _, laddr := range []string{"", testUnixAddr(t)} {
- laddr := laddr
taddr := testUnixAddr(t)
ta, err := ResolveUnixAddr("unixgram", taddr)
if err != nil {
diff --git a/src/os/exec/exec_posix_test.go b/src/os/exec/exec_posix_test.go
index 77c5fc11e4..0711fac90e 100644
--- a/src/os/exec/exec_posix_test.go
+++ b/src/os/exec/exec_posix_test.go
@@ -165,7 +165,6 @@ func TestImplicitPWD(t *testing.T) {
}
for _, tc := range cases {
- tc := tc
t.Run(tc.name, func(t *testing.T) {
t.Parallel()
@@ -242,7 +241,6 @@ func TestExplicitPWD(t *testing.T) {
// contain symlinks preserved from the PWD value in the test's environment.
}
for _, tc := range cases {
- tc := tc
t.Run(tc.name, func(t *testing.T) {
t.Parallel()
diff --git a/src/os/signal/signal_test.go b/src/os/signal/signal_test.go
index 0aa0439b90..8d3f230178 100644
--- a/src/os/signal/signal_test.go
+++ b/src/os/signal/signal_test.go
@@ -347,7 +347,6 @@ func TestStop(t *testing.T) {
}
for _, sig := range sigs {
- sig := sig
t.Run(fmt.Sprint(sig), func(t *testing.T) {
// When calling Notify with a specific signal,
// independent signals should not interfere with each other,
@@ -441,7 +440,6 @@ func TestNohup(t *testing.T) {
subTimeout -= subTimeout / 10 // Leave 10% headroom for propagating output.
}
for i := 1; i <= 2; i++ {
- i := i
t.Run(fmt.Sprintf("%d", i), func(t *testing.T) {
t.Parallel()
@@ -484,7 +482,6 @@ func TestNohup(t *testing.T) {
subTimeout -= subTimeout / 10 // Leave 10% headroom for propagating output.
}
for i := 1; i <= 2; i++ {
- i := i
t.Run(fmt.Sprintf("%d", i), func(t *testing.T) {
t.Parallel()
@@ -743,7 +740,6 @@ func TestNotifyContextNotifications(t *testing.T) {
{"multiple", 10},
}
for _, tc := range testCases {
- tc := tc
t.Run(tc.name, func(t *testing.T) {
t.Parallel()
diff --git a/src/path/filepath/path_test.go b/src/path/filepath/path_test.go
index efdb3c6035..ad99f70287 100644
--- a/src/path/filepath/path_test.go
+++ b/src/path/filepath/path_test.go
@@ -936,7 +936,6 @@ func TestWalkSymlinkRoot(t *testing.T) {
buggyGOOS: []string{"darwin", "ios"}, // https://go.dev/issue/59586
},
} {
- tt := tt
t.Run(tt.desc, func(t *testing.T) {
var walked []string
err := filepath.Walk(tt.root, func(path string, info fs.FileInfo, err error) error {
diff --git a/src/reflect/all_test.go b/src/reflect/all_test.go
index c6610b1968..1fa850a275 100644
--- a/src/reflect/all_test.go
+++ b/src/reflect/all_test.go
@@ -7515,7 +7515,6 @@ func TestTypeStrings(t *testing.T) {
func TestOffsetLock(t *testing.T) {
var wg sync.WaitGroup
for i := 0; i < 4; i++ {
- i := i
wg.Add(1)
go func() {
for j := 0; j < 50; j++ {
@@ -8535,7 +8534,6 @@ func TestClear(t *testing.T) {
}
for _, tc := range tests {
- tc := tc
t.Run(tc.name, func(t *testing.T) {
t.Parallel()
if !tc.testFunc(tc.value) {
@@ -8569,7 +8567,6 @@ func TestValuePointerAndUnsafePointer(t *testing.T) {
}
for _, tc := range tests {
- tc := tc
t.Run(tc.name, func(t *testing.T) {
if got := tc.val.Pointer(); got != uintptr(tc.wantUnsafePointer) {
t.Errorf("unexpected uintptr result, got %#x, want %#x", got, uintptr(tc.wantUnsafePointer))
diff --git a/src/reflect/visiblefields_test.go b/src/reflect/visiblefields_test.go
index 66d545dd1f..eca0925f96 100644
--- a/src/reflect/visiblefields_test.go
+++ b/src/reflect/visiblefields_test.go
@@ -292,7 +292,6 @@ type Rec2 struct {
func TestFields(t *testing.T) {
for _, test := range fieldsTests {
- test := test
t.Run(test.testName, func(t *testing.T) {
typ := TypeOf(test.val)
fields := VisibleFields(typ)
diff --git a/src/runtime/chan_test.go b/src/runtime/chan_test.go
index 526d45bb43..5a1ca52a8c 100644
--- a/src/runtime/chan_test.go
+++ b/src/runtime/chan_test.go
@@ -309,7 +309,6 @@ func TestSelfSelect(t *testing.T) {
wg.Add(2)
c := make(chan int, chanCap)
for p := 0; p < 2; p++ {
- p := p
go func() {
defer wg.Done()
for i := 0; i < 1000; i++ {
@@ -359,7 +358,6 @@ func TestSelectStress(t *testing.T) {
var wg sync.WaitGroup
wg.Add(10)
for k := 0; k < 4; k++ {
- k := k
go func() {
for i := 0; i < N; i++ {
c[k] <- 0
diff --git a/src/runtime/checkptr_test.go b/src/runtime/checkptr_test.go
index 119708be7f..d08b052449 100644
--- a/src/runtime/checkptr_test.go
+++ b/src/runtime/checkptr_test.go
@@ -45,7 +45,6 @@ func TestCheckPtr(t *testing.T) {
}
for _, tc := range testCases {
- tc := tc
t.Run(tc.cmd, func(t *testing.T) {
t.Parallel()
got, err := testenv.CleanCmdEnv(exec.Command(exe, tc.cmd)).CombinedOutput()
@@ -88,7 +87,6 @@ func TestCheckPtr2(t *testing.T) {
}
for _, tc := range testCases {
- tc := tc
t.Run(tc.cmd, func(t *testing.T) {
t.Parallel()
got, err := testenv.CleanCmdEnv(exec.Command(exe, tc.cmd)).CombinedOutput()
diff --git a/src/runtime/crash_cgo_test.go b/src/runtime/crash_cgo_test.go
index b77ff8dafd..baf4523a7a 100644
--- a/src/runtime/crash_cgo_test.go
+++ b/src/runtime/crash_cgo_test.go
@@ -752,8 +752,6 @@ func TestSegv(t *testing.T) {
}
for _, test := range []string{"Segv", "SegvInCgo", "TgkillSegv", "TgkillSegvInCgo"} {
- test := test
-
// The tgkill variants only run on Linux.
if runtime.GOOS != "linux" && strings.HasPrefix(test, "Tgkill") {
continue
diff --git a/src/runtime/map_benchmark_test.go b/src/runtime/map_benchmark_test.go
index a26b35b44d..9e93b219f1 100644
--- a/src/runtime/map_benchmark_test.go
+++ b/src/runtime/map_benchmark_test.go
@@ -493,7 +493,6 @@ func BenchmarkMapInterfacePtr(b *testing.B) {
m := map[any]bool{}
for i := 0; i < 100; i++ {
- i := i
m[&i] = true
}
diff --git a/src/runtime/memmove_test.go b/src/runtime/memmove_test.go
index 22905504d4..6065a84553 100644
--- a/src/runtime/memmove_test.go
+++ b/src/runtime/memmove_test.go
@@ -221,8 +221,6 @@ func TestMemmoveAtomicity(t *testing.T) {
for _, backward := range []bool{true, false} {
for _, n := range []int{3, 4, 5, 6, 7, 8, 9, 10, 15, 25, 49} {
- n := n
-
// test copying [N]*int.
sz := uintptr(n * PtrSize)
name := fmt.Sprint(sz)
diff --git a/src/runtime/mgcpacer_test.go b/src/runtime/mgcpacer_test.go
index ef1483d629..4b9cbf5589 100644
--- a/src/runtime/mgcpacer_test.go
+++ b/src/runtime/mgcpacer_test.go
@@ -603,7 +603,6 @@ func TestGcPacer(t *testing.T) {
// However, it is still possible to trigger this case if something exceptional
// happens between calls to revise; the framework just doesn't support this yet.
} {
- e := e
t.Run(e.name, func(t *testing.T) {
t.Parallel()
diff --git a/src/runtime/mgcscavenge_test.go b/src/runtime/mgcscavenge_test.go
index 7b86ae8ffc..4f9dbac481 100644
--- a/src/runtime/mgcscavenge_test.go
+++ b/src/runtime/mgcscavenge_test.go
@@ -285,7 +285,6 @@ func TestPallocDataFindScavengeCandidate(t *testing.T) {
}
}
for name, v := range tests {
- v := v
t.Run(name, func(t *testing.T) {
b := makePallocData(v.alloc, v.scavenged)
start, size := b.FindScavengeCandidate(PallocChunkPages-1, v.min, v.max)
@@ -447,7 +446,6 @@ func TestPageAllocScavenge(t *testing.T) {
}
}
for name, v := range tests {
- v := v
t.Run(name, func(t *testing.T) {
b := NewPageAlloc(v.beforeAlloc, v.beforeScav)
defer FreePageAlloc(b)
@@ -811,7 +809,6 @@ func TestScavengeIndex(t *testing.T) {
)
}
for _, test := range tests {
- test := test
t.Run("Bg/"+test.name, func(t *testing.T) {
mark, find, nextGen := setup(t, false)
test.mark(mark)
diff --git a/src/runtime/mpagealloc_test.go b/src/runtime/mpagealloc_test.go
index ded7a79922..45badcb260 100644
--- a/src/runtime/mpagealloc_test.go
+++ b/src/runtime/mpagealloc_test.go
@@ -181,7 +181,6 @@ func TestPageAllocGrow(t *testing.T) {
}
}
for name, v := range tests {
- v := v
t.Run(name, func(t *testing.T) {
// By creating a new pageAlloc, we will
// grow it for each chunk defined in x.
@@ -678,7 +677,6 @@ func TestPageAllocAlloc(t *testing.T) {
}
}
for name, v := range tests {
- v := v
t.Run(name, func(t *testing.T) {
b := NewPageAlloc(v.before, v.scav)
defer FreePageAlloc(b)
@@ -705,7 +703,6 @@ func TestPageAllocExhaust(t *testing.T) {
t.Skip("skipping because virtual memory is limited; see #36210")
}
for _, npages := range []uintptr{1, 2, 3, 4, 5, 8, 16, 64, 1024, 1025, 2048, 2049} {
- npages := npages
t.Run(fmt.Sprintf("%d", npages), func(t *testing.T) {
// Construct b.
bDesc := make(map[ChunkIdx][]BitRange)
@@ -973,7 +970,6 @@ func TestPageAllocFree(t *testing.T) {
}
}
for name, v := range tests {
- v := v
t.Run(name, func(t *testing.T) {
b := NewPageAlloc(v.before, nil)
defer FreePageAlloc(b)
@@ -1028,7 +1024,6 @@ func TestPageAllocAllocAndFree(t *testing.T) {
},
}
for name, v := range tests {
- v := v
t.Run(name, func(t *testing.T) {
b := NewPageAlloc(v.init, nil)
defer FreePageAlloc(b)
diff --git a/src/runtime/mpagecache_test.go b/src/runtime/mpagecache_test.go
index 19b4e04807..523a1c0b07 100644
--- a/src/runtime/mpagecache_test.go
+++ b/src/runtime/mpagecache_test.go
@@ -164,7 +164,6 @@ func TestPageCacheAlloc(t *testing.T) {
},
}
for name, test := range tests {
- test := test
t.Run(name, func(t *testing.T) {
c := test.cache
for i, h := range test.hits {
@@ -407,7 +406,6 @@ func TestPageAllocAllocToCache(t *testing.T) {
}
}
for name, v := range tests {
- v := v
t.Run(name, func(t *testing.T) {
b := NewPageAlloc(v.beforeAlloc, v.beforeScav)
defer FreePageAlloc(b)
diff --git a/src/runtime/mpallocbits_test.go b/src/runtime/mpallocbits_test.go
index cf49f77507..755f423f96 100644
--- a/src/runtime/mpallocbits_test.go
+++ b/src/runtime/mpallocbits_test.go
@@ -200,7 +200,6 @@ func TestMallocBitsPopcntRange(t *testing.T) {
}
}
for name, v := range tests {
- v := v
t.Run(name, func(t *testing.T) {
b := makePallocBits(v.init)
for _, h := range v.tests {
@@ -291,7 +290,6 @@ func TestPallocBitsSummarize(t *testing.T) {
},
}
for name, v := range tests {
- v := v
t.Run(name, func(t *testing.T) {
b := makePallocBits(v.free)
// In the PallocBits we create 1's represent free spots, but in our actual
@@ -436,7 +434,6 @@ func TestPallocBitsAlloc(t *testing.T) {
}
}
for name, v := range tests {
- v := v
t.Run(name, func(t *testing.T) {
b := makePallocBits(v.before)
for iter, i := range v.hits {
@@ -498,7 +495,6 @@ func TestPallocBitsFree(t *testing.T) {
}
}
for name, v := range tests {
- v := v
t.Run(name, func(t *testing.T) {
b := makePallocBits(v.beforeInv)
invertPallocBits(b)
diff --git a/src/runtime/proc_test.go b/src/runtime/proc_test.go
index 3b606f62e4..d10d4a1fc9 100644
--- a/src/runtime/proc_test.go
+++ b/src/runtime/proc_test.go
@@ -696,7 +696,6 @@ func BenchmarkCreateGoroutinesCapture(b *testing.B) {
var wg sync.WaitGroup
wg.Add(N)
for i := 0; i < N; i++ {
- i := i
go func() {
if i >= 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)