maybe-async-rs
maybe-async-rs copied to clipboard
`maybe_async::test` does not seem to work in a `test` module
I have the following test case:
#[cfg(test)]
mod tests {
#[cfg(feature = "async")]
use tokio;
#[maybe_async::test(
feature="blocking",
async(feature = "async", tokio::test)
)]
async fn test_oauth() {
...
let client = dbg!Reddit::new(&USER_AGENT, &client_id, &client_secret)
.username(&username)
.password(&password)
.login()
.await;
}
}
The compiler throws the following error:
error[E0728]: `await` is only allowed inside `async` functions and blocks
--> tests\tests.rs:34:21
|
23 | async fn test_oauth() {
| ---------- this is not `async`
...
34 | .login()
| _____________________^
35 | | .await);
| |__________________^ only allowed inside `async` functions and blocks
error[E0728]: `await` is only allowed inside `async` functions and blocks
--> tests\tests.rs:41:28
|
23 | async fn test_oauth() {
| ---------- this is not `async`
...
41 | assert!(me.me().await.is_ok());
| ^^^^^^ only allowed inside `async` functions and blocks
error[E0277]: `Result<Me, RouxError>` is not a future
--> tests\tests.rs:34:21
|
34 | .login()
| _____________________^
35 | | .await);
| |__________________^ `Result<Me, RouxError>` is not a future
|
= help: the trait `Future` is not implemented for `Result<Me, RouxError>`
= note: Result<Me, RouxError> must be a future or must implement `IntoFuture` to be awaited
= note: required because of the requirements on the impl of `IntoFuture` for `Result<Me, RouxError>`
help: remove the `.await`
|
34 - .login()
34 + .login());
|
I'm confused.
#[maybe_async::test(
feature="blocking",
async(feature = "async", tokio::test)
)]
async fn test_oauth() {
The method test_oauth compiles on condition that feature "blocking" is enabled. And I assume feature gate named "blocking" should not allow async?