Closed
Description
Thanks for this awesome linter! It has tripled the speed of my unit tests and I use it daily. I noticed an apparent false positive when using maps as test data. Consider this code snippet:
func Upper(text string) string {
return strings.ToUpper(text)
}
func TestUpper(t *testing.T) {
t.Parallel()
tests := map[string]string{
"one": "ONE",
"two": "TWO",
}
for test := range tests {
t.Run(test, func(t *testing.T) {
t.Parallel()
have := Upper(test)
want := tests[test]
assert.Equal(t, want, have)
})
}
}
paralleltest
produces this linter error which seems a false positive:
Range statement for test TestUpper does not use range value in test Run
Please note that it is also common to destructure the test
variable into give, want
. It would be phantastic if paralleltest
would supported that as well. Here is an example:
func Upper(text string) string {
return strings.ToUpper(text)
}
func TestUpper(t *testing.T) {
t.Parallel()
tests := map[string]string{
"one": "ONE",
"two": "TWO",
}
for give, want := range tests {
t.Run(give, func(t *testing.T) {
t.Parallel()
have := Upper(give)
assert.Equal(t, want, have)
})
}
}
Activity
kunwardeep commentedon Feb 4, 2022
Hey @kevgo. I am glad this linter has helped you. Would you please be able to raise a PR so that we can put a fix in ?
kunwardeep commentedon Jun 3, 2022
Hey @kevgo would you be able to test this with the latest fix?