audunhalland / entrait

Loosely coupled Rust application design made easy
83 stars 1 forks source link

Dependency issues when using unimock #26

Closed wackazong closed 11 months ago

wackazong commented 1 year ago

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?

audunhalland commented 1 year ago

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 commented 1 year ago

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 commented 1 year ago

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 commented 1 year ago

OK, that is understandable. I am fine with entrait as it is, still looking forward to improvement with unimock. Thanks for this fine piece of software.

On Fri, 15 Sep 2023 at 12:41, Audun Halland @.***> wrote:

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.

— Reply to this email directly, view it on GitHub https://github.com/audunhalland/entrait/issues/26#issuecomment-1721058988, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAAQNG2BKMD7NDNJZYKAPGTX2QWENANCNFSM6AAAAAA2QR4AL4 . You are receiving this because you modified the open/close state.Message ID: @.***>

audunhalland commented 11 months ago

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

audunhalland commented 11 months ago

Closing this as fixed.