-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Test function name starts with test_
#8931
Comments
I've seen that sometimes the test functions are directly in the module that gets tested and not a nested module. I guess the lint isn't applicable in that case. |
Could you elaborate? Maybe showing a module tree |
Is anyone looking into this? |
Something like that struct Foo;
// test `Foo` in the middle of the file
#[cfg(test)]
#[test]
fn test_foo() { todo!() }
struct Bar;
// test `Bar` in the middle of the file
#[cfg(test)]
#[test]
fn test_bar() { todo!() }
// ... |
Oh I didn't know you could do that, we could just limit this lint for items in a module containing |
i personally don't see a point to the if the function is a test, we can see #[cfg(test)]
#[test] // it says test right here. it's the same thing, just moved up a line.
fn foo_works() { todo!() } so it's obvious in the code. and when we run tests, we see test foo_works ... ok so |
@rustbot claim |
@Caylub are you still working on this? If not, I'd like to give it a try (starting with the review comments in your PR). |
@farazdagi Yeah, this is my bad, I opened this with good intentions, and never followed through. Feel free to pick this up! |
Thank you! |
What it does
None of the examples in Rust guidelines on writing tests start functions with
test_
, which makes for better code quality sincetests::foo
is more readable thantests::test_foo
Somewhat related to: clippy::module_name_repetitions
Lint Name
test_name_repetitions
Category
pedantic
Advantage
Make the code match Rust guidelines thus making it more idiomatic
Drawbacks
Not sure
Example
Could be written as:
The text was updated successfully, but these errors were encountered: