mirror of
https://codeberg.org/JasterV/test-context.git
synced 2026-04-26 18:10:06 +00:00
add basic impl TestContext for AsyncTestContext
This commit is contained in:
parent
c55eed5464
commit
8d349b6f0c
2 changed files with 21 additions and 0 deletions
15
src/lib.rs
15
src/lib.rs
|
|
@ -84,3 +84,18 @@ where
|
|||
/// normal "drop" semantics.
|
||||
async fn teardown(self) {}
|
||||
}
|
||||
|
||||
// Automatically impl TestContext for anything Send that impls AsyncTestContext.
|
||||
//
|
||||
// A future improvement may be to use feature flags to enable using a specific runtime
|
||||
// to run the future synchronously. This is the easiest way to implement it, though, and
|
||||
// introduces no new dependencies.
|
||||
impl<T> TestContext for T where T: AsyncTestContext + Send {
|
||||
fn setup() -> Self {
|
||||
futures::executor::block_on(<T as AsyncTestContext>::setup())
|
||||
}
|
||||
|
||||
fn teardown(self) {
|
||||
futures::executor::block_on(<T as AsyncTestContext>::teardown(self))
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -94,3 +94,9 @@ async fn async_return_value_func(ctx: &mut AsyncContext) -> u32 {
|
|||
async fn async_includes_return_value() {
|
||||
assert_eq!(async_return_value_func().await, 1);
|
||||
}
|
||||
|
||||
#[test_context(AsyncContext)]
|
||||
#[test]
|
||||
fn async_auto_impls_sync(ctx: &mut AsyncContext) {
|
||||
assert_eq!(ctx.n, 1);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue