Skip to content

Commit

Permalink
fix: unmock with async fn when the trait fn uses RPIT future
Browse files Browse the repository at this point in the history
  • Loading branch information
audunhalland committed Mar 27, 2024
1 parent 9cbcdfc commit c8e2875
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## Unreleased
### Fixed
- Unmocking using `async fn` when the trait fn has an `-> impl Future` signature.

## [0.6.0] - 2024-03-25
### Changed
Expand Down
15 changes: 15 additions & 0 deletions tests/it/unmock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,21 @@ mod unmock_async {
}
}

mod impl_future_in_trait_unmock_with_async_fn {
use core::future::Future;

use super::*;

#[unimock(unmock_with=[foo])]
trait Async {
fn foo(&self) -> impl Future<Output = i32>;
}

async fn foo(_: &impl core::any::Any) -> i32 {
42
}
}

mod unmock_with_custom_args {
use super::*;

Expand Down
2 changes: 1 addition & 1 deletion unimock_macros/src/unimock/method.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ impl<'t> MockMethod<'t> {
if self.method.sig.asyncness.is_some()
|| matches!(
self.output_structure.wrapping,
output::OutputWrapping::AssociatedFuture(_)
output::OutputWrapping::AssociatedFuture(_) | output::OutputWrapping::RpitFuture(_)
)
{
Some(DotAwait)
Expand Down

0 comments on commit c8e2875

Please sign in to comment.