rust-clippy
rust-clippy copied to clipboard
Test function name starts with `test_`
What it does
None of the examples in Rust guidelines on writing tests start functions with test_
, which makes for better code quality since tests::foo
is more readable than tests::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
#[cfg(test)]
mod tests {
#[test]
fn test_foo() {
assert!(true);
}
}
Could be written as:
rust
#[cfg(test)]
mod tests {
#[test]
fn foo() {
assert!(true);
}
}
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?
Could you elaborate? Maybe showing a module tree
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 test
in its name, kind of like https://rust-lang.github.io/rust-clippy/master/index.html#module_name_repetitions