-
Notifications
You must be signed in to change notification settings - Fork 69
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
Initial support for trait-variant #640
base: master
Are you sure you want to change the base?
Conversation
@asomers I think the nightly is failing because some sort of new lints unrelated to this PR, would you like me to fix those also here? |
It's already fixed on master. You just need to rebase. |
32a14f9
to
4e1e0e7
Compare
Great! It looks like it's ready now |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the tests could really benefit from some kind of assertion to check that they actually implement the additional trait. That might be hard to do with Send
, but what about something like this?
trait Foo {}
#[automock]
#[trait_variant::make(Foo)]
pub trait Bar {
...
}
#[test]
fn some_test_method_name() {
let mock = MockBar::new();
let p: Box<dyn Foo> = Box::new(mock); // Ensures that MockBar implements Foo
...
}
Also, with this change, does the #[trait_variant::make(OtherTraitName: Foo)]
syntax work?
I'm not that familiar with the codebase to implement all of those changes. On your first example, automock would not implement trait Foo {}
#[automock]
#[trait_variant::make(Foo)]
pub trait Bar {
...
}
impl Foo for MockBar {} The most common use case is to mark your trait (and async method futures) As for the second example, the syntax already works, but we would be mocking the initial trait only ( @asomers The main goal of this PR is to have feature parity with async_trait, other improvements could be added later. As mentioend on #639 the async_trait annotation can be located before or after the automock annotation, and that means you need to return the actual pinned future or just the future's output on the mocks expectations. With this PR we can do the same for trait_variant, so that the migration is painless. |
This PR aims to fix #639
Feel free to update the readme, as English is not my primary language