Skip to content

Commit eb9367e

Browse files
authored
Merge pull request #37 from JasterV/refactor/remove-async-trait-support
refactor: remove support for async-trait crate
2 parents d932f85 + cb4043f commit eb9367e

File tree

5 files changed

+23
-24
lines changed

5 files changed

+23
-24
lines changed

README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ struct MyAsyncContext {
4141
value: String
4242
}
4343

44-
#[async_trait::async_trait]
4544
impl AsyncTestContext for MyAsyncContext {
4645
async fn setup() -> MyAsyncContext {
4746
MyAsyncContext { value: "Hello, World!".to_string() }

test-context-macros/src/lib.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ use quote::{format_ident, quote};
99
/// ```ignore
1010
/// #[test_context(MyContext)]
1111
/// #[test]
12-
/// #[ignore]
1312
/// fn my_test() {
1413
/// }
1514
/// ```
@@ -18,7 +17,6 @@ use quote::{format_ident, quote};
1817
///
1918
/// ```ignore
2019
/// #[test]
21-
/// #[ignore]
2220
/// #[test_context(MyContext)]
2321
/// fn my_test() {
2422
/// }

test-context/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
[package]
22
name = "test-context"
3+
rust-version = "1.75.0"
34
description = "A library for providing custom setup/teardown for Rust tests without needing a test harness"
45
readme = "../README.md"
56
keywords = ["test", "setup", "teardown"]
@@ -13,7 +14,6 @@ license.workspace = true
1314

1415
[dependencies]
1516
test-context-macros = { version = "0.1.6", path = "../test-context-macros/" }
16-
async-trait = "0.1.42"
1717
futures = "0.3"
1818

1919
[dev-dependencies]

test-context/src/lib.rs

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,13 @@
2727
//! Alternatively, you can use `async` functions in your test context by using the
2828
//! `AsyncTestContext`.
2929
//!
30-
//! ```
30+
//! ```no_run
3131
//! use test_context::{test_context, AsyncTestContext};
3232
//!
3333
//! struct MyAsyncContext {
3434
//! value: String
3535
//! }
3636
//!
37-
//! #[async_trait::async_trait]
3837
//! impl AsyncTestContext for MyAsyncContext {
3938
//! async fn setup() -> MyAsyncContext {
4039
//! MyAsyncContext { value: "Hello, world!".to_string() }
@@ -46,6 +45,7 @@
4645
//! }
4746
//!
4847
//! #[test_context(MyAsyncContext)]
48+
//! #[test]
4949
//! fn test_works(ctx: &mut MyAsyncContext) {
5050
//! assert_eq!(ctx.value, "Hello, World!");
5151
//! }
@@ -55,20 +55,22 @@
5555
//! [`actix_rt::test`](https://docs.rs/actix-rt/1.1.1/actix_rt/attr.test.html) or
5656
//! [`tokio::test`](https://docs.rs/tokio/1.0.2/tokio/attr.test.html).
5757
//!
58-
//! ```
59-
//! # use test_context::{test_context, AsyncTestContext};
60-
//! # struct MyAsyncContext {
61-
//! # value: String
62-
//! # }
63-
//! # #[async_trait::async_trait]
64-
//! # impl AsyncTestContext for MyAsyncContext {
65-
//! # async fn setup() -> MyAsyncContext {
66-
//! # MyAsyncContext { value: "Hello, world!".to_string() }
67-
//! # }
68-
//! # async fn teardown(self) {
69-
//! # // Perform any teardown you wish.
70-
//! # }
71-
//! # }
58+
//! ```no_run
59+
//! use test_context::{test_context, AsyncTestContext};
60+
//!
61+
//! struct MyAsyncContext {
62+
//! value: String
63+
//! }
64+
//!
65+
//! impl AsyncTestContext for MyAsyncContext {
66+
//! async fn setup() -> MyAsyncContext {
67+
//! MyAsyncContext { value: "Hello, world!".to_string() }
68+
//! }
69+
//! async fn teardown(self) {
70+
//! // Perform any teardown you wish.
71+
//! }
72+
//! }
73+
//!
7274
//! #[test_context(MyAsyncContext)]
7375
//! #[tokio::test]
7476
//! async fn test_async_works(ctx: &mut MyAsyncContext) {
@@ -95,17 +97,18 @@ where
9597
}
9698

9799
/// The trait to implement to get setup/teardown functionality for async tests.
98-
#[async_trait::async_trait]
99100
pub trait AsyncTestContext
100101
where
101102
Self: Sized,
102103
{
103104
/// Create the context. This is run once before each test that uses the context.
104-
async fn setup() -> Self;
105+
fn setup() -> impl std::future::Future<Output = Self> + Send;
105106

106107
/// Perform any additional cleanup of the context besides that already provided by
107108
/// normal "drop" semantics.
108-
async fn teardown(self) {}
109+
fn teardown(self) -> impl std::future::Future<Output = ()> + Send {
110+
async {}
111+
}
109112
}
110113

111114
// Automatically impl TestContext for anything Send that impls AsyncTestContext.

test-context/tests/test.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ struct AsyncContext {
5151
n: u32,
5252
}
5353

54-
#[async_trait::async_trait]
5554
impl AsyncTestContext for AsyncContext {
5655
async fn setup() -> Self {
5756
Self { n: 1 }

0 commit comments

Comments
 (0)