From 8cfd3d4fe167e928e617626d1ffc73b1fbcc192e Mon Sep 17 00:00:00 2001 From: Gonzalo Serrano Date: Tue, 19 Aug 2025 16:41:34 +0700 Subject: [PATCH 1/4] 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 --- src/test-table.md | 27 +-------------------------- 1 file changed, 1 insertion(+), 26 deletions(-) diff --git a/src/test-table.md b/src/test-table.md index eafbf3ca..780d320c 100644 --- a/src/test-table.md +++ b/src/test-table.md @@ -238,31 +238,6 @@ for multiple inputs/outputs to a system. ## Parallel Tests -Parallel tests, like some specialized loops (for example, those that spawn -goroutines or capture references as part of the loop body), -must take care to explicitly assign loop variables within the loop's scope to -ensure that they hold the expected values. - -```go -tests := []struct{ - give string - // ... -}{ - // ... -} - -for _, tt := range tests { - tt := tt // for t.Parallel - t.Run(tt.give, func(t *testing.T) { - t.Parallel() - // ... - }) -} -``` - -In the example above, we must declare a `tt` variable scoped to the loop -iteration because of the use of `t.Parallel()` below. -If we do not do that, most or all tests will receive an unexpected value for -`tt`, or a value that changes as they're running. +Run `t.Parallel()` to improve the performance of your test cases. From 71ce86f12684b4c45c8be0ae467e186fe85169e6 Mon Sep 17 00:00:00 2001 From: gonzaloserrano <349328+gonzaloserrano@users.noreply.github.com> Date: Tue, 19 Aug 2025 09:41:59 +0000 Subject: [PATCH 2/4] Auto-update style.md --- style.md | 27 +-------------------------- 1 file changed, 1 insertion(+), 26 deletions(-) diff --git a/style.md b/style.md index bf0d20bb..7521d1ff 100644 --- a/style.md +++ b/style.md @@ -3898,32 +3898,7 @@ for multiple inputs/outputs to a system. #### Parallel Tests -Parallel tests, like some specialized loops (for example, those that spawn -goroutines or capture references as part of the loop body), -must take care to explicitly assign loop variables within the loop's scope to -ensure that they hold the expected values. - -```go -tests := []struct{ - give string - // ... -}{ - // ... -} - -for _, tt := range tests { - tt := tt // for t.Parallel - t.Run(tt.give, func(t *testing.T) { - t.Parallel() - // ... - }) -} -``` - -In the example above, we must declare a `tt` variable scoped to the loop -iteration because of the use of `t.Parallel()` below. -If we do not do that, most or all tests will receive an unexpected value for -`tt`, or a value that changes as they're running. +Run `t.Parallel()` to improve the performance of your test cases. From 2ef6107b05ff32c3deb31dcee6cfecd920726325 Mon Sep 17 00:00:00 2001 From: Gonzalo Serrano Date: Thu, 21 Aug 2025 09:31:28 +0700 Subject: [PATCH 3/4] Remove refs to Parallel tests --- style.md | 4 ---- 1 file changed, 4 deletions(-) diff --git a/style.md b/style.md index 7521d1ff..ca5d2cc1 100644 --- a/style.md +++ b/style.md @@ -3896,10 +3896,6 @@ While there are no strict guidelines, readability and maintainability should always be top-of-mind when deciding between Table Tests versus separate tests for multiple inputs/outputs to a system. -#### Parallel Tests - -Run `t.Parallel()` to improve the performance of your test cases. - ### Functional Options From 0911fb094c045838f11b4b2ec0d235c90c5e6e1d Mon Sep 17 00:00:00 2001 From: Gonzalo Serrano Date: Thu, 21 Aug 2025 09:33:55 +0700 Subject: [PATCH 4/4] Actually remove refs to Parallel tests from the src --- src/test-table.md | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/test-table.md b/src/test-table.md index 780d320c..65fd2c52 100644 --- a/src/test-table.md +++ b/src/test-table.md @@ -236,8 +236,4 @@ While there are no strict guidelines, readability and maintainability should always be top-of-mind when deciding between Table Tests versus separate tests for multiple inputs/outputs to a system. -## Parallel Tests - -Run `t.Parallel()` to improve the performance of your test cases. -