unresolved import when using external crate in tests
R9295 opened this issue · comments
Hello,
I'm writing a dylint rule which checks for a specific function call derived from an external trait. I'm getting an unresolved import error when using an external crate in my tests.
Here's the test I'm writing (paraphrased)
# ui/main.rs
use serde::{Deserialize, Serialize};
#[derive(Debug, Deserialize, Serialize)]
struct Test {
a: u32,
b: u64,
}
fn main() {}
When I run cargo test
I get:
error[E0432]: unresolved import `serde`
--> $DIR/main.rs:1:5
|
LL | use serde::{Deserialize, Serialize};
| ^^^^^ maybe a missing crate `serde`?
|
= help: consider adding `extern crate serde` to use the `serde` crate
I've looked at your examples, and used extern crate
but was unable to get it to work.
Is there a way to use external crates in tests?
Hi, @R9295. Does your test use dylint_testing::ui_test_example
? If so, then it should be possible to declare external crates as dev-dependencies
. For comparison, here is a lint that uses anyhow
in this way:
dylint/examples/restriction/misleading_variable_name/Cargo.toml
Lines 12 to 14 in 43816b7
dylint/examples/restriction/misleading_variable_name/Cargo.toml
Lines 23 to 24 in 43816b7
dylint/examples/restriction/misleading_variable_name/src/lib.rs
Lines 284 to 287 in 43816b7
Ahhh, I was using the default dylint_testing::ui_test
instead of ui_test_example
.
Thanks for the quick response. Feel free to close the issue
This is good feedback. Thank you.
I will try to make mention of ui_test_example
more prominent in the documentation.
Cheers.