]> Cypherpunks repositories - gostls13.git/commitdiff
all: remove unnecessary loop variable copies in tests
authorTobias Klauser <tklauser@distanz.ch>
Tue, 14 Oct 2025 09:40:26 +0000 (11:40 +0200)
committerGopher Robot <gobot@golang.org>
Fri, 17 Oct 2025 20:10:27 +0000 (13:10 -0700)
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>

58 files changed:
src/archive/zip/reader_test.go
src/context/x_test.go
src/crypto/cipher/ctr_aes_test.go
src/crypto/rsa/rsa_test.go
src/crypto/tls/handshake_client_test.go
src/crypto/tls/tls_test.go
src/crypto/x509/platform_test.go
src/database/sql/sql_test.go
src/debug/buildinfo/buildinfo_test.go
src/debug/elf/file_test.go
src/encoding/binary/varint_test.go
src/go/printer/printer_test.go
src/go/types/api_test.go
src/go/types/sizes_test.go
src/go/types/stdlib_test.go
src/internal/fuzz/encoding_test.go
src/internal/fuzz/minimize_test.go
src/internal/fuzz/worker_test.go
src/internal/reflectlite/reflect_mirror_test.go
src/internal/trace/reader_test.go
src/internal/trace/tracev1_test.go
src/internal/zstd/fse_test.go
src/internal/zstd/zstd_test.go
src/log/syslog/syslog_test.go
src/math/rand/default_test.go
src/net/conn_test.go
src/net/dial_test.go
src/net/error_test.go
src/net/http/fs_test.go
src/net/http/httptest/recorder_test.go
src/net/http/serve_test.go
src/net/http/transport_test.go
src/net/net_test.go
src/net/server_test.go
src/net/timeout_test.go
src/net/unixsock_test.go
src/os/exec/exec_posix_test.go
src/os/signal/signal_test.go
src/path/filepath/path_test.go
src/reflect/all_test.go
src/reflect/visiblefields_test.go
src/runtime/chan_test.go
src/runtime/checkptr_test.go
src/runtime/crash_cgo_test.go
src/runtime/map_benchmark_test.go
src/runtime/memmove_test.go
src/runtime/mgcpacer_test.go
src/runtime/mgcscavenge_test.go
src/runtime/mpagealloc_test.go
src/runtime/mpagecache_test.go
src/runtime/mpallocbits_test.go
src/runtime/proc_test.go
src/sync/atomic/value_test.go
src/syscall/exec_linux_test.go
src/testing/flag_test.go
src/testing/panic_test.go
src/testing/sub_test.go
src/time/sleep_test.go

index 410b2d037e44d5671fdb6b35de9a3e1fa61cfbc8..cb8a0c28714eff46852f942030597a459d29d949 100644 (file)
@@ -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)
index 0cf19688c3f5ee775eb64604887c5cf7d0c08328..aeb5470399f4eec82a32533c24079f8c653dd2c9 100644 (file)
@@ -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()
index 33942467784ad3baf1c4df4e89093c2878d18eea..9b7d30e2164422da741a141a84b838d6f36d5323 100644 (file)
@@ -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)
index 0d5b6e08f0e223d451e8dd431c70ddcb92202ca1..b9e85bd8ff8f37ab1f61d62ccc351067a4a56bd3 100644 (file)
@@ -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)
index 9c94016f1339acad4d8af17ba085931d47e5679d..6020c0f055c7761398b49be75ef109bacef1ec9c 100644 (file)
@@ -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)
index bfcc62ccfb8ba0698eaefff628a4c1936698bb34..6539009df6242ab8d283650f5f6ef3567a4dec46 100644 (file)
@@ -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()
 
