Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support ranges over maps #14

Closed
kevgo opened this issue Jan 20, 2022 · 2 comments
Closed

Support ranges over maps #14

kevgo opened this issue Jan 20, 2022 · 2 comments

Comments

@kevgo
Copy link

kevgo commented Jan 20, 2022

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)
		})
	}
}
@kunwardeep
Copy link
Owner

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
Copy link
Owner

Hey @kevgo would you be able to test this with the latest fix?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants