Skip to content

Commit 8cfd3d4

Browse files
Fix reference to variable scoping inside parallel t.Run executions
Since Go 1.22 that's not needed anymore, see https://tip.golang.org/doc/go1.22#language
1 parent 9731441 commit 8cfd3d4

File tree

1 file changed

+1
-26
lines changed

1 file changed

+1
-26
lines changed

src/test-table.md

Lines changed: 1 addition & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -238,31 +238,6 @@ for multiple inputs/outputs to a system.
238238

239239
## Parallel Tests
240240

241-
Parallel tests, like some specialized loops (for example, those that spawn
242-
goroutines or capture references as part of the loop body),
243-
must take care to explicitly assign loop variables within the loop's scope to
244-
ensure that they hold the expected values.
245-
246-
```go
247-
tests := []struct{
248-
give string
249-
// ...
250-
}{
251-
// ...
252-
}
253-
254-
for _, tt := range tests {
255-
tt := tt // for t.Parallel
256-
t.Run(tt.give, func(t *testing.T) {
257-
t.Parallel()
258-
// ...
259-
})
260-
}
261-
```
262-
263-
In the example above, we must declare a `tt` variable scoped to the loop
264-
iteration because of the use of `t.Parallel()` below.
265-
If we do not do that, most or all tests will receive an unexpected value for
266-
`tt`, or a value that changes as they're running.
241+
Run `t.Parallel()` to improve the performance of your test cases.
267242

268243
<!-- TODO: Explain how to use _test packages. -->

0 commit comments

Comments
 (0)