1use heck::ToSnakeCase;
2use proc_macro::TokenStream;
3use quote::quote;
4use syn::Ident;
56/// Creates a test that will run on all gpus on a given system.
7///
8/// Apply this macro to a static variable with a type that can be converted to a `GpuTestConfiguration`.
9#[proc_macro_attribute]
10pub fn gpu_test(_attr: TokenStream, item: TokenStream) -> TokenStream {
11let input_static = syn::parse_macro_input!(item as syn::ItemStatic);
12let vis = input_static.vis;
13let expr = &input_static.expr;
14let ident = &input_static.ident;
15let ident_str = ident.to_string();
16let ident_lower = ident_str.to_snake_case();
1718let register_test_name = Ident::new(&format!("{ident}"), ident.span());
19let test_name_webgl = Ident::new(&format!("{ident_lower}_webgl"), ident.span());
2021quote! {
22#[allow(non_snake_case)]
23#vis fn #register_test_name() -> ::wgpu_test::GpuTestConfiguration {
24struct S;
2526// Allow any type that can be converted to a GpuTestConfiguration
27::wgpu_test::GpuTestConfiguration::from(#expr).name_from_init_function_typename::<S>(#ident_lower)
28 }
2930#[cfg(target_arch = "wasm32")]
31 #[wasm_bindgen_test::wasm_bindgen_test]
32#vis async fn #test_name_webgl() {
33struct S;
3435// Allow any type that can be converted to a GpuTestConfiguration
36let test_config = ::wgpu_test::GpuTestConfiguration::from(#expr).name_from_init_function_typename::<S>(#ident_lower);
3738 ::wgpu_test::execute_test(None, test_config, None).await;
39 }
40 }
41 .into()
42}