Skip to content

proposal: cmd/vet: mark empty tests as errors #63785

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

Closed
ucirello opened this issue Oct 27, 2023 · 2 comments
Closed

proposal: cmd/vet: mark empty tests as errors #63785

ucirello opened this issue Oct 27, 2023 · 2 comments

Comments

@ucirello
Copy link
Contributor

Currently, go test runs a go vet before its execution. Traditionally, unused symbols in Go are considered compilation errors. This proposal aims to equate tests with empty bodies to unused symbols, and thus, they must be removed.

Right now, a test suite that looks like this:

// ...
func TestTarget(t *testing.T) {}
// ...

will return success:

=== RUN   TestTarget
--- PASS: TestTarget (0.00s)
PASS

With this proposal, instead of getting a test success, it would return a go vet error.

I cannot think of one legitimate use case for an empty test. It seems to be a human error always.

As source code analysis is necessary, it seems that cmd/vet is the more appropriate home for this change rather than cmd/build. Also, there is zero false positives in this case, as the AST that needs to be asserted is very small.

Ideally, it would target functions using *testing.T, *testing.B, *testing.F, testing.TB.

@gopherbot gopherbot added this to the Proposal milestone Oct 27, 2023
@seankhliao
Copy link
Member

a bar for inclusion into cmd/vet is frequency. How common are empty test functions?

@ucirello
Copy link
Contributor Author

ucirello commented Oct 27, 2023

In committed code, the frequency is low because empty tests are usually an artifact of building up a test suite/case. I do not have metrics in committed code to justify this proposal, except for occasional accidental commits that are soon fixed.

@golang golang locked and limited conversation to collaborators Oct 29, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants