| 1 | // Take a look at the license at the top of the repository in the LICENSE file. |
| 2 | |
| 3 | use proc_macrorust-analyzer cargo proc_macro https://github.com/rust-lang/rust/library/proc_macro crate/::TokenStreamrust-analyzer cargo proc_macro https://github.com/rust-lang/rust/library/proc_macro TokenStream#; |
| 4 | use quoterust-analyzer cargo quote 1.0.44 crate/::ToTokensrust-analyzer cargo quote 1.0.44 to_tokens/ToTokens#; |
| 5 | |
| 6 | pub(craterust-analyzer cargo glib-macros 0.22.6 crate/) fn async_testrust-analyzer cargo glib-macros 0.22.6 async_test/async_test().(_args: TokenStreamrust-analyzer cargo proc_macro https://github.com/rust-lang/rust/library/proc_macro TokenStream#, mut item: TokenStreamrust-analyzer cargo proc_macro https://github.com/rust-lang/rust/library/proc_macro TokenStream#) -> TokenStreamrust-analyzer cargo proc_macro https://github.com/rust-lang/rust/library/proc_macro TokenStream# { |
| 7 | let mut item_fn: synrust-analyzer cargo syn 2.0.117 crate/::ItemFnrust-analyzer cargo syn 2.0.117 item/ItemFn# = match synrust-analyzer cargo syn 2.0.117 crate/::parserust-analyzer cargo syn 2.0.117 parse().(item.clonerust-analyzer cargo proc_macro https://github.com/rust-lang/rust/library/proc_macro impl#[TokenStream][Clone]clone().()) { |
| 8 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(it) => it, |
| 9 | Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(e) => { |
| 10 | item.extendrust-analyzer cargo proc_macro https://github.com/rust-lang/rust/library/proc_macro impl#[TokenStream][`Extend<TokenTree>`]extend().(TokenStreamrust-analyzer cargo proc_macro https://github.com/rust-lang/rust/library/proc_macro TokenStream#::fromrust-analyzer cargo proc-macro2 1.0.106 impl#[`proc_macro::TokenStream`][`From<TokenStream>`]from().(e.into_compile_errorrust-analyzer cargo syn 2.0.117 error/impl#[Error]into_compile_error().())); |
| 11 | return item; |
| 12 | } |
| 13 | }; |
| 14 | |
| 15 | if item_fn.sigrust-analyzer cargo syn 2.0.117 item/ItemFn#sig..asyncnessrust-analyzer cargo syn 2.0.117 item/Signature#asyncness..is_nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]is_none().() { |
| 16 | item.extendrust-analyzer cargo proc_macro https://github.com/rust-lang/rust/library/proc_macro impl#[TokenStream][`Extend<TokenTree>`]extend().(TokenStreamrust-analyzer cargo proc_macro https://github.com/rust-lang/rust/library/proc_macro TokenStream#::fromrust-analyzer cargo proc-macro2 1.0.106 impl#[`proc_macro::TokenStream`][`From<TokenStream>`]from().( |
| 17 | synrust-analyzer cargo syn 2.0.117 crate/::Errorrust-analyzer cargo syn 2.0.117 error/Error#::new_spannedrust-analyzer cargo syn 2.0.117 error/impl#[Error]new_spanned().( |
| 18 | item_fn.sigrust-analyzer cargo syn 2.0.117 item/ItemFn#sig..identrust-analyzer cargo syn 2.0.117 item/Signature#ident., |
| 19 | "The 'async' keyword is missing from the test function declaration", |
| 20 | ) |
| 21 | .into_compile_errorrust-analyzer cargo syn 2.0.117 error/impl#[Error]into_compile_error().(), |
| 22 | )); |
| 23 | return item; |
| 24 | } |
| 25 | |
| 26 | item_fn.sigrust-analyzer cargo syn 2.0.117 item/ItemFn#sig..asyncnessrust-analyzer cargo syn 2.0.117 item/Signature#asyncness. = Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#; |
| 27 | |
| 28 | let gen_attr = quoterust-analyzer cargo quote 1.0.44 crate/::quoterust-analyzer cargo quote 1.0.44 quote!! { |
| 29 | #[::core::prelude::v1::test] |
| 30 | }; |
| 31 | |
| 32 | let body = &item_fn.blockrust-analyzer cargo syn 2.0.117 item/ItemFn#block.; |
| 33 | |
| 34 | item_fn.blockrust-analyzer cargo syn 2.0.117 item/ItemFn#block. = synrust-analyzer cargo syn 2.0.117 crate/::parse2rust-analyzer cargo syn 2.0.117 parse2().(quoterust-analyzer cargo quote 1.0.44 crate/::quoterust-analyzer cargo quote 1.0.44 quote!! { |
| 35 | { |
| 36 | let main_ctx = glib::MainContext::new(); |
| 37 | main_ctx.with_thread_default(|| main_ctx.block_on(async #body)) |
| 38 | .expect("cannot set thread default main context for test") |
| 39 | } |
| 40 | }) |
| 41 | .expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]expect().("Body parsing failure"); |
| 42 | |
| 43 | let mut tokens = TokenStreamrust-analyzer cargo proc_macro https://github.com/rust-lang/rust/library/proc_macro TokenStream#::newrust-analyzer cargo proc_macro https://github.com/rust-lang/rust/library/proc_macro impl#[TokenStream]new().(); |
| 44 | tokens.extendrust-analyzer cargo proc_macro https://github.com/rust-lang/rust/library/proc_macro impl#[TokenStream][`Extend<TokenTree>`]extend().(TokenStreamrust-analyzer cargo proc_macro https://github.com/rust-lang/rust/library/proc_macro TokenStream#::fromrust-analyzer cargo proc-macro2 1.0.106 impl#[`proc_macro::TokenStream`][`From<TokenStream>`]from().(gen_attr.to_token_streamrust-analyzer cargo quote 1.0.44 to_tokens/ToTokens#to_token_stream().())); |
| 45 | tokens.extendrust-analyzer cargo proc_macro https://github.com/rust-lang/rust/library/proc_macro impl#[TokenStream][`Extend<TokenTree>`]extend().(TokenStreamrust-analyzer cargo proc_macro https://github.com/rust-lang/rust/library/proc_macro TokenStream#::fromrust-analyzer cargo proc-macro2 1.0.106 impl#[`proc_macro::TokenStream`][`From<TokenStream>`]from().(item_fn.into_token_streamrust-analyzer cargo quote 1.0.44 to_tokens/ToTokens#into_token_stream().())); |
| 46 | |
| 47 | tokens |
| 48 | } |