-
Notifications
You must be signed in to change notification settings - Fork 15
Open
Labels
bugSomething isn't workingSomething isn't working
Description
Hi,
I'm trying to mock nix::unistd::execvp which has the function signature below:
pub fn execvp<S: AsRef<CStr>>(
filename: &CStr,
args: &[S],
) -> Result<Infallible>
when I use InjectorPP with the lines below:
injector.when_called(injectorpp::func!(nix::unistd::execvp, fn(&std::ffi::CStr, &[&std::ffi::CStr]) -> nix::Result<std::convert::Infallible>))
.will_execute(injectorpp::fake!(
func_type: fn(_cmd: &std::ffi::CStr, _args: &[&std::ffi::CStr]) -> nix::Result<std::convert::Infallible>,
returns: Err(nix::errno::Errno::E2BIG)
)
);
I'm getting the compile time error:
error[E0308]: mismatched types
--> src/linux_util/namespace/mod.rs:221:48
|
221 | injector.when_called(injectorpp::func!(nix::unistd::execvp, fn(&std::ffi::CStr, &[&std::ffi::CStr]) -> nix::Result<std::convert::Infallible>))
| ^^^^^^^^^^^^^^^^^^^ -------------------------------------------------------------------------------- expected due to this
| |
| one type is more general than the other
|
= note: expected fn pointer `for<'a, 'b, 'c> fn(&'a CStr, &'b [&'c CStr]) -> Result<_, _>`
found fn item `for<'a, 'b> fn(&'a CStr, &'b [_]) -> Result<_, _> {nix::unistd::execvp::<_>}`
My questions are:
- I couldn't manage to avoid the lifetime mismatch between my mock signature and the real
execvpsignature. I don't see a way to define the lifetimes for the parameters within thefunc!macro. Is there any ways to achieve this? - I tried to use
&'staticlifetime for all the parameters in the mock signature to match the lifetime expectations and it helped me to avoid the compile time failure but the injector didn't catch the call toexecvpat all.
Thanks!
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working