index b425e02f3bc144ee00a82c0112d0472e43264cd0..44ceff43f454df0d79ac550943bb3725ffd1c028 100644 (file)
@@ -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
index f706610b87e85b791fa44fdee9ec1bcd32ee4161..c3f228ef0ba1040a74f75b66687dd25411dea1f5 100644 (file)
@@ -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)
index 1c22f1ccdb7577be1a336e2327e018eea08ad26d..ceab14e8bff6221c1371806ebf5e5ef2caf6cbbe 100644 (file)
@@ -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)
index 0c1a7cf18aeb6e1a0a69791cee1e3e2652b98770..b796cdb95b65c6182b14c80b0c6589b33cbf340e 100644 (file)
@@ -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)
index 5c3ea318c397bdf650cc771d06d5b42631736abb..dbb615070bf44809875039807960d94be32a5b87 100644 (file)
@@ -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 {
index 2a9c8be30032493b685704a3692e40910d17c641..604b8e5aea3a226b0f5d0bd589e8aea6c75e86f7 100644 (file)
@@ -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
index 2798b9e0c4eb473b9e4060778eefe535d44e1707..f31b9d30c58add6f5f2846344df202effb648be7 100644 (file)
@@ -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)
index 157faf87d4c57504d89843aade55d677682b0641..e0ca14e11b279a466686ad6f8316b5bfff166c94 100644 (file)
@@ -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{
index eb838b2c88e47044e2cff209601492a1e8775055..e7ef39fd5b53b8bdad2ecb49d55ead5bae55c081 100644 (file)
@@ -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() {
index a46a34740380994470e7e2a44f18dcfed2664348..5f2af4476b86527153931392d09d732379634822 100644 (file)
@@ -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++ {
index e7e23e5a052cc4f51952a92ea9ec2def15fcf43a..79d986374f08a142794367673022b414af954738 100644 (file)
@@ -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{
index d0b21da7838643a58b93af9d7a1c73d631119ec5..9420248d2c0d60902d0a3ac08374907278410d8a 100644 (file)
@@ -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
index 8d13641516341a28b65b269d22998809021f8206..c5642d092d99826de2ee6642c4da78ae26d4d7a1 100644 (file)
@@ -101,7 +101,6 @@ func TestMirrorWithReflect(t *testing.T) {
                {".", "reflectlite", rl},
                {reflectDir, "reflect", r},
        } {
-               tc := tc
                wg.Add(1)
                go func() {
                        defer wg.Done()
index 39ae77471e7f73a8efae8d1b17eee8dc55ebf108..e0733b827dfd1943ffd8e450467abaf006f79d03 100644 (file)
@@ -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)
index 42a83718877e1f00e8d3354c14f6f316a58a70d8..355a6ff529f2aefbc6361245e9c3c62c42be41bc 100644 (file)
@@ -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)
index 6f106b65b77814e2931a8209804fa5d18a48f822..20365745a5402e3d4c2f46b65f1c1535d0b7237c 100644 (file)
@@ -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)
index f2a2e1b5851314a2c9ada47186320cc21e7c235c..eb06af8a14b324d3c7c87029f3bee93c4645a0e6 100644 (file)
@@ -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)
index cec225f75131f2cd0fe1e3fee1f783231eb95097..0d94bcbc4cb41a8be312c619efff53efc7ed5d8a 100644 (file)
@@ -145,7 +145,6 @@ func TestWithSimulated(t *testing.T) {
                        continue
                }
 
-               tr := tr
                t.Run(tr, func(t *testing.T) {
                        t.Parallel()
 
index 0ba51b4dbd4f2c1576b707ac7229e4a54808d545..25c24244c46a7bd50b6a80683cf1b89c2894c5a3 100644 (file)
@@ -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$")
index d1e1e7bf1cdf321b321a764aa165b26d279d69fb..87097e10ee3281c46744fad7d713fc7335f4a7d2 100644 (file)
@@ -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)
index 829b80c33a198d4cf213d300ee0b1938db57a2b7..07a9b46ddb69ef450a8502c159d5418c2dad7cdb 100644 (file)
@@ -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"
index ff254336211606c9c41bbcc4dabf097e9984cfc5..8026144c3da7f523090f52c7829e956877b93baa 100644 (file)
@@ -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 {
index 9b34ad080efe1ae2b9e9692fa344ea3aea0bd3e6..32fb696fee792a57df24b680251f0eba80702b66 100644 (file)
@@ -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 {
index 099697651465adb1e7131b3c7a10e3b326a69b6d..9d1c4430c9b01c7de4a59cdf1333d2086651654f 100644 (file)
@@ -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 {
index aee6288f3b253b746f1a748caee246cb3a8aee86..4a16ba02af6cee57f1c7a05adbd5ee43eae618e5 100644 (file)
@@ -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)
index 75dbd25d2252da2e1ffece859c6befb550cfbbf3..8ab4107fb7b6b99f7bfbd83a3d1b0e8759cc16f6 100644 (file)
@@ -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) {
index 7269db8f2be0fe6ed668f105b44d195d6f456209..637c95540f41bc805c664ab122120a54c44bb07a 100644 (file)
@@ -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)
index eb6b111f1f5ffbe0a6b057e373e2def571427ddf..cc9e9857099af2322576e22276ff56babf1967d9 100644 (file)
@@ -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)
index 0d009f6999386529add54f7a38b25dc8cf04c55b..b7f8c613b4b1a20163e055e6e379e982cad222f4 100644 (file)
@@ -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()
 
index 6758afddcaae0cdc40f9205df0a22c380f5b2158..f6c5679f4291b35d1977533eac221cbba9d1fe55 100644 (file)
@@ -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 {
index 77c5fc11e482132708acf2a807546ec09fce247e..0711fac90e7c14db635850c3bde68f2cc33bc5ef 100644 (file)
@@ -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()
 
index 0aa0439b90c390376ddd77b9fd5e02df448f16cb..8d3f230178ece57041cef7ee21315ae4fa6a082f 100644 (file)
@@ -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()
 
index efdb3c603592eef3942a65e4fd79bc8349dde46c..ad99f70287f74caa2b2a99c68def095b2cd305da 100644 (file)
@@ -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 {
index c6610b1968a83475bb3160793fb145046a3712b6..1fa850a27562ce245489fc064583ac8ddf4efc41 100644 (file)
@@ -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))
index 66d545dd1f7c2cc185ab358f8114ec0c92412961..eca0925f966283beed06eb05dc2b0dc68104d2aa 100644 (file)
@@ -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)
index 526d45bb43013675593ba87265bc0cad176b0741..5a1ca52a8c3b03f9767a0867521bffe5fe2bc2e4 100644 (file)
@@ -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
index 119708be7f52aca74b9d2c1841667ba760341c3c..d08b0524499b62bf636657fda940763548dc846e 100644 (file)
@@ -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()
index b77ff8dafdd2d4b08e66db0c9be1846a367546f2..baf4523a7ae109da3aa2a025df2a93d707b48e45 100644 (file)
@@ -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
index a26b35b44dc173edae4e45e9d038776709e9da56..9e93b219f17795dd641bb6be85da0e0043de8f99 100644 (file)
@@ -493,7 +493,6 @@ func BenchmarkMapInterfacePtr(b *testing.B) {
        m := map[any]bool{}
 
        for i := 0; i < 100; i++ {
-               i := i
                m[&i] = true
        }
 
index 22905504d45e3a28b085d155d7a0fd89c67900c8..6065a845539c530ce9b80221c10f79908094c9fa 100644 (file)
@@ -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)
index ef1483d629ea13345422f5a91524b456b65446d1..4b9cbf558909d4ae65b95199bc89a81a56a1ab3f 100644 (file)
@@ -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()
 
index 7b86ae8ffcab35e319793903ad325d0340157bce..4f9dbac4815dfe76a8774851e2bbfd1979775231 100644 (file)
@@ -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)
index ded7a799223743d3121af8983603674c3a2b5a98..45badcb2606f915ed69b376aacd0e4fb9e88297b 100644 (file)
@@ -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)
index 19b4e04807ee1b69dac492ab4213137bb56395fb..523a1c0b07f15e555b2de77e1f8c6cf848e26c6b 100644 (file)
@@ -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)
index cf49f7750780b5dae9a86e14d11140a5e3221538..755f423f960f24987566ae03c1bc902da7a25844 100644 (file)
@@ -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)
index 3b606f62e4320cc944af19c71b0493d1d7b220b0..d10d4a1fc931ccefe7a47309a1baf972d8ec143e 100644 (file)
@@ -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
index 721da965e35800a8a9ba72259bcd2e880d839544..b8bc8b8851b65673a96b3a807c7f3fdf012ccf67 100644 (file)
@@ -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() {
index 69d49169446d1ccf2dbdead3a282f36a8f02b3f9..ac04e51b144cb3132a6885627314f98abc883c58 100644 (file)
@@ -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()
index 6a7754425d5bb860f2d5ce10b3809ee973bb268c..fb65e1592811e3b3c003a7db5680bdc8d991e2d2 100644 (file)
@@ -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)
index fc84175ee6f0dd6802df142734deb19afbffd5d0..01a34b08019edde9b59a4dd3e985b097188494ad 100644 (file)
@@ -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 {
index bb5586d9fcb5268c0c25c712f4989a9a5570b11a..5d5573ccec506b92019d65c16f9ecdd33338898f 100644 (file)
@@ -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
index b9e81b98febef27231a9065140e6fe68ff7f7885..c87f420f8f360edb6a1e03924fe0c365eac6cbc4 100644 (file)
@@ -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)