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

Async test function attribute #2409

Merged
merged 5 commits into from May 7, 2021
Merged

Async test function attribute #2409

merged 5 commits into from May 7, 2021

Conversation

ibraheemdev
Copy link
Contributor

@ibraheemdev ibraheemdev commented May 6, 2021

#[futures_test::test]
async fn my_test() {
     let fut = async { true };
     assert!(fut.await);
}

Resolves #1890

@ibraheemdev ibraheemdev requested a review from taiki-e as a code owner May 6, 2021
@ibraheemdev
Copy link
Contributor Author

ibraheemdev commented May 6, 2021

This macro is actually not even testing specific. Maybe it should be called block_on and re-exported from futures_util/futures also?

Copy link
Member

@taiki-e taiki-e left a comment

Thanks!

Maybe it should be called block_on and re-exported from futures_util/futures also?

I tend to prefer to provide this attribute as part of futures-test until #2295 is done. (block_on is provided by futures-executor that depend on futures-util, so it is difficult to provide this as part of futures-util.)

futures-macro/src/executor.rs Outdated Show resolved Hide resolved
futures-macro/src/executor.rs Show resolved Hide resolved
futures-macro/src/executor.rs Outdated Show resolved Hide resolved
futures-macro/src/executor.rs Outdated Show resolved Hide resolved
futures-test/src/lib.rs Show resolved Hide resolved
@taiki-e taiki-e added 0.3-backport: pending A-macro futures-test labels May 6, 2021
ibraheemdev and others added 2 commits May 6, 2021
Co-authored-by: Taiki Endo <te316e89@gmail.com>

#[futures_test::test]
#[should_panic]
async fn it_is_being_run() {
Copy link
Contributor Author

@ibraheemdev ibraheemdev May 6, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know if there is a reliable way to test if the generate test actually gets run. If the macro regresses and omits the attrs and #[test], this will silently fail.

Copy link
Member

@taiki-e taiki-e May 6, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is good as-is for now.
macrotest is a crate for that use case (example), but it's difficult to use with #[futures_test::test], as it will show other code generated by #[test].

Copy link
Member

@taiki-e taiki-e left a comment

LGTM aside from a few nits.

futures/tests/test_macro.rs Outdated Show resolved Hide resolved
futures-test/src/lib.rs Show resolved Hide resolved
taiki-e
taiki-e approved these changes May 7, 2021
Copy link
Member

@taiki-e taiki-e left a comment

Thanks again.

@taiki-e taiki-e merged commit 84c2fed into rust-lang:master May 7, 2021
20 checks passed
@taiki-e taiki-e mentioned this pull request May 10, 2021
@taiki-e taiki-e added 0.3-backport: completed and removed 0.3-backport: pending labels May 10, 2021
@taiki-e taiki-e mentioned this pull request May 10, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants