How to remove the "function is never used" warning for a function used only in tests?
Hello colleagues! I've just started learning Rust and encountered an annoying problem. I have a small utility and wrote a helper function that is only needed in tests. For example, to prepare test data.
Here's the simplified code:
```rust
fn prepare_test_data() -> Vec {
vec![1, 2, 3, 4, 5]
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_with_data() {
let data = prepare_test_data();
assert_eq!(data.len(), 5);
}
}
```
When I run `cargo build` (not tests, but a regular build), the compiler gives a warning:
```
warning: function `prepare_test_data` is never used
--> src/lib.rs:1:1
|
1 | fn prepare_test_data() -> Vec {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note:
No answers yet.
Log in to leave an answer