Test and source separation
Closed this issue · 3 comments
Hi I noticed that the example that the metadata attributes for testing are part of the code It's a bit odd to pollute source files like that. I tried inherited traits like so:
trait MyTestTrait: ARealTraitInSrcFile {// Could I derive from the trait and just mock that to avoid polluting the files in src/ ? Turns out no.
...
}
#[test]
pub fn test() {
let scenario = Scenario::new();
let mut mock = scenario.create_mock_for::<MyTestTrait>();
....
}
But that gave me an error
error: custom attribute panicked
--> tests/lexer.rs:11:1
|
11 | #[mocked]
| ^^^^^^^^^
|
= help: message: parent trait path must be given using 'refs' param
Am I just missing a fundamental piece of syntax that would allow me to mock things easily without all those #[mocked] annotations in my src/ files?
See Usage from test crate guide section
Hi, a little bit related to this: maybe I'm missing something, but if we just use #[mocked]
, when I'm building (cargo build
) it complains:
warning: unused attribute
--> src/main.rs:5:1
|
5 | #[mocked]
| ^^^^^^^^^
|
= note: #[warn(unused_attributes)] on by default
Finished dev [unoptimized + debuginfo] target(s) in 0.27s
In the main page of documentation, apparently it encourages to use #[cfg_attr(test, mocked)]
, what is better in my opinion, since you will not have these warnings. I'm wondering if we can encourage only the use of #[cfg_attr(test, mocked)]
or better, if there is a way to put this #[cfg_attr(test)]
inside the #[mocked]
that automatically would avoid these warnings.
It is technically possible, but I'm not sure that such implicitness is good.