-
Notifications
You must be signed in to change notification settings - Fork 130
Closed
Labels
bugSomething isn't workingSomething isn't working
Description
Example Code
I have the following test helper, which temporarily clears all environment variables:
func stashEnv(t *testing.T) {
t.Helper()
environ := os.Environ()
t.Cleanup(func() {
for _, val := range environ {
parts := strings.Split(val, "=")
os.Setenv(parts[0], parts[1])
}
})
os.Clearenv()
}
Expected
I would not expect advice to rename it as a test, since it is a test helper.
Actual
Gocritic offers me the following advice:
sloppyTestFuncName: function stashEnv should be of form TestXXX(t *testing.T)
Additional Information
If I change the test name to testStashEnv
, I get the following advice, which is good advice:
sloppyTestFuncName: function testStashEnv looks like a test helper, consider to change 1st param to 'tb testing.TB'
If I follow that advice with the original function name, both errors go away:
func stashEnv(t testing.TB) {
// ...
}
The rule logic seems to consider test
a special prefix that means "test helper", but in this particular case I think stashEnv
is a more appropriate name than anything starting with test
might be.
cristaloleg, mibo-fdc and zemanlx
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working