Skip to content

Instantly share code, notes, and snippets.

@prashantv
Created October 26, 2021 03:09
Show Gist options
  • Save prashantv/9febe96e7df2b0d5311fa3b4aedb3059 to your computer and use it in GitHub Desktop.
Save prashantv/9febe96e7df2b0d5311fa3b4aedb3059 to your computer and use it in GitHub Desktop.
package main
import (
"fmt"
"testing"
)
func TestFoo(t *testing.T) {
t.Parallel()
tests1 := []struct {
name string
v string
}{
{"outer1-1", "outer1-1"},
{"outer1-2", "outer1-2"},
}
tests2 := []struct {
name string
v string
}{
{"outer2-1", "outer2-1"},
{"outer2-2", "outer2-2"},
}
for _, tt1 := range tests1 {
tt1 := tt1
t.Run(tt1.name, func(t *testing.T) {
for _, tt2 := range tests2 {
tt2 := tt2
t.Run(tt2.name, func(t *testing.T) {
t.Parallel()
fmt.Println(tt1.v, tt2.v)
})
}
})
}
}
@prashantv
Copy link
Author

$ ./bin/paralleltest .
[...]/foo_test.go:27:2: Range statement for test TestFoo does not reinitialise the variable tt2

using paralleltest 1.0.3:

> grep paralleltest go.*
go.mod: github.com/kunwardeep/paralleltest v1.0.3
go.sum:github.com/kunwardeep/paralleltest v1.0.3 h1:UdKIkImEAXjR1chUWLn+PNXqWUGs//7tzMeWuP7NhmI=
go.sum:github.com/kunwardeep/paralleltest v1.0.3/go.mod h1:vLydzomDFpk7yu5UX02RmP0H8QfRPOV/oFhWN85Mjb4=

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment