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

Add #[async_test] to futures-test crate? #1890

Closed
ngg opened this issue Sep 28, 2019 · 1 comment · Fixed by #2409
Closed

Add #[async_test] to futures-test crate? #1890

ngg opened this issue Sep 28, 2019 · 1 comment · Fixed by #2409

Comments

@ngg
Copy link
Contributor

ngg commented Sep 28, 2019

Hi!

I'm interested what you're thinking about adding an #[async_test] proc-macro to the futures-test crate.

There were previous discussions about it at #1169 (comment) and there are also some implementations existing already.

  • I have a kind of ugly (sry but I'm not good at proc-macros) but working implementation at futures-await-test-preview which uses futures_executor::LocalPool::new().run_until(), I'm not sure if this is better or worse then using block_on, for my use-cases it seems to work perfectly.
  • There is one created for tokio: tokio-async-await-test

Examples for intended use-case:

#[async_test]
async fn normal_test() {
    assert!(create_future().await == 4);
}

#[async_test]
#[should_panic]
async fn panic_test() {
    assert!(create_future().await == 5);
}

#[async_test]
async fn result_test() -> Result<(), ()> {
    assert!(create_result_future().await? == 4);
    Ok(())
}

Currently I use my implementation to write tests for a Rust wrapper around an asynchronous C++ library, which uses only futures-0.3, not tokio. I find it really useful, perhaps others would too even if it uses futures-executor only at first. Later it could be somehow extended to support other executors as well..

Would you be interested in adding something like this to futures-test?

@LucioFranco
Copy link
Member

@ngg tokio currently has one https://docs.rs/tokio/0.2.0-alpha.5/tokio/attr.test.html

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

Successfully merging a pull request may close this issue.

4 participants