kunwardeep
Repos
42
Followers
1
Following
5

Events

Nested range causes false positive "Range statement [..] does not reinitialise the variable"

Repro: https://gist.github.com/prashantv/9febe96e7df2b0d5311fa3b4aedb3059

Using the latest release of paralleltest (1.0.3) raises an incorrect issue:

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

tt2 is reinitialized: https://gist.github.com/prashantv/9febe96e7df2b0d5311fa3b4aedb3059#file-foo_test-go-L31

This seems related to https://github.com/kunwardeep/paralleltest/issues/8 (though the last comment on the issue indicates the issue is fixed)

Created at 2 weeks ago
Support ranges over maps

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)
		})
	}
}
Created at 2 weeks ago
Breaking change introduced by v1.0.6 - removal of `NewAnalyzer`

In https://github.com/kunwardeep/paralleltest/commit/8da1323054fee1167a31e061738c6408e42e3341 we've removed the NewAnalyzer method which is used by other tools, such as golangci-lint

Created at 2 weeks ago
kunwardeep create branch main
Created at 1 month ago
create repository
kunwardeep create repository
Created at 1 month ago