Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

maybe_async::test does not seem to work in a test module #14

Open
juliankrieger opened this issue Jul 4, 2022 · 1 comment
Open

maybe_async::test does not seem to work in a test module #14

juliankrieger opened this issue Jul 4, 2022 · 1 comment

Comments

@juliankrieger
Copy link

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());
   | 
@fMeow
Copy link
Owner

fMeow commented Aug 12, 2022

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants