Skip to content
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

Dependency issues when using unimock #26

Closed
wackazong opened this issue Jul 19, 2023 · 6 comments
Closed

Dependency issues when using unimock #26

wackazong opened this issue Jul 19, 2023 · 6 comments

Comments

@wackazong
Copy link

wackazong commented Jul 19, 2023

Hi there, a couple of issues with dependencies I noticed. Thanks for this elegant library, I searched high and low for a solid dependency injection in Rust and this is the only one I think makes sense.

I use cargo build --tests to build.

Using the unimock option for the entrait macro

Given this cargo.toml

[package]
name = "entrait-issue"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
entrait = "0.5.3"

and this main.rs

use entrait::entrait;

#[entrait(Foo, unimock, mock_api=FooMock)]
fn foo<D>(_: &D) -> i32 {
    unimplemented!()
}

#[entrait(MyMod, unimock, mock_api=mock)]
mod my_mod {
    pub fn bar<D>(_: &D) -> i32 {
        unimplemented!()
    }
}

fn main(){}

I get the error error[E0433]: failed to resolve: could not find `__unimock` in `entrait

Using the unimock feature

When I switch to the unimock feature in cargo.toml things get better.

[package]
name = "entrait-issue"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
entrait = { version = "0.5.3", features = ["unimock"] }

[dev-dependencies]
unimock = "0.5.3"

Here is the main.rs for this case

use entrait::entrait;

#[entrait(Foo, mock_api=FooMock)]
fn foo<D>(_: &D) -> i32 {
    unimplemented!()
}
#[entrait(MyMod, mock_api=mock)]
mod my_mod {
    pub fn bar<D>(_: &D) -> i32 {
        unimplemented!()
    }
}

fn my_func(deps: &(impl Foo + MyMod)) -> i32 {
    deps.foo() + deps.bar()
}

fn main() {}

#[cfg(test)]
mod tests {
    use super::*;
    use unimock::*;    

    #[test]
    fn test() {
        let mocked_deps = Unimock::new((
            FooMock.each_call(matching!()).returns(40),
            my_mod::mock::bar.each_call(matching!()).returns(2),
        ));

        assert_eq!(42, my_func(&mocked_deps));
    }
}

Still, the compiler complains no method named `each_call` found for struct `FooMock` in the current scope

What I did to work around this problem was to import entrait::__unimock::* instead of use unimock::*;.

Am I overlooking something (quite likely) or are these bugs?

@wackazong wackazong reopened this Jul 20, 2023
@audunhalland
Copy link
Owner

Sorry, I was on vacation when this bug was filed, and I didn't get the notification.

The thing is, entrait is a little out of date, and still uses unimock 0.4.x. I've planned for some time to release a new major version of entrait with better ergonomics for mocking. The fix for now is to depend on unimock 0.4!

@wackazong
Copy link
Author

Hi, thanks for the reply. Good to see that there is still activity here. Looking forward to the next version then. Is there a roadmap for entrait/unimock?

@audunhalland
Copy link
Owner

I don't really have a roadmap. It's mostly ergonomic improvements and small tweaks I think, I haven't planned any major features. Lately I've focused more on Unimock, and when I think the 0.5 branch is in a good state, I'll publish a new major entrait version. I'm working on this in my spare time when I have time, development has slowed down a bit because it's now more busy on my day job.

@wackazong
Copy link
Author

wackazong commented Sep 15, 2023 via email

@audunhalland
Copy link
Owner

entrait 0.6.0 has been released with the only breaking change being the unimock 0.5 bump.

@audunhalland
Copy link
Owner

Closing this as fixed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants