asomers / mockall

A powerful mock object library for Rust
Apache License 2.0
1.5k stars 62 forks source link

Concretize doesn't work with cfg_attr #427

Closed asomers closed 1 year ago

asomers commented 1 year ago

The #[concretize] attribute isn't processed as a real Rust attribute. It's processed as text by Mockall, and used as a directive to tell it how to mock something that's already being mocked. That's why it must be used with its canonical name; you can't do use mockall::concretize as something_else. But as of this writing, Mockall doesn't process the text correctly if it appears within a cfg_attr directive. Instead, it passes it through in the emitted code, causing various compile failures. This example will trigger the problem.

use std::path::Path;

#[cfg(test)]
use mockall::{automock, concretize};

#[cfg_attr(test, automock)]
trait Foo {
    #[cfg_attr(test, concretize)]
    fn foo<P: AsRef<Path>>(&self, p: P);
}

First reported as https://github.com/asomers/mockall/pull/408#issuecomment-1312794561 .

asomers commented 1 year ago

@cjriches this should be fixed now.

cjriches commented 1 year ago

Thanks! Yup, seems to work now.

horacimacias commented 12 months ago

I'm trying to use this but if I understand correctly this concretize is on a non-released version of mockall. Any idea when a new release containing concretize will be available?

asomers commented 12 months ago

I've held off from releasing it because it's a big change, not just to the implementation but to the API. And it's a weird change, too. I haven't heard much feedback about it. Why don't you try it out, on the master branch, and let me know how it works for you?

horacimacias commented 12 months ago

sure, let me give it a try. thanks!