mirror of
https://codeberg.org/JasterV/test-context.git
synced 2026-04-26 18:10:06 +00:00
refactor: remove support for async-trait crate
This commit is contained in:
parent
d932f8529f
commit
cb4043fae6
5 changed files with 23 additions and 24 deletions
|
|
@ -41,7 +41,6 @@ struct MyAsyncContext {
|
|||
value: String
|
||||
}
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl AsyncTestContext for MyAsyncContext {
|
||||
async fn setup() -> MyAsyncContext {
|
||||
MyAsyncContext { value: "Hello, World!".to_string() }
|
||||
|
|
|
|||
|
|
@ -9,7 +9,6 @@ use quote::{format_ident, quote};
|
|||
/// ```ignore
|
||||
/// #[test_context(MyContext)]
|
||||
/// #[test]
|
||||
/// #[ignore]
|
||||
/// fn my_test() {
|
||||
/// }
|
||||
/// ```
|
||||
|
|
@ -18,7 +17,6 @@ use quote::{format_ident, quote};
|
|||
///
|
||||
/// ```ignore
|
||||
/// #[test]
|
||||
/// #[ignore]
|
||||
/// #[test_context(MyContext)]
|
||||
/// fn my_test() {
|
||||
/// }
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
[package]
|
||||
name = "test-context"
|
||||
rust-version = "1.75.0"
|
||||
description = "A library for providing custom setup/teardown for Rust tests without needing a test harness"
|
||||
readme = "../README.md"
|
||||
keywords = ["test", "setup", "teardown"]
|
||||
|
|
@ -13,7 +14,6 @@ license.workspace = true
|
|||
|
||||
[dependencies]
|
||||
test-context-macros = { version = "0.1.6", path = "../test-context-macros/" }
|
||||
async-trait = "0.1.42"
|
||||
futures = "0.3"
|
||||
|
||||
[dev-dependencies]
|
||||
|
|
|
|||
|
|
@ -27,14 +27,13 @@
|
|||
//! Alternatively, you can use `async` functions in your test context by using the
|
||||
//! `AsyncTestContext`.
|
||||
//!
|
||||
//! ```
|
||||
//! ```no_run
|
||||
//! use test_context::{test_context, AsyncTestContext};
|
||||
//!
|
||||
//! struct MyAsyncContext {
|
||||
//! value: String
|
||||
//! }
|
||||
//!
|
||||
//! #[async_trait::async_trait]
|
||||
//! impl AsyncTestContext for MyAsyncContext {
|
||||
//! async fn setup() -> MyAsyncContext {
|
||||
//! MyAsyncContext { value: "Hello, world!".to_string() }
|
||||
|
|
@ -46,6 +45,7 @@
|
|||
//! }
|
||||
//!
|
||||
//! #[test_context(MyAsyncContext)]
|
||||
//! #[test]
|
||||
//! fn test_works(ctx: &mut MyAsyncContext) {
|
||||
//! assert_eq!(ctx.value, "Hello, World!");
|
||||
//! }
|
||||
|
|
@ -55,20 +55,22 @@
|
|||
//! [`actix_rt::test`](https://docs.rs/actix-rt/1.1.1/actix_rt/attr.test.html) or
|
||||
//! [`tokio::test`](https://docs.rs/tokio/1.0.2/tokio/attr.test.html).
|
||||
//!
|
||||
//! ```
|
||||
//! # use test_context::{test_context, AsyncTestContext};
|
||||
//! # struct MyAsyncContext {
|
||||
//! # value: String
|
||||
//! # }
|
||||
//! # #[async_trait::async_trait]
|
||||
//! # impl AsyncTestContext for MyAsyncContext {
|
||||
//! # async fn setup() -> MyAsyncContext {
|
||||
//! # MyAsyncContext { value: "Hello, world!".to_string() }
|
||||
//! # }
|
||||
//! # async fn teardown(self) {
|
||||
//! # // Perform any teardown you wish.
|
||||
//! # }
|
||||
//! # }
|
||||
//! ```no_run
|
||||
//! use test_context::{test_context, AsyncTestContext};
|
||||
//!
|
||||
//! struct MyAsyncContext {
|
||||
//! value: String
|
||||
//! }
|
||||
//!
|
||||
//! impl AsyncTestContext for MyAsyncContext {
|
||||
//! async fn setup() -> MyAsyncContext {
|
||||
//! MyAsyncContext { value: "Hello, world!".to_string() }
|
||||
//! }
|
||||
//! async fn teardown(self) {
|
||||
//! // Perform any teardown you wish.
|
||||
//! }
|
||||
//! }
|
||||
//!
|
||||
//! #[test_context(MyAsyncContext)]
|
||||
//! #[tokio::test]
|
||||
//! async fn test_async_works(ctx: &mut MyAsyncContext) {
|
||||
|
|
@ -95,17 +97,18 @@ where
|
|||
}
|
||||
|
||||
/// The trait to implement to get setup/teardown functionality for async tests.
|
||||
#[async_trait::async_trait]
|
||||
pub trait AsyncTestContext
|
||||
where
|
||||
Self: Sized,
|
||||
{
|
||||
/// Create the context. This is run once before each test that uses the context.
|
||||
async fn setup() -> Self;
|
||||
fn setup() -> impl std::future::Future<Output = Self> + Send;
|
||||
|
||||
/// Perform any additional cleanup of the context besides that already provided by
|
||||
/// normal "drop" semantics.
|
||||
async fn teardown(self) {}
|
||||
fn teardown(self) -> impl std::future::Future<Output = ()> + Send {
|
||||
async {}
|
||||
}
|
||||
}
|
||||
|
||||
// Automatically impl TestContext for anything Send that impls AsyncTestContext.
|
||||
|
|
|
|||
|
|
@ -51,7 +51,6 @@ struct AsyncContext {
|
|||
n: u32,
|
||||
}
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl AsyncTestContext for AsyncContext {
|
||||
async fn setup() -> Self {
|
||||
Self { n: 1 }
|
||||
|
|
|
|||
Loading…
Reference in a new issue